Add snapshot.sh — LLM-friendly plain text dump of all reports#91
Closed
Add snapshot.sh — LLM-friendly plain text dump of all reports#91
Conversation
- 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
snapshot.shruns 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
What it does
DO/SETnoise,NOTICE:prefixesWARNING:to⚠️for visibilitySkipped by default (safe/fast only)
pgstattuplefull table scans)pg_buffercachescan)--fullincludes 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.