patched_12=/home/postgres/install_row_filter_12_rel/bin/
patched_123=/home/postgres/install_row_filter_123_rel/bin/

#install_path=${patched_12}
install_path=${patched_123}

ulimit -c unlimited

pub_port=5432
sub_port=5433

${install_path}pg_ctl -D data_pub stop -m i
${install_path}pg_ctl -D data_sub stop -m i
rm -rf data_pub data_sub pub.log sub.log

${install_path}initdb -D data_pub
${install_path}initdb -D data_sub

cat << EOF >> data_pub/postgresql.conf
wal_level = logical
port = $pub_port
checkpoint_timeout = 1d
max_wal_size = 24GB
min_wal_size = 15GB
autovacuum = off
wal_sender_timeout = 0
wal_receiver_timeout = 0
EOF

cat << EOF >> data_sub/postgresql.conf
checkpoint_timeout = 1d
max_wal_size = 24GB
min_wal_size = 15GB
autovacuum = off
wal_level = logical
wal_sender_timeout = 0
wal_receiver_timeout = 0
port = $sub_port
EOF

${install_path}pg_ctl -D data_pub start -l pub.log -c
${install_path}pg_ctl -D data_sub start -l sub.log -c

${install_path}psql -d postgres -p $pub_port -c "create table test(key int, value text, data jsonb, primary key(key, value));\
                                  create publication pub1 for table test where (abs(key) > 2500000);"
                                  #create publication pub1 for table test where (key > 2500000);"
${install_path}psql -d postgres -p $sub_port -c "create table test(key int, value text, data jsonb, primary key(key, value));"
${install_path}psql -d postgres -p $sub_port -c "create subscription sub1 connection 'dbname=postgres port=$pub_port' publication pub1;"

#echo synchronous_standby_names = \'sub1\' >> data_pub/postgresql.conf
#${install_path}pg_ctl -D data_pub reload
#sleep 3

${install_path}psql -d postgres -p $pub_port -c "truncate test;"
${install_path}psql -d postgres -p $pub_port -c "insert into test select i, i::text, row_to_json(row(i)) from generate_series(1,10000001)i;"

#case1
time ${install_path}psql -d postgres -p $pub_port -c "update test set key = 1        where key > 2500000;"

#case2
#time ${install_path}psql -d postgres -p $pub_port -c "update test set key = 2500001 where key < 2500000;"

#case3
#time ${install_path}psql -d postgres -p $pub_port -c "update test set key = 2500001 where key > 2500000;"

#case4
#time ${install_path}psql -d postgres -p $pub_port -c " update test set key = 1       where key < 2500000;"


