饿虎岗资源网 Design By www.oxmxm.com
背景
公司的项目中使用了postgresql(简称pg)作为其数据库管理系统,前两天环境突然崩溃了,页面无法打开。经过排查,我发现是数据库所在机器磁盘满了,通过目录和文件排序,原来是pg的日志太多(大约保留了大半年的日志在磁盘上没有被清理)。
我看了下pg的日志配置,发现基本都是用的默认配置,日志滚动没有开启,于是乎做了下相关配置优化后对pg进行重启,最后看了pg的日志滚动,恢复正常了。以下是我梳理的关于pg的日志配置项。
配置详解
配置文件:postgresql.conf
配置1:日志开启与关闭
默认为off,设置为on则pg可以记录相关日志,建议打开,否则在数据库出现异常时候,没有日志来定位具体问题
# This is used when logging to stderr: logging_collector =on# Enable capturing of stderr and csvlog # into log files. Required to be on for # csvlogs. # (change requires restart)
配置2:日志滚动策略
# These are only used if logging_collector is on: #配置日志目录,默认为pg_log即可 log_directory = 'pg_log' # directory where log files are written, # can be absolute or relative to PGDATA #pg日志文件名及其扩展名,默认即可 log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern, # can include strftime() escapes #pg日志文件的权限,默认即可 log_file_mode = 0600 # creation mode for log files, #开启日志滚动阶段,这里需要设置为on log_truncate_on_rotation =on# If on, an existing log file with the #日志保留天数,这里看实际环境,如果是测试建议1d,如果是生产环境建议7d log_rotation_age = 1d # Automatic rotation of logfiles will #单个日志大小,默认100MB即可,比较标准的配置
配置3:日志打印时机
#发送给客户端的消息级别,建议warning即可,日志等级越低,打印的内容越多,性能上越有损耗 client_min_messages = warning # values in order of decreasing detail: # debug5 # debug4 # debug3 # debug2 # debug1 # log # notice # warning # error #写到数据库日志文件中的消息的级别,建议warning即可,日志等级越低,打印的内容越多,性能上越有损耗 log_min_messages = warning # values in order of decreasing detail: # debug5 # debug4 # debug3 # debug2 # debug1 # info # notice # warning # error # log # fatal # panic #是否记录导致数据库出现错误的SQL语句,建议warning即可,日志等级越低,打印的内容越多,性能上越有损耗 log_min_error_statement = error # values in order of decreasing detail: # debug5 # debug4 # debug3 # debug2 # debug1 # info # notice # warning # error # log # fatal # panic (effectively off)
配置4:数据库统计监控
#log_statement_stats为on则会开启log_parser_stats,log_planner_stats,log_executor_stats这三个选项,生产环境不建议开启,建议测试环境开启,用于定位问题。 #log_parser_stats = off #log_planner_stats = off #log_executor_stats = off #log_statement_stats = off
配置5:慢sql记录配置
#执行sql时间为2s以上的sql都会被记录下来 log_min_duration_statement = 2s
以上配置再修改完之后,均需要重启pg生效。
饿虎岗资源网 Design By www.oxmxm.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
饿虎岗资源网 Design By www.oxmxm.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年09月21日
2024年09月21日
- [ABC]安娜-胆麦发烧女声[6N纯银镀膜][2016[低速原抓WAV+CUE]
- 任天堂今晚举行直面会!第三方及独立游戏展示
- 《哆啦A梦的铜锣烧店物语》发售!开罗公式+哆啦A梦
- 任天堂公布《塞尔达传说》系列时间线:野炊与王泪独立在外
- 五条人.2012-一些风景2CD【刀马旦】【WAV+CUE】
- 陈奕迅.2013-Easons.Life演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 许美静.1995-遗憾(新马版)【上华】【WAV+CUE】
- 《叶倩文 歌声情缘》[WAV+CUE][410MB]
- 《张国荣 首首动听经典不容错过 追忆的风 2CD》[WAV+CUE][870MB]
- 《腾格尔 容中尔甲 亚东 高原三星 男人篇 3CD》[WAV/分轨][1GB]
- 命运圣契公测实测可用兑换码大全 命运圣契最新兑换码分享
- 黑神话悟空上品疾蝠精魄获取方法一览|上品疾蝠精魄收集攻略
- 《七龙珠电光炸裂!ZERO》GT角色预告片曝光,15位新角色登场
- [ABC]安娜-胆麦发烧女声[6N纯银镀膜][2016[低速原抓WAV+CUE]
- NewViennaOctetViennaWindSoloists-TheDeccaRecordings(2024)18CD[24-48][FLAC]-7