删除旧的 postgresql 日志文件 (Ubuntu)

Has*_*aig 9 postgresql maintenance disk-space postgresql-9.3

在托管 postgresql 数据库的 Ubuntu 机器中,我在/var/lib/postgresql/9.3/main/pg_log. 显然,几个月前的日志文件也被存储了。我手动删除了一些以摆脱我的disk full错误。每周删除旧的 postgresql 日志的可靠方法是什么?我可以做些什么postgresql.conf来自动化这个过程?

目前我有以下内容postgresql.conf

#log_truncate_on_rotation = off         # If on, an existing log file with the
                                        # same name as the new log file will be
                                        # truncated rather than appended to.
                                        # But such truncation only occurs on
                                        # time-driven rotation, not on restarts
                                        # or size-driven rotation.  Default is
                                        # off, meaning append to existing files
                                        # in all cases.
#log_rotation_age = 1d                  # Automatic rotation of logfiles will
                                        # happen after that time.  0 disables.
log_rotation_size = 100MB               # Automatic rotation of logfiles will
                                        # happen after that much log output.
                                        # 0 disables.
Run Code Online (Sandbox Code Playgroud)

我想我会启用log_rotation_age并将其值设置为30d. 但是这会自动删除旧的日志文件吗?

Sah*_*sci 10

您可以使用以下配置;

log_truncate_on_rotation = on
log_rotation_age = 1d
log_filename = 'postgresql-%a.log'
log_rotation_size = 0  #just rotate daily
Run Code Online (Sandbox Code Playgroud)

这表示创建一个名为“postgresql-Mon.log”的日志文件,并在发生轮换时覆盖具有相同名称的旧文件。