3

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)?

Polacan
  • 55
  • 5

1 Answers1

4

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.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263