Skip to content

Instantly share code, notes, and snippets.

@repodevs
Created December 6, 2025 09:44
Show Gist options
  • Select an option

  • Save repodevs/b8b57350bd4a0c84539c8bbe628c6c7f to your computer and use it in GitHub Desktop.

Select an option

Save repodevs/b8b57350bd4a0c84539c8bbe628c6c7f to your computer and use it in GitHub Desktop.
watch command to run postgres query every 1 seconds via psql
# get count postgres idle connection for database
$ watch -n 1 psql -U myuser -d mydb -c \"select count\(\*\) from pg_stat_activity where state in \(\'idle\', \'idle in transaction\'\) and datname = \'mydb\'\"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment