Last active
December 4, 2023 11:20
-
-
Save Elektordi/ab2817f3f0b236268c95502c51056aa4 to your computer and use it in GitHub Desktop.
Postgres activity log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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