Hi Dear Experts,
I hit a case seems odd. I wonder if I do something unexpected, or something is here I can't see.

First, these are all on test environment. The version is PostgreSQL 17.11, uses homebrew installation on MacOS.

I have a master - replica setup, both are on the same host.
master's
PGDATA = m
port = 15432
rs = rep slot for streaming replication used by instance "r", created on master (m instance)
max_wal_size = 4GB
min_wal_size = 2GB
wal_level = replica


replica's
PGDATA = r
port = 25432
primary_conninfo = created by pg_basebackup
primary_slot_name = rs


Case: I have 16MB WAL files on master instance (so on replica). I want to utilize 1GB WAL files.
Here are the steps I take.

1. setup master - replica run on same host in respective directories and on ports
2. verify streaming replication works
3. verify "rs" (replication slot), master ("m" instance), and replica ("r" instance) have SAME WAL lsn
4. stop master, keep replica online (simulation for actual case) (pg_ctl-17 stop -D m)
5. run "pg_resetwal-17 -D m --wal-segsize=1024" on master instance.
6. start master instance, started, fine. Replica complains about "ERROR: requested WAL segment 000000010000000000000000 has already been removed", no worry.
7. stop master again, cool, done. (last log lines: "checkpoint complete", "database system is shut down")
8. start master -> bamm, could not start. (pg_ctl-17 start -D m -l m.log)

There is no read, write between after step 3 (after verification of WAL lsns)

Final failure log (step 8):
2026-09-21 14:47:45.525 +03 [22817] LOG: starting PostgreSQL 17.11 (Homebrew) on aarch64-apple-darwin25.6.0, compiled by Apple clang version 21.0.0 (clang-2100.1.1.101), 64-bit
2026-09-21 14:47:45.525 +03 [22817] LOG: listening on IPv4 address "127.0.0.1", port 15432
2026-09-21 14:47:45.525 +03 [22817] LOG: listening on Unix socket "/tmp/.s.PGSQL.15432"
2026-09-21 14:47:45.528 +03 [22820] LOG: database system was shut down at 2026-09-21 14:46:42 +03
2026-09-21 14:47:45.528 +03 [22820] LOG: invalid checkpoint record
2026-09-21 14:47:45.528 +03 [22820] PANIC: could not locate a valid checkpoint record at 0/40000110
2026-09-21 14:47:45.528 +03 [22817] LOG: startup process (PID 22820) was terminated by signal 6: Abort trap: 6
2026-09-21 14:47:45.528 +03 [22817] LOG: terminating any other active server processes
2026-09-21 14:47:45.529 +03 [22817] LOG: shutting down due to startup process failure
2026-09-21 14:47:45.529 +03 [22817] LOG: database system is shut down



After pg_resetwal, first start of master successful, but a second start fails.
I guess this causes master to be lost.

I'm able to spot the issue:
The issue is replication slot. If I would have removed replication slot before second start (do it between 6 and 7), it succeeds.

Questions:
1. Is this behavior is expected?
2. Should replication slot case mentioned in PostgreSQL documents? (I checked yet could not see)
3. Am I doing something out of order, unexpected?
4. Once I understood the case, I dropped replication slot and able to start master. Now I want to copy m/global/pg_control to replica and m/pg_wal to replica as well and complete wal segment size change. I wonder if this way is documented or supported. I can say "it works" but does not mean "supported or documented at all".

Thank you in advance.

Attachments:
14:41:17 test$ bash setup_pg17_replication.sh recreate
[pg17-lab] Stopping replica
waiting for server to shut down.... done
server stopped
[pg17-lab] Removing replica data directory: /Users/ridvan.korkmaz/adjust/test/r
[pg17-lab] Removing primary data directory: /Users/ridvan.korkmaz/adjust/test/m
[pg17-lab] Cleanup complete
[pg17-lab] Initializing primary with 16 MB WAL segments and checksums disabled
The files belonging to this database system will be owned by user 
"ridvan.korkmaz".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /Users/ridvan.korkmaz/adjust/test/m ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default "max_connections" ... 100
selecting default "shared_buffers" ... 128MB
selecting default time zone ... Europe/Istanbul
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    /opt/homebrew/bin/pg_ctl -D /Users/ridvan.korkmaz/adjust/test/m -l logfile 
start

[pg17-lab] Starting primary on port 15432
waiting for server to start.... done
server started
[pg17-lab] Creating physical replication slot 'rs'
 pg_create_physical_replication_slot 
-------------------------------------
 (rs,)
(1 row)

[pg17-lab] Creating replica with pg_basebackup
23498/23498 kB (100%), 1/1 tablespace
[pg17-lab] Starting replica on port 25432
waiting for server to start.... done
server started
[pg17-lab] Primary checks
 port  | max_wal_size | min_wal_size | wal_level | in_recovery 
-------+--------------+--------------+-----------+-------------
 15432 | 4GB          | 2GB          | replica   | f
(1 row)

 slot_name | slot_type | active 
-----------+-----------+--------
 rs        | physical  | t
(1 row)

 application_name | client_addr |   state   | sync_state 
------------------+-------------+-----------+------------
 walreceiver      | 127.0.0.1   | streaming | async
(1 row)

[pg17-lab] Replica checks
 port  | max_wal_size | min_wal_size | wal_level | in_recovery 
-------+--------------+--------------+-----------+-------------
 25432 | 4GB          | 2GB          | replica   | t
(1 row)

  status   | sender_host | sender_port | slot_name 
-----------+-------------+-------------+-----------
 streaming | 127.0.0.1   |       15432 | rs
(1 row)

[pg17-lab] Ready: primary=127.0.0.1:15432 replica=127.0.0.1:25432 slot=rs
[pg17-lab] WAL segment size verified as 16 MB; data checksums verified off

14:43:01 test$ psql -p 15432 -c "checkpoint"
CHECKPOINT
14:43:20 test$ psql -p 15432 -c "select slot_name, active, restart_lsn from 
pg_replication_slots"
 slot_name | active | restart_lsn 
-----------+--------+-------------
 rs        | t      | 0/3047328
(1 row)

14:43:24 test$ psql -p 25432 -c "SELECT pg_last_wal_replay_lsn()"
 pg_last_wal_replay_lsn 
------------------------
 0/3047328
(1 row)


14:43:33 test$ psql -p 15432 -c "select pg_current_wal_lsn()"
 pg_current_wal_lsn 
--------------------
 0/3047328
(1 row)


Reply via email to