WAL is a stream, not a row count
wal_level controls available information: minimal supports crash recovery, replica also supports physical replication, and logical also supports decoding row changes. This image starts at replica. The lab repeats the setting and restart to demonstrate activation, rather than pretending it began at minimal.
Read a WAL position with pg_current_wal_lsn(), map it with pg_walfile_name(), and measure a distance with pg_wal_lsn_diff(). The measured interval includes the marker write and any other cluster activity. pg_size_pretty rounds the result; exact byte differences do not establish exact statement attribution.
psql -c connections end after their commands, so a table retains the baseline across clients. wal_demo and wal_marker are separate fixtures, leaving baked datasets untouched. generate_series(1,50000) creates the insert workload, and || 'x' changes each payload.
pg_ls_waldir() lists entries, not permission to remove them. PostgreSQL's checkpoint, archiving, slot and retention policies determine recycling. A connected standby without a protecting slot does not by itself guarantee retention.
Did you know? WAL segment size is chosen when the cluster is initialised: 16 MiB is the default, not a universal constant. PostgreSQL initdb options.
Key concepts
LSN (Log Sequence Number)
A monotonically increasing byte position within the entire WAL stream since the cluster's creation, printed as two hexadecimal numbers separated by a slash (e.g. 0/8000078). Every WAL record has one, every replication connection reports one for what it has sent/written/flushed/replayed, and pg_wal_lsn_diff() computes the exact byte distance between any two of them.
wal_level
Controls how much information beyond bare crash-recovery is written into WAL records. Each level is a strict superset of the one below it — logical includes everything replica needs, which includes everything minimal needs — so raising the level costs some extra WAL volume but never breaks a use case the lower level supported.