Skip to content

Instantly share code, notes, and snippets.

@Elektordi
Last active December 4, 2023 11:20
Show Gist options
  • Save Elektordi/ab2817f3f0b236268c95502c51056aa4 to your computer and use it in GitHub Desktop.
Save Elektordi/ab2817f3f0b236268c95502c51056aa4 to your computer and use it in GitHub Desktop.
Postgres activity log
# Put this file in /etc/cron.d/
# Setup:
# sudo -u postgres psql -c "create table activity_log as select now(), * from pg_stat_activity limit 0; create index activity_log_idx on activity_log (now);"
* * * * * postgres psql -q -c "insert into activity_log select now(), * from pg_stat_activity;"
0 0 * * * postgres psql -q -c "delete from activity_log where now < now() - interval '7 days';"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment