case3_setup.sh
text/x-sh
Filename: case3_setup.sh
Type: text/x-sh
Part: 3
#!/bin/bash
##################
### Definition ###
##################
port_primary=5533
port_standby=5534
## scale factor
SCALE=100
## pgbench init command
INIT_COMMAND="pgbench -i -U postgres postgres -s $SCALE"
################
### clean up ###
################
./pg_ctl stop -D data_primary -w
./pg_ctl stop -D data_standby -w
rm -rf data* *log
#######################
### setup publisher ###
#######################
./initdb -D data_primary -U postgres
cat << EOF >> data_primary/postgresql.conf
port=$port_primary
autovacuum = false
shared_buffers = '30GB'
max_wal_size = 20GB
min_wal_size = 10GB
EOF
./pg_ctl -D data_primary start -w -l primary.log
./$INIT_COMMAND -p $port_primary
./psql -p $port_primary -d postgres -U postgres -c "SELECT pg_create_physical_replication_slot('standby_1');"
./psql -p $port_primary -d postgres -U postgres -c "CREATE ROLE replication WITH REPLICATION PASSWORD 'password' LOGIN;"
./pg_ctl -D data_primary restart -l primary.log
#######################
### setup standby ###
#######################
./pg_basebackup -h 127.0.0.1 -D data_standby -R -P -U replication -X s -p $port_primary
cat << EOF >> data_standby/postgresql.conf
port = $port_standby
primary_slot_name = 'standby_1'
hot_standby_feedback = on
wal_receiver_status_interval=100s
EOF
./pg_ctl -D data_standby start -w -l standby.log
sleep 5s