Goal: configure and inspect real slow-statement logs even when pgBadger is absent.
command -v tests the shell’s executable search path. The if prints a clear absence marker without treating an expected missing program as an unexpected failure. This image should print PGBADGER_NOT_INSTALLED. The later pipeline handles our single-line labelled experiment, not arbitrary CSV records or a full pgBadger report.
All hints run at the Linux shell. psql -c executes quoted SQL and exits; each command uses a new connection. -U postgres explicitly selects the administrative SQL role, and -v ON_ERROR_STOP=1 stops on SQL errors. The monitoring tables are separate provided fixtures, not the baked business datasets.
Goal: request a collector, CSV output, and a 200-millisecond statement threshold.
Set logging_collector, log_destination, and duration logging explicitly. Also disable unconditional statement/duration logging so it does not confuse the fast-query comparison. log_directory is relative to PGDATA here; a fixed lesson filename keeps discovery focused. Other errors and server messages may still be logged: log_min_duration_statement is not the only logging control.
Goal: prove the requested configuration became active.
logging_collector has postmaster context: it needs a restart to create the collector process. Other settings here can reload once it exists. Start the restart’s diagnostics in the explicit server log and read the active settings from a new client; saved configuration text alone is not proof.
Goal: read the file the collector is actually using, rather than every historical CSV file.
pg_current_logfile('csvlog') returns its relative path. Shell $(...) captures it; export preserves the variable for later commands. Combine it with the data directory and inspect it with as-postgres, which uses the server’s Linux account because student cannot traverse PGDATA. SQL superuser privileges and filesystem access are separate.
Goal: compare tiny queries with deliberate sleeps while preserving statement identity in the log.
SQL comments label two controls and two sleeps. Expect control results 1 and 2; sleep calls return one blank value, not zero rows. The sleeps add at least 300/500 milliseconds; exact logged times include overhead. A query’s text alone does not guarantee its real duration. Poll for both labelled sleep records because the collector writes asynchronously.
Goal: verify which of the four statements crossed the logging threshold.
Filter only LAB24_ records from the current file, then extract each label and its duration with a narrowly defined sed pattern. Save the readable result under /tmp as the student. Expect two labelled sleep records of at least 200 ms and no fast-control label in this run. This retains identity, unlike extracting anonymous numbers from all log history. It is not a general CSV parser: quoted newlines or different record layouts need proper CSV handling.
Goal: sort the actual times without losing the query labels.
awk -F splits our deliberately simple label/duration file at |. It prints duration first so sort -rn sorts numerically in reverse order. Expect the 500-ms sleep first and the 300-ms sleep second for this observed workload. This is a two-statement ranking, not query normalization, frequency analysis, or a pgBadger-equivalent report.