Skip to content

Comments

Add snapshot.sh — LLM-friendly plain text dump of all reports#91

Closed
NikolayS wants to merge 1 commit intomasterfrom
add-snapshot-script
Closed

Add snapshot.sh — LLM-friendly plain text dump of all reports#91
NikolayS wants to merge 1 commit intomasterfrom
add-snapshot-script

Conversation

@NikolayS
Copy link
Owner

What

snapshot.sh runs all safe reports non-interactively and outputs clean plain text. Designed for feeding database state to LLMs, saving to files, or piping into automation.

Usage

./snapshot.sh -h localhost -U postgres -d mydb           # plain text output
./snapshot.sh -d mydb > snapshot.txt                     # save to file
./snapshot.sh -d mydb | pbcopy                           # clipboard (macOS)
./snapshot.sh --full -d mydb                             # include expensive reports

What it does

  • Runs 25 reports (out of 34) with clean text output
  • Strips: ANSI colors, psql file references, DO/SET noise, NOTICE: prefixes
  • Converts WARNING: to ⚠️ for visibility
  • Caps each report at 500 lines

Skipped by default (safe/fast only)

Skipped Reason
b3, b4 Expensive (pgstattuple full table scans)
c2, c3, c4 Heavy or blocking amcheck
m1 Expensive (pg_buffercache scan)
p1 Progress — only useful during active operations
r1, r2 Interactive (require user input)

--full includes everything except r1/r2.

Output

~1500 lines / ~430KB for a typical database. Fits comfortably in LLM context windows.

Tested on

PG17 (localhost). Output is clean and parseable.

- Runs all safe reports non-interactively, outputs clean plain text
- Strips ANSI colors, psql noise, DO/SET lines, NOTICE: prefixes
- Skips: interactive (r1/r2), expensive (b3/b4/c2-c4/m1), progress (p1)
- --full flag includes expensive reports
- Works with any psql connection args or connection string
- ~1500 lines / ~430KB for a typical database — fits in LLM context

# Ensure non-interactive mode for t1
PSQLRC_TMP=$(mktemp)
trap "rm -f $PSQLRC_TMP" EXIT
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor quoting nit: since this runs in a trap, it’s safer to quote the tmp path to avoid word-splitting/globbing edge cases.

Suggested change
trap "rm -f $PSQLRC_TMP" EXIT
trap 'rm -f "$PSQLRC_TMP"' EXIT

#
# To include expensive reports, use --full.

set -euo pipefail
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone runs this in a checkout without sql/*.sql (or the glob doesn’t match), bash will iterate the literal pattern and the script will fail under set -e. Enabling nullglob avoids that surprise.

Suggested change
set -euo pipefail
set -euo pipefail
shopt -s nullglob

@NikolayS NikolayS closed this Feb 10, 2026
@NikolayS NikolayS deleted the add-snapshot-script branch February 10, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant