简体   繁体   中英

PostgreSQL Log Rotation Size Reached File Limit

I have configured the following settings in postgreSQL 13.

logging_collector = on  
log_rotation_size='100MB'
log_truncate_on_rotation = on    
log_filename ='postgresql-%Y-%m-%d.log'

My issue is when the log file size reached 100MB, it will continue to append on it, I think it is because of the log_filename. Is there anyway I can rename the filename when it reached the log_rotation_size? I need to set the log_filename with this format (without the time) so that whenever I restart the service, the log will still be in the same log file.

Do I have to run some script or services on the background so that the program is able to monitor the data/logs folder and rename the file when the log file size reaches the limit?

As the documentation says:

However, truncation will occur only when a new file is being opened due to time-based rotation, not during server startup or size-based rotation.

Truncating the log file in your case would mean to lose recent log information, so PostgreSQL won't do it.

I can think of no better way than a cron job that removes the log file when it approaches the limit. Then size based log rotation will create the file again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM