神剑山庄资源网 Design By www.hcban.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.hcban.com
神剑山庄资源网
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
神剑山庄资源网 Design By www.hcban.com
暂无Postgresql的日志配置教程详解的评论...
更新日志
2024年10月18日
2024年10月18日
- 群星《歌手2024 第4期》[FLAC/分轨][563.76MB]
- RiffKitten-ChaosParade(2024)[24-44,1]FLAC
- RuneKlakegg-Nattevandrer(2024)[24-96]\FLAC
- 赖冰霞.2006-金嗓典藏辑2IN1(南方金点系列)2CD【南方】【WAV+CUE】
- 群星.1988-国语金曲尽精英VOL.2【瑞成】【WAV+CUE】
- 张宇.1999-雨一直下【EMI百代】【WAV+CUE】
- 袁娅维.2021-月亮失眠了(DELUXE)【华纳】【FLAC分轨】
- AlanBroadbent-JazzFunk(2024)[24-44,1]
- 梅艳芳《绝代芳华》开盘母带[低速原抓WAV+CUE]
- ABC唱片-《外国精逊母带直刻神奇黑胶[APE+CUE].
- 群星《天赐的声音第五季 第6期》[320K/MP3][101.43MB]
- 群星《天赐的声音第五季 第6期》[FLAC/分轨][526.16MB]
- 群星《说唱梦工厂 第2期》[320K/MP3][96.37MB]
- 杨宗宪.1994-留你留袂着【有容唱片】【WAV+CUE】
- 李翊君.2005-勇敢的爱【创意唱片】【WAV+CUE】