patternsqlModerate
Deleting old postgresql log files (Ubuntu)
Viewed 0 times
postgresqldeletinglogubuntufilesold
Problem
In a Ubuntu machine hosting a postgresql database, I have 16G space taken up at
Currently I have the following in
I'm thinking I'll enable
/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?Solution
You can use the configuration below;
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.
log_truncate_on_rotation = on
log_rotation_age = 1d
log_filename = 'postgresql-%a.log'
log_rotation_size = 0 #just rotate dailyThis says create a log file with a name like 'postgresql-Mon.log' and when rotation occurs override the old file with the same name.
Code Snippets
log_truncate_on_rotation = on
log_rotation_age = 1d
log_filename = 'postgresql-%a.log'
log_rotation_size = 0 #just rotate dailyContext
StackExchange Database Administrators Q#133434, answer score: 13
Revisions (0)
No revisions yet.