On Wed, Oct 1, 2025 at 6:00 AM Peter Smith <[email protected]> wrote:
>
> Hi Shubham,
>
> Here are some v13 review comments.
>
> ======
> src/bin/pg_basebackup/pg_createsubscriber.c
>
> 1.
> - /*
> - * In dry-run mode, we don't create publications, but we still try to drop
> - * those to provide necessary information to the user.
> - */
>   if (!drop_all_pubs || dry_run)
> - drop_publication(conn, dbinfo->pubname, dbinfo->dbname,
> - &dbinfo->made_publication);
> + {
> + /*
> + * Since the publications were created before the consistent LSN, they
> + * remain on the subscriber even after the physical replica is
> + * promoted. Only drop publications that were created by
> + * pg_createsubscriber during this operation. Pre-existing
> + * publications are preserved.
> + */
> + if (!drop_all_pubs && dbinfo->made_publication)
> + drop_publication(conn, dbinfo->pubname, dbinfo->dbname,
> + &dbinfo->made_publication);
> + else if (!drop_all_pubs)
> + pg_log_info("preserve existing publication \"%s\" in database \"%s\"",
> + dbinfo->pubname, dbinfo->dbname);
> + }
>
> 1a.
> Sorry, that code looks wrong to me. Notice, the result of that patch
> fragment is essentially:
>
> if (!drop_all_pubs || dry_run)
> {
>   if (!drop_all_pubs && dbinfo->made_publication)
>     drop_publication(...);
>   else if (!drop_all_pubs)
>     pg_log_info("preserve existing...";
> }
>
> You've coded *every* condition say !drop_all_pubs, which is basically
> saying when drop_all_pubs == true then dry_run does nothing at all
> (??). Surely, that's not the intention.
>
> Let's see a specific test case: --publication=mynew
> --clean=publications --dry-run
>
> According to your matrix, AFAICT, you expect this to log:
> - "create publication mynew"
> - "dropping all existing"
> - "dropping other existing..." (loop)
> - "drop publication mynew"
>
> But, I don't see how that "drop publication mynew" is possible with
> this code. Can you provide some test/script output as proof that it
> actually works like you say it does?
>
> ~~~
>
> 1b.
> The original code at least had a comment saying what it was trying to do:
>
> - /*
> - * In dry-run mode, we don't create publications, but we still try to drop
> - * those to provide necessary information to the user.
> - */
>
> Why was that comment removed? In my v12 review, I suggested some
> possible better wording [1] for that. Please imagine someone reading
> this code without handy access to that "expected logging" matrix, and
> write explanatory comments accordingly.
>
> ======
> [1] 
> https://www.postgresql.org/message-id/CAHut%2BPtk%3Ds9VweQWXatEZ7i9GiFxZn_3A5wMSE_gDO9h7jEcRA%40mail.gmail.com
>

Hi Peter,

Thanks for the detailed review. You are right — with the earlier code,
the “drop publication mynew” case was indeed not possible. I’ve
reworked the logic so that the behavior now matches the expected
matrix in all scenarios.
I’ve also prepared a script and captured the output to demonstrate
this, which I’ve attached for reference.
Additionally, I have updated the comments per your suggestion to
better explain the intended behavior, especially around the dry-run
handling, so that it’s clearer to a future reader without needing to
refer back to the logging matrix.
The attached patch includes these changes.

Thanks and regards,
Shubham Khanna.
1. Command:
./pg_createsubscriber -D standby/ -P "host=localhost port=5432 dbname=postgres" 
-d db2 --publication pub2 --clean=publications --dry-run --verbose

Output:
shubham@shubham-Virtual-Machine:~/Project/Git/postgres/inst/bin$ sh 
test_script.sh
The files belonging to this database system will be owned by user "shubham".
This user must also own the server process.

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

Data page checksums are enabled.

creating directory data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default "max_connections" ... 20
selecting default "shared_buffers" ... 400kB
selecting default time zone ... Asia/Kolkata
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option 
-A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D data -l logfile start

waiting for server to start.... done
server started
CREATE ROLE
 slot_name |    lsn
-----------+------------
 replica_1 | 0/018ED790
(1 row)

waiting for server to shut down.... done
server stopped
waiting for server to start.... done
server started
CREATE DATABASE
CREATE DATABASE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE PUBLICATION
CREATE PUBLICATION
CREATE PUBLICATION
CREATE PUBLICATION
37878/37878 kB (100%), 1/1 tablespace
waiting for server to start.... done
server started
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
waiting for server to shut down.... done
server stopped
pg_createsubscriber: validating publisher connection string
pg_createsubscriber: validating subscriber connection string
pg_createsubscriber: checking if directory "standby" is a cluster data directory
pg_createsubscriber: getting system identifier from publisher
pg_createsubscriber: system identifier is 7556914823016805018 on publisher
pg_createsubscriber: getting system identifier from subscriber
pg_createsubscriber: system identifier is 7556914823016805018 on subscriber
pg_createsubscriber: starting the standby server with command-line options
2025-10-03 14:19:16.716 IST [1585911] LOG:  starting PostgreSQL 19devel on 
x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 
64-bit
2025-10-03 14:19:16.718 IST [1585911] LOG:  listening on Unix socket 
"/home/shubham/Project/Git/postgres/inst/bin/.s.PGSQL.50432"
2025-10-03 14:19:16.731 IST [1585917] LOG:  database system was shut down in 
recovery at 2025-10-03 14:19:15 IST
2025-10-03 14:19:16.732 IST [1585917] LOG:  entering standby mode
2025-10-03 14:19:16.736 IST [1585917] LOG:  redo starts at 0/03000028
2025-10-03 14:19:16.736 IST [1585917] LOG:  consistent recovery state reached 
at 0/04000000
2025-10-03 14:19:16.736 IST [1585911] LOG:  database system is ready to accept 
read-only connections
2025-10-03 14:19:16.742 IST [1585918] LOG:  started streaming WAL from primary 
at 0/04000000 on timeline 1
pg_createsubscriber: server was started
pg_createsubscriber: checking settings on subscriber
pg_createsubscriber: checking settings on publisher
pg_createsubscriber: warning: two_phase option will not be enabled for 
replication slots
pg_createsubscriber: detail: Subscriptions will be created with the two_phase 
option disabled.  Prepared transactions will be replicated at COMMIT PREPARED.
pg_createsubscriber: hint: You can use the command-line option 
--enable-two-phase to enable two_phase.
pg_createsubscriber: warning: required WAL could be removed from the publisher
pg_createsubscriber: hint: Set the configuration parameter 
"max_slot_wal_keep_size" to -1 to ensure that required WAL files are not 
prematurely removed.
pg_createsubscriber: stopping the subscriber
2025-10-03 14:19:16.855 IST [1585911] LOG:  received fast shutdown request
2025-10-03 14:19:16.858 IST [1585911] LOG:  aborting any active transactions
2025-10-03 14:19:16.859 IST [1585918] FATAL:  terminating walreceiver process 
due to administrator command
2025-10-03 14:19:16.865 IST [1585915] LOG:  shutting down
2025-10-03 14:19:16.878 IST [1585911] LOG:  database system is shut down
pg_createsubscriber: server was stopped
pg_createsubscriber: creating publication "pub2" in database "db2"
pg_createsubscriber: create publication "pub2" in database "db2"
pg_createsubscriber: creating the replication slot 
"pg_createsubscriber_16386_e9a70df3" in database "db2"
pg_createsubscriber: create replication slot 
"pg_createsubscriber_16386_e9a70df3" on publisher
pg_createsubscriber: starting the subscriber
2025-10-03 14:19:17.005 IST [1585930] LOG:  starting PostgreSQL 19devel on 
x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 
64-bit
2025-10-03 14:19:17.007 IST [1585930] LOG:  listening on Unix socket 
"/home/shubham/Project/Git/postgres/inst/bin/.s.PGSQL.50432"
2025-10-03 14:19:17.025 IST [1585936] LOG:  database system was shut down in 
recovery at 2025-10-03 14:19:16 IST
2025-10-03 14:19:17.026 IST [1585936] LOG:  entering standby mode
2025-10-03 14:19:17.030 IST [1585936] LOG:  redo starts at 0/03000028
2025-10-03 14:19:17.030 IST [1585936] LOG:  consistent recovery state reached 
at 0/04000000
2025-10-03 14:19:17.030 IST [1585930] LOG:  database system is ready to accept 
read-only connections
2025-10-03 14:19:17.039 IST [1585937] LOG:  started streaming WAL from primary 
at 0/04000000 on timeline 1
pg_createsubscriber: server was started
pg_createsubscriber: waiting for the target server to reach the consistent state
pg_createsubscriber: target server reached the consistent state
pg_createsubscriber: hint: If pg_createsubscriber fails after this point, you 
must recreate the physical replica before continuing.
pg_createsubscriber: dropping all existing publications in database "db2"
pg_createsubscriber: dropping publication "pub2" in database "db2"
pg_createsubscriber: creating subscription "pg_createsubscriber_16386_e9a70df3" 
in database "db2"
pg_createsubscriber: setting the replication progress (node name "pg_0", LSN 
0/00000000) in database "db2"
pg_createsubscriber: enabling subscription "pg_createsubscriber_16386_e9a70df3" 
in database "db2"
pg_createsubscriber: stopping the subscriber
2025-10-03 14:19:17.147 IST [1585930] LOG:  received fast shutdown request
2025-10-03 14:19:17.150 IST [1585930] LOG:  aborting any active transactions
2025-10-03 14:19:17.151 IST [1585937] FATAL:  terminating walreceiver process 
due to administrator command
2025-10-03 14:19:17.157 IST [1585934] LOG:  shutting down
2025-10-03 14:19:17.174 IST [1585930] LOG:  database system is shut down
pg_createsubscriber: server was stopped
pg_createsubscriber: modifying system identifier of subscriber
pg_createsubscriber: system identifier is 7556914887256519405 on subscriber
pg_createsubscriber: running pg_resetwal on the subscriber
pg_createsubscriber: Done!


2. Command:
./pg_createsubscriber -D standby/ -P "host=localhost port=5432 dbname=postgres" 
-d db2 --publication pub2 --dry-run --verbose

Output:
shubham@shubham-Virtual-Machine:~/Project/Git/postgres/inst/bin$ sh 
test_script.sh
The files belonging to this database system will be owned by user "shubham".
This user must also own the server process.

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

Data page checksums are enabled.

creating directory data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default "max_connections" ... 20
selecting default "shared_buffers" ... 400kB
selecting default time zone ... Asia/Kolkata
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option 
-A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D data -l logfile start

waiting for server to start.... done
server started
CREATE ROLE
 slot_name |    lsn
-----------+------------
 replica_1 | 0/018ED790
(1 row)

waiting for server to shut down.... done
server stopped
waiting for server to start.... done
server started
CREATE DATABASE
CREATE DATABASE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE PUBLICATION
CREATE PUBLICATION
CREATE PUBLICATION
CREATE PUBLICATION
37878/37878 kB (100%), 1/1 tablespace
waiting for server to start.... done
server started
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
waiting for server to shut down.... done
server stopped
pg_createsubscriber: validating publisher connection string
pg_createsubscriber: validating subscriber connection string
pg_createsubscriber: checking if directory "standby" is a cluster data directory
pg_createsubscriber: getting system identifier from publisher
pg_createsubscriber: system identifier is 7556915190528430937 on publisher
pg_createsubscriber: getting system identifier from subscriber
pg_createsubscriber: system identifier is 7556915190528430937 on subscriber
pg_createsubscriber: starting the standby server with command-line options
2025-10-03 14:20:41.904 IST [1586103] LOG:  starting PostgreSQL 19devel on 
x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 
64-bit
2025-10-03 14:20:41.906 IST [1586103] LOG:  listening on Unix socket 
"/home/shubham/Project/Git/postgres/inst/bin/.s.PGSQL.50432"
2025-10-03 14:20:41.919 IST [1586109] LOG:  database system was shut down in 
recovery at 2025-10-03 14:20:40 IST
2025-10-03 14:20:41.919 IST [1586109] LOG:  entering standby mode
2025-10-03 14:20:41.922 IST [1586109] LOG:  redo starts at 0/03000028
2025-10-03 14:20:41.923 IST [1586109] LOG:  consistent recovery state reached 
at 0/04000000
2025-10-03 14:20:41.923 IST [1586103] LOG:  database system is ready to accept 
read-only connections
2025-10-03 14:20:41.929 IST [1586110] LOG:  started streaming WAL from primary 
at 0/04000000 on timeline 1
pg_createsubscriber: server was started
pg_createsubscriber: checking settings on subscriber
pg_createsubscriber: checking settings on publisher
pg_createsubscriber: warning: two_phase option will not be enabled for 
replication slots
pg_createsubscriber: detail: Subscriptions will be created with the two_phase 
option disabled.  Prepared transactions will be replicated at COMMIT PREPARED.
pg_createsubscriber: hint: You can use the command-line option 
--enable-two-phase to enable two_phase.
pg_createsubscriber: warning: required WAL could be removed from the publisher
pg_createsubscriber: hint: Set the configuration parameter 
"max_slot_wal_keep_size" to -1 to ensure that required WAL files are not 
prematurely removed.
pg_createsubscriber: stopping the subscriber
2025-10-03 14:20:42.044 IST [1586103] LOG:  received fast shutdown request
2025-10-03 14:20:42.048 IST [1586103] LOG:  aborting any active transactions
2025-10-03 14:20:42.048 IST [1586110] FATAL:  terminating walreceiver process 
due to administrator command
2025-10-03 14:20:42.055 IST [1586107] LOG:  shutting down
2025-10-03 14:20:42.072 IST [1586103] LOG:  database system is shut down
pg_createsubscriber: server was stopped
pg_createsubscriber: creating publication "pub2" in database "db2"
pg_createsubscriber: create publication "pub2" in database "db2"
pg_createsubscriber: creating the replication slot 
"pg_createsubscriber_16386_11bc173d" in database "db2"
pg_createsubscriber: create replication slot 
"pg_createsubscriber_16386_11bc173d" on publisher
pg_createsubscriber: starting the subscriber
2025-10-03 14:20:42.191 IST [1586122] LOG:  starting PostgreSQL 19devel on 
x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 
64-bit
2025-10-03 14:20:42.193 IST [1586122] LOG:  listening on Unix socket 
"/home/shubham/Project/Git/postgres/inst/bin/.s.PGSQL.50432"
2025-10-03 14:20:42.207 IST [1586128] LOG:  database system was shut down in 
recovery at 2025-10-03 14:20:42 IST
2025-10-03 14:20:42.208 IST [1586128] LOG:  entering standby mode
2025-10-03 14:20:42.212 IST [1586128] LOG:  redo starts at 0/03000028
2025-10-03 14:20:42.212 IST [1586128] LOG:  consistent recovery state reached 
at 0/04000000
2025-10-03 14:20:42.212 IST [1586122] LOG:  database system is ready to accept 
read-only connections
2025-10-03 14:20:42.218 IST [1586129] LOG:  started streaming WAL from primary 
at 0/04000000 on timeline 1
pg_createsubscriber: server was started
pg_createsubscriber: waiting for the target server to reach the consistent state
pg_createsubscriber: target server reached the consistent state
pg_createsubscriber: hint: If pg_createsubscriber fails after this point, you 
must recreate the physical replica before continuing.
pg_createsubscriber: dropping publication "pub2" in database "db2"
pg_createsubscriber: creating subscription "pg_createsubscriber_16386_11bc173d" 
in database "db2"
pg_createsubscriber: setting the replication progress (node name "pg_0", LSN 
0/00000000) in database "db2"
pg_createsubscriber: enabling subscription "pg_createsubscriber_16386_11bc173d" 
in database "db2"
pg_createsubscriber: stopping the subscriber
2025-10-03 14:20:42.331 IST [1586122] LOG:  received fast shutdown request
2025-10-03 14:20:42.334 IST [1586122] LOG:  aborting any active transactions
2025-10-03 14:20:42.334 IST [1586129] FATAL:  terminating walreceiver process 
due to administrator command
2025-10-03 14:20:42.342 IST [1586126] LOG:  shutting down
2025-10-03 14:20:42.356 IST [1586122] LOG:  database system is shut down
pg_createsubscriber: server was stopped
pg_createsubscriber: modifying system identifier of subscriber
pg_createsubscriber: system identifier is 7556915253080212397 on subscriber
pg_createsubscriber: running pg_resetwal on the subscriber
pg_createsubscriber: Done!


3. Command:
./pg_createsubscriber -D standby/ -P "host=localhost port=5432 dbname=postgres" 
-d db1 --publication pub1 --clean=publications --dry-run --verbose

Output:
shubham@shubham-Virtual-Machine:~/Project/Git/postgres/inst/bin$ sh 
test_script.sh
The files belonging to this database system will be owned by user "shubham".
This user must also own the server process.

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

Data page checksums are enabled.

creating directory data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default "max_connections" ... 20
selecting default "shared_buffers" ... 400kB
selecting default time zone ... Asia/Kolkata
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option 
-A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D data -l logfile start

waiting for server to start.... done
server started
CREATE ROLE
 slot_name |    lsn
-----------+------------
 replica_1 | 0/018ED790
(1 row)

waiting for server to shut down.... done
server stopped
waiting for server to start.... done
server started
CREATE DATABASE
CREATE DATABASE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE PUBLICATION
CREATE PUBLICATION
CREATE PUBLICATION
CREATE PUBLICATION
37878/37878 kB (100%), 1/1 tablespace
waiting for server to start.... done
server started
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
waiting for server to shut down.... done
server stopped
pg_createsubscriber: validating publisher connection string
pg_createsubscriber: validating subscriber connection string
pg_createsubscriber: checking if directory "standby" is a cluster data directory
pg_createsubscriber: getting system identifier from publisher
pg_createsubscriber: system identifier is 7556915544679711769 on publisher
pg_createsubscriber: getting system identifier from subscriber
pg_createsubscriber: system identifier is 7556915544679711769 on subscriber
pg_createsubscriber: starting the standby server with command-line options
2025-10-03 14:22:04.944 IST [1586294] LOG:  starting PostgreSQL 19devel on 
x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 
64-bit
2025-10-03 14:22:04.946 IST [1586294] LOG:  listening on Unix socket 
"/home/shubham/Project/Git/postgres/inst/bin/.s.PGSQL.50432"
2025-10-03 14:22:04.960 IST [1586300] LOG:  database system was shut down in 
recovery at 2025-10-03 14:22:03 IST
2025-10-03 14:22:04.961 IST [1586300] LOG:  entering standby mode
2025-10-03 14:22:04.965 IST [1586300] LOG:  redo starts at 0/03000028
2025-10-03 14:22:04.965 IST [1586300] LOG:  consistent recovery state reached 
at 0/04000000
2025-10-03 14:22:04.966 IST [1586294] LOG:  database system is ready to accept 
read-only connections
2025-10-03 14:22:04.973 IST [1586301] LOG:  started streaming WAL from primary 
at 0/04000000 on timeline 1
pg_createsubscriber: server was started
pg_createsubscriber: checking settings on subscriber
pg_createsubscriber: checking settings on publisher
pg_createsubscriber: warning: two_phase option will not be enabled for 
replication slots
pg_createsubscriber: detail: Subscriptions will be created with the two_phase 
option disabled.  Prepared transactions will be replicated at COMMIT PREPARED.
pg_createsubscriber: hint: You can use the command-line option 
--enable-two-phase to enable two_phase.
pg_createsubscriber: warning: required WAL could be removed from the publisher
pg_createsubscriber: hint: Set the configuration parameter 
"max_slot_wal_keep_size" to -1 to ensure that required WAL files are not 
prematurely removed.
pg_createsubscriber: stopping the subscriber
2025-10-03 14:22:05.083 IST [1586294] LOG:  received fast shutdown request
2025-10-03 14:22:05.089 IST [1586294] LOG:  aborting any active transactions
2025-10-03 14:22:05.089 IST [1586301] FATAL:  terminating walreceiver process 
due to administrator command
2025-10-03 14:22:05.095 IST [1586298] LOG:  shutting down
2025-10-03 14:22:05.109 IST [1586294] LOG:  database system is shut down
pg_createsubscriber: server was stopped
pg_createsubscriber: use existing publication "pub1" in database "db1"
pg_createsubscriber: creating the replication slot 
"pg_createsubscriber_16385_52e3a5a" in database "db1"
pg_createsubscriber: create replication slot 
"pg_createsubscriber_16385_52e3a5a" on publisher
pg_createsubscriber: starting the subscriber
2025-10-03 14:22:05.317 IST [1586313] LOG:  starting PostgreSQL 19devel on 
x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 
64-bit
2025-10-03 14:22:05.323 IST [1586313] LOG:  listening on Unix socket 
"/home/shubham/Project/Git/postgres/inst/bin/.s.PGSQL.50432"
2025-10-03 14:22:05.334 IST [1586319] LOG:  database system was shut down in 
recovery at 2025-10-03 14:22:05 IST
2025-10-03 14:22:05.334 IST [1586319] LOG:  entering standby mode
2025-10-03 14:22:05.339 IST [1586319] LOG:  redo starts at 0/03000028
2025-10-03 14:22:05.339 IST [1586319] LOG:  consistent recovery state reached 
at 0/04000000
2025-10-03 14:22:05.339 IST [1586313] LOG:  database system is ready to accept 
read-only connections
2025-10-03 14:22:05.346 IST [1586320] LOG:  started streaming WAL from primary 
at 0/04000000 on timeline 1
pg_createsubscriber: server was started
pg_createsubscriber: waiting for the target server to reach the consistent state
pg_createsubscriber: target server reached the consistent state
pg_createsubscriber: hint: If pg_createsubscriber fails after this point, you 
must recreate the physical replica before continuing.
pg_createsubscriber: dropping all existing publications in database "db1"
pg_createsubscriber: dropping publication "pub1" in database "db1"
pg_createsubscriber: dropping publication "pub2" in database "db1"
pg_createsubscriber: dropping publication "pub3" in database "db1"
pg_createsubscriber: dropping publication "pub4" in database "db1"
pg_createsubscriber: creating subscription "pg_createsubscriber_16385_52e3a5a" 
in database "db1"
pg_createsubscriber: setting the replication progress (node name "pg_0", LSN 
0/00000000) in database "db1"
pg_createsubscriber: enabling subscription "pg_createsubscriber_16385_52e3a5a" 
in database "db1"
pg_createsubscriber: stopping the subscriber
2025-10-03 14:22:05.457 IST [1586313] LOG:  received fast shutdown request
2025-10-03 14:22:05.461 IST [1586313] LOG:  aborting any active transactions
2025-10-03 14:22:05.461 IST [1586320] FATAL:  terminating walreceiver process 
due to administrator command
2025-10-03 14:22:05.463 IST [1586319] LOG:  invalid record length at 
0/04000228: expected at least 24, got 0
2025-10-03 14:22:05.466 IST [1586317] LOG:  shutting down
2025-10-03 14:22:05.481 IST [1586313] LOG:  database system is shut down
pg_createsubscriber: server was stopped
pg_createsubscriber: modifying system identifier of subscriber
pg_createsubscriber: system identifier is 7556915610088608876 on subscriber
pg_createsubscriber: running pg_resetwal on the subscriber
pg_createsubscriber: Done!


4. Command:
./pg_createsubscriber -D standby/ -P "host=localhost port=5432 dbname=postgres" 
-d db1 --publication pub1 --dry-run --verbose

Output:
shubham@shubham-Virtual-Machine:~/Project/Git/postgres/inst/bin$ sh 
test_script.sh
The files belonging to this database system will be owned by user "shubham".
This user must also own the server process.

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

Data page checksums are enabled.

creating directory data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default "max_connections" ... 20
selecting default "shared_buffers" ... 400kB
selecting default time zone ... Asia/Kolkata
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option 
-A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D data -l logfile start

waiting for server to start.... done
server started
CREATE ROLE
 slot_name |    lsn
-----------+------------
 replica_1 | 0/018ED790
(1 row)

waiting for server to shut down.... done
server stopped
waiting for server to start.... done
server started
CREATE DATABASE
CREATE DATABASE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE PUBLICATION
CREATE PUBLICATION
CREATE PUBLICATION
CREATE PUBLICATION
37878/37878 kB (100%), 1/1 tablespace
waiting for server to start.... done
server started
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
waiting for server to shut down.... done
server stopped
pg_createsubscriber: validating publisher connection string
pg_createsubscriber: validating subscriber connection string
pg_createsubscriber: checking if directory "standby" is a cluster data directory
pg_createsubscriber: getting system identifier from publisher
pg_createsubscriber: system identifier is 7556915744664904916 on publisher
pg_createsubscriber: getting system identifier from subscriber
pg_createsubscriber: system identifier is 7556915744664904916 on subscriber
pg_createsubscriber: starting the standby server with command-line options
2025-10-03 14:22:51.639 IST [1586481] LOG:  starting PostgreSQL 19devel on 
x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 
64-bit
2025-10-03 14:22:51.641 IST [1586481] LOG:  listening on Unix socket 
"/home/shubham/Project/Git/postgres/inst/bin/.s.PGSQL.50432"
2025-10-03 14:22:51.656 IST [1586487] LOG:  database system was shut down in 
recovery at 2025-10-03 14:22:50 IST
2025-10-03 14:22:51.656 IST [1586487] LOG:  entering standby mode
2025-10-03 14:22:51.662 IST [1586487] LOG:  redo starts at 0/03000028
2025-10-03 14:22:51.662 IST [1586487] LOG:  consistent recovery state reached 
at 0/04000000
2025-10-03 14:22:51.662 IST [1586481] LOG:  database system is ready to accept 
read-only connections
2025-10-03 14:22:51.669 IST [1586488] LOG:  started streaming WAL from primary 
at 0/04000000 on timeline 1
pg_createsubscriber: server was started
pg_createsubscriber: checking settings on subscriber
pg_createsubscriber: checking settings on publisher
pg_createsubscriber: warning: two_phase option will not be enabled for 
replication slots
pg_createsubscriber: detail: Subscriptions will be created with the two_phase 
option disabled.  Prepared transactions will be replicated at COMMIT PREPARED.
pg_createsubscriber: hint: You can use the command-line option 
--enable-two-phase to enable two_phase.
pg_createsubscriber: warning: required WAL could be removed from the publisher
pg_createsubscriber: hint: Set the configuration parameter 
"max_slot_wal_keep_size" to -1 to ensure that required WAL files are not 
prematurely removed.
pg_createsubscriber: stopping the subscriber
2025-10-03 14:22:51.777 IST [1586481] LOG:  received fast shutdown request
2025-10-03 14:22:51.782 IST [1586481] LOG:  aborting any active transactions
2025-10-03 14:22:51.783 IST [1586488] FATAL:  terminating walreceiver process 
due to administrator command
2025-10-03 14:22:51.788 IST [1586485] LOG:  shutting down
2025-10-03 14:22:51.804 IST [1586481] LOG:  database system is shut down
pg_createsubscriber: server was stopped
pg_createsubscriber: use existing publication "pub1" in database "db1"
pg_createsubscriber: creating the replication slot 
"pg_createsubscriber_16385_55490a8e" in database "db1"
pg_createsubscriber: create replication slot 
"pg_createsubscriber_16385_55490a8e" on publisher
pg_createsubscriber: starting the subscriber
2025-10-03 14:22:52.044 IST [1586500] LOG:  starting PostgreSQL 19devel on 
x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 
64-bit
2025-10-03 14:22:52.046 IST [1586500] LOG:  listening on Unix socket 
"/home/shubham/Project/Git/postgres/inst/bin/.s.PGSQL.50432"
2025-10-03 14:22:52.059 IST [1586506] LOG:  database system was shut down in 
recovery at 2025-10-03 14:22:51 IST
2025-10-03 14:22:52.059 IST [1586506] LOG:  entering standby mode
2025-10-03 14:22:52.063 IST [1586506] LOG:  redo starts at 0/03000028
2025-10-03 14:22:52.064 IST [1586506] LOG:  consistent recovery state reached 
at 0/04000000
2025-10-03 14:22:52.064 IST [1586500] LOG:  database system is ready to accept 
read-only connections
2025-10-03 14:22:52.072 IST [1586507] LOG:  started streaming WAL from primary 
at 0/04000000 on timeline 1
pg_createsubscriber: server was started
pg_createsubscriber: waiting for the target server to reach the consistent state
pg_createsubscriber: target server reached the consistent state
pg_createsubscriber: hint: If pg_createsubscriber fails after this point, you 
must recreate the physical replica before continuing.
pg_createsubscriber: preserve existing publication "pub1" in database "db1"
pg_createsubscriber: creating subscription "pg_createsubscriber_16385_55490a8e" 
in database "db1"
pg_createsubscriber: setting the replication progress (node name "pg_0", LSN 
0/00000000) in database "db1"
pg_createsubscriber: enabling subscription "pg_createsubscriber_16385_55490a8e" 
in database "db1"
pg_createsubscriber: stopping the subscriber
2025-10-03 14:22:52.191 IST [1586500] LOG:  received fast shutdown request
2025-10-03 14:22:52.195 IST [1586500] LOG:  aborting any active transactions
2025-10-03 14:22:52.195 IST [1586507] FATAL:  terminating walreceiver process 
due to administrator command
2025-10-03 14:22:52.200 IST [1586504] LOG:  shutting down
2025-10-03 14:22:52.216 IST [1586500] LOG:  database system is shut down
pg_createsubscriber: server was stopped
pg_createsubscriber: modifying system identifier of subscriber
pg_createsubscriber: system identifier is 7556915810852594983 on subscriber
pg_createsubscriber: running pg_resetwal on the subscriber
pg_createsubscriber: Done!


5. Command:
./pg_createsubscriber -D standby/ -P "host=localhost port=5432 dbname=postgres" 
--clean=publications --dry-run --verbose

Output:
shubham@shubham-Virtual-Machine:~/Project/Git/postgres/inst/bin$ sh 
test_script.sh
The files belonging to this database system will be owned by user "shubham".
This user must also own the server process.

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

Data page checksums are enabled.

creating directory data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default "max_connections" ... 20
selecting default "shared_buffers" ... 400kB
selecting default time zone ... Asia/Kolkata
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option 
-A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D data -l logfile start

waiting for server to start.... done
server started
CREATE ROLE
 slot_name |    lsn
-----------+------------
 replica_1 | 0/018ED790
(1 row)

waiting for server to shut down.... done
server stopped
waiting for server to start.... done
server started
CREATE DATABASE
CREATE DATABASE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE PUBLICATION
CREATE PUBLICATION
CREATE PUBLICATION
CREATE PUBLICATION
37878/37878 kB (100%), 1/1 tablespace
waiting for server to start.... done
server started
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
waiting for server to shut down.... done
server stopped
pg_createsubscriber: validating publisher connection string
pg_createsubscriber: validating subscriber connection string
pg_createsubscriber: no database was specified
pg_createsubscriber: database name "postgres" was extracted from the publisher 
connection string
pg_createsubscriber: checking if directory "standby" is a cluster data directory
pg_createsubscriber: getting system identifier from publisher
pg_createsubscriber: system identifier is 7556915961586996622 on publisher
pg_createsubscriber: getting system identifier from subscriber
pg_createsubscriber: system identifier is 7556915961586996622 on subscriber
pg_createsubscriber: starting the standby server with command-line options
2025-10-03 14:23:41.455 IST [1586667] LOG:  starting PostgreSQL 19devel on 
x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 
64-bit
2025-10-03 14:23:41.460 IST [1586667] LOG:  listening on Unix socket 
"/home/shubham/Project/Git/postgres/inst/bin/.s.PGSQL.50432"
2025-10-03 14:23:41.471 IST [1586673] LOG:  database system was shut down in 
recovery at 2025-10-03 14:23:40 IST
2025-10-03 14:23:41.471 IST [1586673] LOG:  entering standby mode
2025-10-03 14:23:41.477 IST [1586673] LOG:  redo starts at 0/03000028
2025-10-03 14:23:41.477 IST [1586673] LOG:  consistent recovery state reached 
at 0/04000000
2025-10-03 14:23:41.477 IST [1586667] LOG:  database system is ready to accept 
read-only connections
2025-10-03 14:23:41.483 IST [1586674] LOG:  started streaming WAL from primary 
at 0/04000000 on timeline 1
pg_createsubscriber: server was started
pg_createsubscriber: checking settings on subscriber
pg_createsubscriber: checking settings on publisher
pg_createsubscriber: warning: two_phase option will not be enabled for 
replication slots
pg_createsubscriber: detail: Subscriptions will be created with the two_phase 
option disabled.  Prepared transactions will be replicated at COMMIT PREPARED.
pg_createsubscriber: hint: You can use the command-line option 
--enable-two-phase to enable two_phase.
pg_createsubscriber: warning: required WAL could be removed from the publisher
pg_createsubscriber: hint: Set the configuration parameter 
"max_slot_wal_keep_size" to -1 to ensure that required WAL files are not 
prematurely removed.
pg_createsubscriber: stopping the subscriber
2025-10-03 14:23:41.599 IST [1586667] LOG:  received fast shutdown request
2025-10-03 14:23:41.603 IST [1586667] LOG:  aborting any active transactions
2025-10-03 14:23:41.603 IST [1586674] FATAL:  terminating walreceiver process 
due to administrator command
2025-10-03 14:23:41.610 IST [1586671] LOG:  shutting down
2025-10-03 14:23:41.624 IST [1586667] LOG:  database system is shut down
pg_createsubscriber: server was stopped
pg_createsubscriber: creating publication "pg_createsubscriber_5_c2542c28" in 
database "postgres"
pg_createsubscriber: create publication "pg_createsubscriber_5_c2542c28" in 
database "postgres"
pg_createsubscriber: creating the replication slot 
"pg_createsubscriber_5_c2542c28" in database "postgres"
pg_createsubscriber: create replication slot "pg_createsubscriber_5_c2542c28" 
on publisher
pg_createsubscriber: starting the subscriber
2025-10-03 14:23:41.748 IST [1586686] LOG:  starting PostgreSQL 19devel on 
x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 
64-bit
2025-10-03 14:23:41.751 IST [1586686] LOG:  listening on Unix socket 
"/home/shubham/Project/Git/postgres/inst/bin/.s.PGSQL.50432"
2025-10-03 14:23:41.767 IST [1586692] LOG:  database system was shut down in 
recovery at 2025-10-03 14:23:41 IST
2025-10-03 14:23:41.770 IST [1586692] LOG:  entering standby mode
2025-10-03 14:23:41.785 IST [1586692] LOG:  redo starts at 0/03000028
2025-10-03 14:23:41.785 IST [1586692] LOG:  consistent recovery state reached 
at 0/04000000
2025-10-03 14:23:41.785 IST [1586686] LOG:  database system is ready to accept 
read-only connections
2025-10-03 14:23:41.797 IST [1586693] LOG:  started streaming WAL from primary 
at 0/04000000 on timeline 1
pg_createsubscriber: server was started
pg_createsubscriber: waiting for the target server to reach the consistent state
pg_createsubscriber: target server reached the consistent state
pg_createsubscriber: hint: If pg_createsubscriber fails after this point, you 
must recreate the physical replica before continuing.
pg_createsubscriber: dropping all existing publications in database "postgres"
pg_createsubscriber: dropping publication "pg_createsubscriber_5_c2542c28" in 
database "postgres"
pg_createsubscriber: creating subscription "pg_createsubscriber_5_c2542c28" in 
database "postgres"
pg_createsubscriber: setting the replication progress (node name "pg_0", LSN 
0/00000000) in database "postgres"
pg_createsubscriber: enabling subscription "pg_createsubscriber_5_c2542c28" in 
database "postgres"
pg_createsubscriber: stopping the subscriber
2025-10-03 14:23:41.889 IST [1586686] LOG:  received fast shutdown request
2025-10-03 14:23:41.893 IST [1586686] LOG:  aborting any active transactions
2025-10-03 14:23:41.894 IST [1586693] FATAL:  terminating walreceiver process 
due to administrator command
2025-10-03 14:23:41.900 IST [1586690] LOG:  shutting down
2025-10-03 14:23:41.913 IST [1586686] LOG:  database system is shut down
pg_createsubscriber: server was stopped
pg_createsubscriber: modifying system identifier of subscriber
pg_createsubscriber: system identifier is 7556916024166639073 on subscriber
pg_createsubscriber: running pg_resetwal on the subscriber
pg_createsubscriber: Done!


6. Command:
./pg_createsubscriber -D standby/ -P "host=localhost port=5432 dbname=postgres" 
--dry-run --verbose

Output:
shubham@shubham-Virtual-Machine:~/Project/Git/postgres/inst/bin$ sh 
test_script.sh
The files belonging to this database system will be owned by user "shubham".
This user must also own the server process.

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

Data page checksums are enabled.

creating directory data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default "max_connections" ... 20
selecting default "shared_buffers" ... 400kB
selecting default time zone ... Asia/Kolkata
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option 
-A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D data -l logfile start

waiting for server to start.... done
server started
CREATE ROLE
 slot_name |    lsn
-----------+------------
 replica_1 | 0/018ED790
(1 row)

waiting for server to shut down.... done
server stopped
waiting for server to start.... done
server started
CREATE DATABASE
CREATE DATABASE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE PUBLICATION
CREATE PUBLICATION
CREATE PUBLICATION
CREATE PUBLICATION
37878/37878 kB (100%), 1/1 tablespace
waiting for server to start.... done
server started
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
waiting for server to shut down.... done
server stopped
pg_createsubscriber: validating publisher connection string
pg_createsubscriber: validating subscriber connection string
pg_createsubscriber: no database was specified
pg_createsubscriber: database name "postgres" was extracted from the publisher 
connection string
pg_createsubscriber: checking if directory "standby" is a cluster data directory
pg_createsubscriber: getting system identifier from publisher
pg_createsubscriber: system identifier is 7556916270290454089 on publisher
pg_createsubscriber: getting system identifier from subscriber
pg_createsubscriber: system identifier is 7556916270290454089 on subscriber
pg_createsubscriber: starting the standby server with command-line options
2025-10-03 14:24:53.236 IST [1586854] LOG:  starting PostgreSQL 19devel on 
x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 
64-bit
2025-10-03 14:24:53.240 IST [1586854] LOG:  listening on Unix socket 
"/home/shubham/Project/Git/postgres/inst/bin/.s.PGSQL.50432"
2025-10-03 14:24:53.251 IST [1586860] LOG:  database system was shut down in 
recovery at 2025-10-03 14:24:52 IST
2025-10-03 14:24:53.251 IST [1586860] LOG:  entering standby mode
2025-10-03 14:24:53.257 IST [1586860] LOG:  redo starts at 0/03000028
2025-10-03 14:24:53.257 IST [1586860] LOG:  consistent recovery state reached 
at 0/04000000
2025-10-03 14:24:53.257 IST [1586854] LOG:  database system is ready to accept 
read-only connections
2025-10-03 14:24:53.263 IST [1586861] LOG:  started streaming WAL from primary 
at 0/04000000 on timeline 1
pg_createsubscriber: server was started
pg_createsubscriber: checking settings on subscriber
pg_createsubscriber: checking settings on publisher
pg_createsubscriber: warning: two_phase option will not be enabled for 
replication slots
pg_createsubscriber: detail: Subscriptions will be created with the two_phase 
option disabled.  Prepared transactions will be replicated at COMMIT PREPARED.
pg_createsubscriber: hint: You can use the command-line option 
--enable-two-phase to enable two_phase.
pg_createsubscriber: warning: required WAL could be removed from the publisher
pg_createsubscriber: hint: Set the configuration parameter 
"max_slot_wal_keep_size" to -1 to ensure that required WAL files are not 
prematurely removed.
pg_createsubscriber: stopping the subscriber
2025-10-03 14:24:53.377 IST [1586854] LOG:  received fast shutdown request
2025-10-03 14:24:53.382 IST [1586854] LOG:  aborting any active transactions
2025-10-03 14:24:53.382 IST [1586861] FATAL:  terminating walreceiver process 
due to administrator command
2025-10-03 14:24:53.388 IST [1586858] LOG:  shutting down
2025-10-03 14:24:53.402 IST [1586854] LOG:  database system is shut down
pg_createsubscriber: server was stopped
pg_createsubscriber: creating publication "pg_createsubscriber_5_f13abbd6" in 
database "postgres"
pg_createsubscriber: create publication "pg_createsubscriber_5_f13abbd6" in 
database "postgres"
pg_createsubscriber: creating the replication slot 
"pg_createsubscriber_5_f13abbd6" in database "postgres"
pg_createsubscriber: create replication slot "pg_createsubscriber_5_f13abbd6" 
on publisher
pg_createsubscriber: starting the subscriber
2025-10-03 14:24:53.525 IST [1586873] LOG:  starting PostgreSQL 19devel on 
x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 
64-bit
2025-10-03 14:24:53.530 IST [1586873] LOG:  listening on Unix socket 
"/home/shubham/Project/Git/postgres/inst/bin/.s.PGSQL.50432"
2025-10-03 14:24:53.543 IST [1586879] LOG:  database system was shut down in 
recovery at 2025-10-03 14:24:53 IST
2025-10-03 14:24:53.545 IST [1586879] LOG:  entering standby mode
2025-10-03 14:24:53.548 IST [1586879] LOG:  redo starts at 0/03000028
2025-10-03 14:24:53.548 IST [1586879] LOG:  consistent recovery state reached 
at 0/04000000
2025-10-03 14:24:53.549 IST [1586873] LOG:  database system is ready to accept 
read-only connections
2025-10-03 14:24:53.554 IST [1586880] LOG:  started streaming WAL from primary 
at 0/04000000 on timeline 1
pg_createsubscriber: server was started
pg_createsubscriber: waiting for the target server to reach the consistent state
pg_createsubscriber: target server reached the consistent state
pg_createsubscriber: hint: If pg_createsubscriber fails after this point, you 
must recreate the physical replica before continuing.
pg_createsubscriber: dropping publication "pg_createsubscriber_5_f13abbd6" in 
database "postgres"
pg_createsubscriber: creating subscription "pg_createsubscriber_5_f13abbd6" in 
database "postgres"
pg_createsubscriber: setting the replication progress (node name "pg_0", LSN 
0/00000000) in database "postgres"
pg_createsubscriber: enabling subscription "pg_createsubscriber_5_f13abbd6" in 
database "postgres"
pg_createsubscriber: stopping the subscriber
2025-10-03 14:24:53.668 IST [1586873] LOG:  received fast shutdown request
2025-10-03 14:24:53.671 IST [1586873] LOG:  aborting any active transactions
2025-10-03 14:24:53.671 IST [1586880] FATAL:  terminating walreceiver process 
due to administrator command
2025-10-03 14:24:53.679 IST [1586877] LOG:  shutting down
2025-10-03 14:24:53.691 IST [1586873] LOG:  database system is shut down
pg_createsubscriber: server was stopped
pg_createsubscriber: modifying system identifier of subscriber
pg_createsubscriber: system identifier is 7556916332497479324 on subscriber
pg_createsubscriber: running pg_resetwal on the subscriber
pg_createsubscriber: Done!

Attachment: v14-0001-Support-existing-publications-in-pg_createsubscr.patch
Description: Binary data

pkill -9 postgres
rm -rf data
rm -rf standby
rm standby.log
rm logfile

./initdb -D data -c "wal_level=logical" -c "max_prepared_transactions = 10" -c "listen_addresses=*" -c "max_slot_wal_keep_size=300"

cp pg_hba_primary.conf data/pg_hba.conf

./pg_ctl -D data -l logfile -c start

./psql -d postgres -c "CREATE ROLE replication WITH REPLICATION PASSWORD 'password' LOGIN;"
./psql -d postgres -c "SELECT * FROM pg_create_physical_replication_slot('replica_1', true);"

./pg_ctl -D data -l logfile -c restart

./psql -d postgres -c "create database db1;"
./psql -d postgres -c "create database db2;"
./psql -d db1 -c "CREATE TABLE public.t1 (id int, val text);"
./psql -d db1 -c "CREATE TABLE public.t2 (id int, val text);"
./psql -d db2 -c "CREATE TABLE public.t3 (id int, val text, extra int);"
./psql -d db1 -c "CREATE PUBLICATION pub1 FOR table public.t1;"
./psql -d db1 -c "CREATE PUBLICATION pub2 FOR table public.t2;"
./psql -d db1 -c "CREATE PUBLICATION pub3 FOR table public.t1;"
./psql -d db1 -c "CREATE PUBLICATION pub4 FOR table public.t2;"

./pg_basebackup -h 127.0.0.1 -D /home/shubham/Project/Git/postgres/inst/bin/standby -P -U replication -R

cp standby.signal standby/

echo "wal_level=logical
\n listen_addresses='*'
\n Port=9999
\n max_logical_replication_workers=5
\n max_sync_workers_per_subscription=1" >> standby/postgresql.conf

sleep 3

./pg_ctl -D standby -l standby.log -o "-p 9999" -c start

sleep 2

./psql -d postgres -c "ALTER SYSTEM SET wal_level = 'logical';"
./psql -d postgres -c "ALTER SYSTEM SET listen_addresses = '*';"
./psql -d postgres -c "ALTER SYSTEM SET port = 9999;"
./psql -d postgres -c "ALTER SYSTEM SET max_logical_replication_workers = 5;"
./psql -d postgres -c "ALTER SYSTEM SET max_sync_workers_per_subscription = 1;"

./pg_ctl -D standby -l standby.log -c stop

sleep 1

./pg_createsubscriber -D standby/ -P "host=localhost port=5432 dbname=postgres" -d db2 --publication pub2 --clean=publications --dry-run --verbose

#./pg_createsubscriber -D standby/ -P "host=localhost port=5432 dbname=postgres" -d db2 --publication pub2 --dry-run --verbose

#./pg_createsubscriber -D standby/ -P "host=localhost port=5432 dbname=postgres" -d db1 --publication pub1 --clean=publications --dry-run --verbose

#./pg_createsubscriber -D standby/ -P "host=localhost port=5432 dbname=postgres" -d db1 --publication pub1 --dry-run --verbose

#./pg_createsubscriber -D standby/ -P "host=localhost port=5432 dbname=postgres" --clean=publications --dry-run --verbose

#./pg_createsubscriber -D standby/ -P "host=localhost port=5432 dbname=postgres" --dry-run --verbose

Reply via email to