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
| Long | Short | Description |
|---|---|---|
| --version | -V | Show version and license |
| --db | -d | Database name |
| --db-url | — | Full connection string (postgres://...) |
| --all | -a | Show all tables including system schemas |
| --top | -t | Limit number of tables shown (default 20) |
| --json | -j | Output as JSON |
| --watch | -w | Re-run every N seconds |
| --no-queries | — | Skip 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
Downloads
Verify integrity
SHA256 checksums