记一次 PostgreSQL 事故处理

2022-08-24 23:10:43 +08:00
 samin

notion 文章链接: https://gaudy-feels-700.notion.site/PostgreSQL-eb2ae9499ae94be583058f6e0cad5fa1

via: https://github.com/SaminZou/study-prj

处理完问题心血来潮写了个记录 mark 一下,希望对大家处理问题可以有点启发

4711 次点击
所在节点    程序员
42 条回复
killva4624
2022-08-25 10:15:49 +08:00
线上用容器跑 PgSQL 是最佳实践吗?哪怕是单 Node 单 Pod 的方式。
encounter2017
2022-08-25 10:26:09 +08:00
用 timestamp with time zone 是不是就没这么多事情了
samin
2022-08-25 10:26:40 +08:00
@killva4624 感谢,线上是 K8s 跑的 stolon

看来本帖更大的意义是让我完善文章,没交代清楚不是生产环境

再次表示感谢哈😂
samin
2022-08-25 10:27:40 +08:00
@encounter2017 确实是小伙伴对 PG 的数据类型不够清晰
Huelse
2022-08-25 10:32:57 +08:00
@HashV2 #19 好吧,我刚查了下 timestamp 的确存的 utc ,但 pg 会根据我服务器的时区自动转换,命令行查就已经是转过的了
Huelse
2022-08-25 10:39:19 +08:00
@encounter2017 #22
@samin #24

如果服务器或连接的服务器设置过时区也不用这些设置

https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-TIMEZONES

```
For timestamp with time zone, the internally stored value is always in UTC (Universal Coordinated Time, traditionally known as Greenwich Mean Time, GMT). An input value that has an explicit time zone specified is converted to UTC using the appropriate offset for that time zone. If no time zone is stated in the input string, then it is assumed to be in the time zone indicated by the system's TimeZone parameter, and is converted to UTC using the offset for the timezone zone.
```
csx163
2022-08-25 10:45:49 +08:00
看了还是不敢用容器跑数据库啊
fisherwei
2022-08-25 10:57:29 +08:00
k8s 部署 pg 有严重的 cache 问题,楼主你们生产环境没有遇到吗?
HashV2
2022-08-25 11:47:31 +08:00
@Huelse #25 ok 那只要确保服务器时区正确就可以了,所以这其实是个 future ?😆
adoal
2022-08-25 12:18:49 +08:00
硬生生把开发和配置问题转变成了故障修复问题
samin
2022-08-25 13:55:47 +08:00
@adoal DevOps 方式研发界限不清
samin
2022-08-25 13:57:26 +08:00
@fisherwei 有 Sample 或者连接看一下吗 ? 目前确实没遇到过 这个问题产生可能和 PG Cache 机制参数配置有关 ?
yjhatfdu2
2022-08-25 14:00:35 +08:00
@sardina 可以的,set timezone to 'Asia/Shanghai'
samin
2022-08-25 14:02:40 +08:00
@yjhatfdu2 这种方式在于 PG 服务不能重启,探究永久修改的原因是得保证减少运维变量
fisherwei
2022-08-25 15:04:22 +08:00
yjhatfdu2
2022-08-25 17:42:53 +08:00
@samin 永久修改的话可以
ALTER SYSTEM SET timezone to 'Asia/Shanghai';
select pg_reload_conf();
这样不用重启,连配置文件都不用手动改
raysonlu
2022-08-25 17:53:25 +08:00
不懂就问,如果不是用 k8s 部署,是不是就能避免这种事?
sampeng
2022-08-25 18:39:43 +08:00
看到这一句。。。线上使用 K8s 部署(单 Node 单 Pod ) bitnami PostgreSQL 14 版本数据库。。我就表示,不是这次出事就是下次出事。
数据库放 k8s 不是不可以,开发测试环境无所谓。生产环境?你是真不怕挂啊。。。。
sampeng
2022-08-25 18:41:13 +08:00
最后看到总结。。。。
what ?你这叫啥总结????
julyclyde
2022-08-26 08:50:45 +08:00
@adoal 哈哈哈哈

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/875189

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX