Reproduce Heroku's Postgres WAL metric with pg_ls_waldir()



  • Is it possible to reproduce Heroku’s WAL usage metric by using the postgres query SELECT sum(size) FROM pg_ls_waldir(); that returns the size of the WAL directory? I asked Heroku support but they haven’t been able to answer and said the WAL drive is 64 GB in one ticket and 112 GB in another. The calculation is off when using either of these values. We have a large migration and it could reach the Heroku WAL threshold. I think the Heroku metric is produced every minute or so via the logging system and reproducing it via a query would make things easier



  • We asked Heroku support again and they're saying we should be able to use SELECT sum(size) FROM pg_ls_waldir();

    To address your follow up question; internally we use a symlink from the pg_wal directory to a directory on a separate WAL drive. From there it gets pushed to an S3 bucket.

    We also wanted to get back to you about the tests you were running using the select sum(size) from pg_ls_waldir() function, and let you know that there can be discrepancies reported when comparing the results of the pg_ls_waldir() function against our server metrics (sample#wal-percentage-used) due to the nature of how they are both being measured internally, but ultimately using the pg_ls_waldir() function should be a good way to monitor WAL usage (considering the WAL disk is 68GB).

    We're going to test our script again and see if this measurement is comparable to the Heroku-provided one.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2