do_one_test_PUB.sh
text/x-sh
Filename: do_one_test_PUB.sh
Type: text/x-sh
Part: 6
#!/bin/bash
#
# PUB
#
# First argument : number of tables
# Second argument : size[Byte] of each tables
# Third argument : max_sync_workers
# Fourth argument : execution numbers
#
port_pub=5431
data_pub=datapub
port_sub=5432
data_sub=datasub
echo '########################'
echo '# Check configurations #'
echo '########################'
declare num_tables
if [ -n "$1" ]; then
num_tables=$1
else
num_tables=10
fi
echo "$num_tables tables will be used while testing"
declare table_size
if [ -n "$2" ]; then
table_size=$2
else
table_size=0
fi
num_sync_workers=$3
run_no=$4
#
# Convert from table_size to number of tuples. The equation was
# found by my tests...
#
declare num_tuples
if [ $table_size == "10kB" ]
then
num_tuples=3250
else
num_tuples=0
fi
echo "$num_tuples tuples will be inserted to each tables"
echo '#########################'
echo '# IPC at publisher-side #'
echo '#########################'
psql -U postgres -p $port_pub -a -c "CREATE PUBLICATION ipc_at_publisher FOR TABLE ipc;"
# wait a bit for the subscriber-side to connect to this publication
sleep 5s
psql -U postgres -p $port_pub -a -c "CREATE SUBSCRIPTION ipc_from_subscriber CONNECTION 'host=localhost user=postgres port=$port_sub' PUBLICATION ipc_at_subscriber WITH(origin=NONE);"
psql -U postgres -p $port_pub -a -c "INSERT INTO ipc VALUES('pub ipc ready');"
psql -U postgres -p $port_pub -a -c "CALL ipc_wait_for('sub ipc ready');"
psql -U postgres -p $port_pub -a -c "SELECT * FROM ipc ORDER BY ts;"
echo '#############################################'
echo '# Create tables, and populate the test data #'
echo '#############################################'
(
echo "CREATE TABLE busy_tbl(a text);"
echo "CREATE SCHEMA test_tables;"
echo -e "SELECT 'CREATE TABLE test_tables.manytables_'||i||'(i int);' FROM generate_series(1, $num_tables) g(i) \gexec"
echo -e "SELECT 'INSERT INTO test_tables.manytables_'||i||' VALUES (generate_series(1, $num_tuples))' FROM generate_series(1, $num_tables) g(i) \gexec"
) | psql -U postgres -p $port_pub -a
echo '##############'
echo '# Busy table #'
echo '##############'
psql -U postgres -p $port_pub -a -c "CREATE PUBLICATION mypub FOR TABLE busy_tbl;"
# wait a bit for the subscriber-side to connect to this publication
sleep 5s
psql -U postgres -p $port_pub -a -c "CALL ipc_wait_for('mysub is created');"
psql -U postgres -p $port_pub -a -c "SELECT * FROM ipc ORDER BY ts;"
echo '#####################'
echo '# Alter publication #'
echo '#####################'
psql -U postgres -p $port_pub -a -c "ALTER PUBLICATION mypub ADD TABLES IN SCHEMA test_tables;"
echo '################'
echo '# Stay busy... #'
echo '################'
(
echo -e "CREATE OR REPLACE PROCEDURE stay_busy() AS \$\$
DECLARE
counter INTEGER := 0;
commit_counter INTEGER := 0;
BEGIN
EXECUTE 'INSERT INTO ipc VALUES(''pub busy started'');';
RAISE NOTICE 'START: stay_busy';
WHILE NOT EXISTS (SELECT 1 FROM ipc WHERE msg = 'test finished') LOOP
EXECUTE 'INSERT INTO busy_tbl VALUES(''some data'');';
counter := counter + 1;
commit_counter := commit_counter + 1;
IF commit_counter = 1000 THEN
COMMIT;
commit_counter := 0;
END IF;
END LOOP;
EXECUTE 'INSERT INTO ipc VALUES(''pub busy finished'');';
RAISE NOTICE 'END: stay_busy inserted % records', counter;
END;
\$\$ LANGUAGE plpgsql;
"
) | psql -U postgres -p $port_pub -a
psql -U postgres -p $port_pub -a -c "CALL stay_busy();"
psql -U postgres -p $port_pub -a -c "SELECT * FROM ipc ORDER BY ts;"
# wait a bit for the subscriber-side to drop the subscription
sleep 5s
psql -U postgres -p $port_pub -a -c "DROP PUBLICATION mypub;"
psql -U postgres -p $port_pub -a -c "DROP SUBSCRIPTION ipc_from_subscriber;"
psql -U postgres -p $port_pub -a -c "DROP PUBLICATION ipc_at_publisher;"