Is there a way to measure log volume in PostgreSQL instance?

Viewed 109

Started up a new postgres database instance and enable pgaudit logs. Is there a way I can monitor the volume of logs ingested on the database as well as the ingestion rate so that it does not exceed a certain threshold (or better yet be alerted that I've exceed that threshold)?

1 Answers

To get the size of the current log file:

SELECT size FROM pg_stat_file(pg_current_logfile());

To get the sum of the size of all files in the log directory:

SELECT sum(stat.size)
FROM pg_ls_dir(current_setting('log_directory')) AS logs
   CROSS JOIN LATERAL
      pg_stat_file(current_setting('log_directory') || '/' || logs) AS stat;

That should work on Windows as well.

Related