Skip to content
s-tech-labs/tools/pg-snapshot

pg-snapshot

Pythonv0.1.0MIT

Connects to a PostgreSQL database and produces a compact summary of its health and structure. Shows the largest tables sorted by size, row counts, index counts, currently running queries with durations, and connection breakdown by state. Uses psql under the hood so no Python database drivers are needed. Supports --watch mode for continuous monitoring. Essential for daily DB health checks.

DatabasePostgreSQLDevOpsCLI

Features

  • Table sizes sorted descending with row counts and index counts
  • Longest-running active queries with duration
  • Connection breakdown by state (active, idle, idle in transaction)
  • Database size and total connections
  • Watch mode for continuous monitoring

Flags

LongShortDescription
--version-VShow version and license
--db-dDatabase name
--db-urlFull connection string (postgres://...)
--all-aShow all tables including system schemas
--top-tLimit number of tables shown (default 20)
--json-jOutput as JSON
--watch-wRe-run every N seconds
--no-queriesSkip active queries section

Usage

terminal
$ pg-snapshot --db mydatabase
$
$ pg-snapshot --db-url postgres://user:***@host:5432/mydb --watch 30

Dependencies

stdlib + psql (system) — subprocess, os, sys

Install
$ curl -LO https://labs.stech-sol.com/downloads/pg-snapshot/0.1.0/pg-snapshot_0.1.0.tar.gz
$ tar xzf pg-snapshot_0.1.0.tar.gz
$ chmod +x pg-snapshot/pg-snapshot.py
$ sudo ln -s $PWD/pg-snapshot/pg-snapshot.py /usr/local/bin/pg-snapshot
About
Language
Python
Versionv0.1.0
LicenseMIT
RepositoryGitHub