PostgreSQL: pg_rotate_logfile to Switch and Rotate the server log file (pg_log)

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.


Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from dbrnd.com

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz