11

In a Ubuntu machine hosting a postgresql database, I have 16G space taken up at /var/lib/postgresql/9.3/main/pg_log. Apparently, log files from many months ago are being stored as well. I manually deleted a few to get rid of my disk full error. What's a robust way to delete old postgresql logs every week? Anything I can do in postgresql.conf to automate this process?

Currently I have the following in 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.

I'm thinking I'll enable log_rotation_age and set its value to 30d. But will this auto delete older log files?

1

2 Answers 2

13

You can use the configuration below;

log_truncate_on_rotation = on
log_rotation_age = 1d
log_filename = 'postgresql-%a.log'
log_rotation_size = 0  #just rotate daily

This says create a log file with a name like 'postgresql-Mon.log' and when rotation occurs override the old file with the same name.

1
  • It will work but its only single log file per server.
    – Gherman
    Oct 29, 2019 at 16:21
3

PostgreSQL supports log rotation feature but doesn't support log removing feature. So user should remove logs manually or has to use logrotate utility to remove them.

Here is the official document.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.