Postgres 日志文件不旋转

7 postgresql

我有一个带有热备用服务器的 postgres 系统。他们使用相同的配置文件。我已将日志轮换设置为使用 log_rotation_size 和 log_rotation_age,以便主服务器每 10MB 轮换一次,备用日志每天轮换一次。我的参数如下:

postgres=# select name,setting,unit from pg_settings where name like '%log%';
            name             |            setting             | unit
-----------------------------+--------------------------------+------
 log_autovacuum_min_duration | -1                             | ms
 log_checkpoints             | on                             |
 log_connections             | on                             |
 log_destination             | stderr                         |
 log_directory               | /apps/postgres/pg_log          |
 log_disconnections          | on                             |
 log_duration                | off                            |
 log_error_verbosity         | default                        |
 log_executor_stats          | off                            |
 log_file_mode               | 0600                           |
 log_filename                | postgresql-%Y-%m-%d_%H%M%S.log |
 log_hostname                | on                             |
 log_line_prefix             | %u %h %p                       |
 log_lock_waits              | on                             |
 log_min_duration_statement  | 10000                          | ms
 log_min_error_statement     | error                          |
 log_min_messages            | warning                        |
 log_parser_stats            | off                            |
 log_planner_stats           | off                            |
 log_rotation_age            | 1440                           | min
 log_rotation_size           | 10240                          | kB
 log_statement               | ddl                            |
 log_statement_stats         | off                            |
 log_temp_files              | -1                             | kB
 log_timezone                | Australia/NSW                  |
 log_truncate_on_rotation    | off                            |
 logging_collector           | on                             |
 syslog_facility             | local0                         |
 syslog_ident                | postgres                       |
Run Code Online (Sandbox Code Playgroud)

我的问题是生产数据库中的日志文件根本没有轮换,而备用日志每天都在按预期轮换。这是一个高可用性应用程序,因此我通过将日志文件复制到新文件然后将 "" 回显到当前日志文件来保持当前运行。无论如何,我可以在不中断系统的情况下解决这个问题吗?

fra*_*ncs 4

尝试以下日志参数。修改后,记得重新加载配置文件( $PGDATA/postgresql.conf)。

# These are only used if logging_collector is on:
log_directory = '/var/applog/pg_log/1921'               # directory where log files are written,
                                        # can be absolute or relative to PGDATA
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern,
                                        # can include strftime() escapes
log_file_mode = 0600                    # creation mode for log files,
                                        # begin with 0 to use octal notation
log_truncate_on_rotation = on           # 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 = 10MB               # Automatic rotation of logfiles will
Run Code Online (Sandbox Code Playgroud)