2pub_test_setup.sh

text/x-sh

Filename: 2pub_test_setup.sh
Type: text/x-sh
Part: 1
Message: Re: Conflict detection for update_deleted in logical replication
#!/bin/bash

##################
### Definition ###
##################

##sleep 5s


port_pub1=5433
port_pub2=5434
port_sub=5435


## scale factor
SCALE=60

## pgbench init command
INIT_COMMAND="./pgbench -i -U postgres postgres -s $SCALE"

SOURCE=$1

################
### clean up ###
################

./pg_ctl stop -m i -D data_pub -w
./pg_ctl stop -m i -D data_pub2 -w
./pg_ctl stop -m i -D data_sub -w
rm -rf data* *log

#######################
### setup publisher 1 ###
#######################

./initdb -D data_pub -U postgres
cat << EOF >> data_pub/postgresql.conf
port=$port_pub1
autovacuum = false
shared_buffers = '30GB'
max_wal_size = 20GB
min_wal_size = 10GB
wal_level = logical
EOF

./pg_ctl -D data_pub start -w -l pub1.log

$INIT_COMMAND -p $port_pub1
./psql -U postgres -p $port_pub1 -c "CREATE PUBLICATION pub FOR ALL TABLES;"


#######################
### setup publisher 2 ###
#######################

./initdb -D data_pub2 -U postgres
cat << EOF >> data_pub2/postgresql.conf
port=$port_pub2
autovacuum = false
shared_buffers = '30GB'
max_wal_size = 20GB
min_wal_size = 10GB
wal_level = logical
EOF

./pg_ctl -D data_pub2 start -w -l pub2.log

$INIT_COMMAND -p $port_pub2
./psql -U postgres -p $port_pub2 -c "CREATE PUBLICATION pub FOR ALL TABLES;"


#######################
### setup sublisher ###
#######################

./initdb -D data_sub -U postgres

cat << EOF >> data_sub/postgresql.conf
port=$port_sub
autovacuum = false
shared_buffers = '30GB'
max_wal_size = 20GB
min_wal_size = 10GB
track_commit_timestamp = on
# log_min_messages = DEBUG1
max_worker_processes = 100
max_logical_replication_workers = 50
#max_parallel_apply_workers_per_subscription = 8
EOF

./pg_ctl -D data_sub start -w -l sub.log
$INIT_COMMAND -p $port_sub


if [ $SOURCE = "head" ]
then
    ./psql -U postgres -p $port_sub -c "CREATE SUBSCRIPTION sub1 CONNECTION 'port=$port_pub1 user=postgres' PUBLICATION pub WITH (copy_data=false);"
    ./psql -U postgres -p $port_sub -c "CREATE SUBSCRIPTION sub2 CONNECTION 'port=$port_pub2 user=postgres' PUBLICATION pub WITH (copy_data=false);"
else
    ./psql -U postgres -p $port_sub -c "CREATE SUBSCRIPTION sub1 CONNECTION 'port=$port_pub1 user=postgres' PUBLICATION pub WITH (copy_data= false, retain_conflict_info = on);"
    ./psql -U postgres -p $port_sub -c "CREATE SUBSCRIPTION sub2 CONNECTION 'port=$port_pub2 user=postgres' PUBLICATION pub WITH (copy_data=false, retain_conflict_info = on);"
fi



sleep 5s