port=5432

pg_ctl -D data_test stop -m immediate
rm -rf data_test test.log

initdb -D data_test -U postgres

cat << EOF >> data_test/postgresql.conf
wal_level = logical
port = $port
EOF

pg_ctl -D data_test start -l test.log

psql -d postgres -p $port -c "create table tbl (a int primary key, b text);"


psql -d postgres -p $port -c "create publication pub for table tbl;"
psql -d postgres -p $port -c "SELECT pg_create_logical_replication_slot('sub', 'pgoutput');"

createdb sub -p$port
psql -d sub -p$port -c "create table tbl (a int primary key, b text);"
psql -d sub -p$port -c "create subscription sub connection 'dbname=postgres port=$port' publication pub with(create_slot=false);"


sleep 5
psql -d postgres -p $port -c "insert into tbl SELECT i, repeat('abcdefg',10000) FROM generate_series(1, 1000000) s(i);"

