Goal: connect live server settings to the files and directories that form a cluster.
Connect to postgres as the SQL role postgres. This lab uses privileged file and directory functions; ordinary catalog queries do not all require a superuser. Set a visible marker for SQL NULL.
In the connection command, -U postgres selects the SQL role and -d postgres selects the database. Expect the psql welcome message and a postgres=# prompt; run the following SQL there. \pset null changes only the client’s display of missing values; expect Null display is "(null)".
Goal: locate data, configuration, authentication rules, and socket endpoints.
Read four paths. Here the configuration files are inside the data directory, but the Unix socket is in /tmp. Other installations can separate configuration and data too.
SHOW asks the running server, avoiding guessed paths. Expect data under /var/lib/postgresql/19/data, its postgresql.conf and pg_hba.conf, and socket directory /tmp. A socket directory identifies a connection endpoint, not a database storage directory.
Goal: compare the running release with its on-disk major-version marker.
Run SHOW server_version, then read PG_VERSION. The running version is 19.0; the disk file contains only 19. Minor upgrades retain the same major-version directory format.
\! runs a shell command from psql, then returns to the SQL prompt. as-postgres selects the Linux file owner; cat prints the file. That account is separate from the SQL role selected by -U postgres.
Goal: recognize the top-level storage layout without editing it.
List the top level as the Linux postgres account. Find base/, global/, pg_wal/, and pg_tblspc/. In this image pg_log is a compatibility symlink to log; it is not a required directory name.
ls -1 prints one directory entry per line. base holds per-database default-tablespace storage, global shared cluster catalogs, pg_wal write-ahead log files, and pg_tblspc custom tablespace links. These are server-managed contents, not files to rename for a schema change.
Goal: relate database catalog identities to directory names.
List all seven databases and test whether their OID-named directory exists under base/. All seven checks are true in this cluster. These are default-tablespace paths; custom tablespaces can store relations elsewhere.
An OID is an internal object identifier. oid::text converts it to the text used in directory names; pg_ls_dir('base') lists entries relative to the server data directory. EXISTS checks whether the matching name occurs. t means true; expect seven such results.
Goal: distinguish built-in tablespaces from custom links.
Show pg_default and pg_global, then count the entries in pg_tblspc/: zero. The built-ins use base/ and global/ directly; custom tablespaces add symlinks.
pg_tablespace is the catalog of tablespaces; a tablespace describes a storage location, not a separate database. count(*) returns one summary row, whose value 0 means no custom link entries.
Goal: compare a recorded server identity with live settings.
Read postmaster.pid. Its first lines contain the server PID, data path, start epoch, port, and socket directory. Compare its recorded port and directory with live settings. A stale PID file can remain after a crash; file existence alone does not establish readiness.
head -n 5 prints five lines. pg_read_file reads on the server; split_part(..., E'\n', n) selects a newline-delimited field, with E'\n' representing a newline. current_setting returns the live value; = yields a boolean. Expect data_path_matches = t and port_matches = t, while PID/start numbers vary.
Goal: locate actual server log output and find readiness evidence.
Inspect the collector setting and current file. In this image the collector is on and pg_current_logfile() returns log/postgresql.log. Verify that file exists and contains the startup readiness message. With the collector off, the function can return SQL NULL; the launcher then determines where stderr goes.
The collector path is relative to the data directory. grep selects lines containing the readiness message; older baked entries may also appear. Expect collector = on, log/postgresql.log, and a startup readiness line; its timestamp and PID are not fixed answers.
Goal: record server uptime evidence from two timestamps.
Read the actual start timestamp and compare it with clock_timestamp(). It must be in the past. A later restart experiment will compare before and after values in the same lesson.
pg_postmaster_start_time() belongs to the server instance; clock_timestamp() reads the clock now. <= compares them, and the AS names label the result columns. Expect start_is_in_past = t; this says nothing about the duration of your client session.
Goal: verify WAL segment sizes using the server’s own setting.
List up to five WAL files ordered by name. Check their byte sizes against wal_segment_size; this cluster uses 16 MiB segments. Names and modification timestamps can change, so they are observations rather than fixed seed IDs.
WAL records changes for recovery. pg_ls_waldir() reports names and byte sizes; pg_size_bytes converts the configured size to bytes. Expect 16MB, size 16777216, and segment_size_matches = t for displayed segments. LIMIT 5 is a preview even if fewer segments exist.
Goal: check total WAL storage against segment count and size.
Count the files and sum their bytes, then verify that the sum equals segment count × segment size. This is a point-in-time storage measurement, not a demonstration of a runaway WAL incident. Never delete WAL files manually to reclaim space.
sum(size) totals bytes; pg_size_pretty only formats that number. The equality compares raw bytes, not formatted text. This recorded cluster shows four segments / 64 MB; sizes_agree = t is the consistency test even if segment count later changes.