This article is half-done without your Comment! *** Please share your thoughts via Comment ***
If you don’t know the difference between pg_log, pg_clog and pg_xlog directories, please visit the below article.
PostgreSQL: Difference between pg_log, pg_clog and pg_xlog log directories
In the PostgreSQL, you can switch or rotate your server log file of a pg_log directory using pg_rotate_logfile(). It is mostly available in all versions of PostgreSQL.
Why do we require to do this?
Let me share a small example; We are doing ETL operations like data migration, data processing. Let’s assume that, senior database manager wants to know PostgreSQL Server log after every four hours.
You suppose to send a new log file to senior DBA group at after every four hours.
The simplest solution is, switch or rotate your PostgreSQL database log file at every four hours. For this, you can configure LINUX Cron job, PGAgent job and can take help of any other OS Scheduler.
Once you create a new file, you can send an old log file which has last four hours of PostgreSQL Logs.
Only, you could execute below query, and it will generate a new log file immediately in a pg_log directory.
1 |
SELECT *FROM pg_rotate_logfile() |