postgres 日志文件大约在 1MB 后旋转

postgres 日志文件大约在 1MB 后旋转

我在 ubuntu 18.04 上运行 postgres 10.2。我在同一天收到多个日志文件,似乎它们在达到一定文件大小后会轮换:

-rw-------  1 postgres postgres 10485987 Jun  4 10:11 postgresql-2022-06-04_101108.log
-rw-------  1 postgres postgres 10486020 Jun  4 10:12 postgresql-2022-06-04_101150.log
-rw-------  1 postgres postgres 10485962 Jun  4 10:13 postgresql-2022-06-04_101233.log
-rw-------  1 postgres postgres 10486364 Jun  4 10:13 postgresql-2022-06-04_101316.log
-rw-------  1 postgres postgres 10485884 Jun  4 10:14 postgresql-2022-06-04_101356.log
-rw-------  1 postgres postgres 10486050 Jun  4 10:15 postgresql-2022-06-04_101438.log
-rw-------  1 postgres postgres 10485978 Jun  4 10:15 postgresql-2022-06-04_101516.log
-rw-------  1 postgres postgres 10486038 Jun  4 10:16 postgresql-2022-06-04_101554.log
-rw-------  1 postgres postgres 10486002 Jun  4 10:17 postgresql-2022-06-04_101632.log
-rw-------  1 postgres postgres 10485946 Jun  4 10:17 postgresql-2022-06-04_101710.log
-rw-------  1 postgres postgres 10486516 Jun  4 10:18 postgresql-2022-06-04_101745.log
-rw-------  1 postgres postgres 10485788 Jun  4 10:18 postgresql-2022-06-04_101822.log
-rw-------  1 postgres postgres 10485906 Jun  4 10:19 postgresql-2022-06-04_101856.log
-rw-------  1 postgres postgres 10485760 Jun  4 10:20 postgresql-2022-06-04_101933.log
-rw-------  1 postgres postgres 10486022 Jun  4 10:20 postgresql-2022-06-04_102002.log
-rw-------  1 postgres postgres 10485966 Jun  4 10:21 postgresql-2022-06-04_102035.log
-rw-------  1 postgres postgres 10486044 Jun  4 10:21 postgresql-2022-06-04_102108.log

实际情况是,我每天早上运行一个 cronjob 来删除 pgsql_tmp 目录的内容。日志文件中充满了以下内容:

 2022-06-04 10:22:41.561 UTC [18892] helloworld@helloworld LOG:  could not stat file "base/pgsql_tmp/pgsql_tmp18892.2548082": No such file or directory
    2022-06-04 10:22:41.561 UTC [26662] helloworld@helloworld LOG:  could not unlink file "base/pgsql_tmp/pgsql_tmp26662.5138907": No such file or directory

直到达到一定大小并启动​​另一个。这种情况会一直持续到 cron 作业完成。

我查看了 postgresql.conf

logging_collector = on          # Enable capturing of stderr and csvlog
                                        # into log files. Required to be on for
                                        # csvlogs.
                                        # (change requires restart)

# These are only used if logging_collector is on:
log_directory = 'pg_log'                        # 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 = 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 = 10MB               # Automatic rotation of logfiles will
                                        # happen after that much log output.
                                        # 0 disables.

我觉得它看起来不错,但我缺少了一些东西。

答案1

默认值为log_rotation_size10MB。

您的文件大小为 10MB。

没什么奇怪的。

如果您只想在 1 天后旋转,则需要设置log_rotation_size0

0 禁用

相关内容