@@ -13,6 +13,7 @@ function start_pgcat() {
1313
1414# Setup the database with shards and user
1515PGPASSWORD=postgres psql -e -h 127.0.0.1 -p 5432 -U postgres -f tests/sharding/query_routing_setup.sql
16+
1617PGPASSWORD=sharding_user pgbench -h 127.0.0.1 -U sharding_user shard0 -i
1718PGPASSWORD=sharding_user pgbench -h 127.0.0.1 -U sharding_user shard1 -i
1819PGPASSWORD=sharding_user pgbench -h 127.0.0.1 -U sharding_user shard2 -i
@@ -30,26 +31,28 @@ toxiproxy-cli create -l 127.0.0.1:5433 -u 127.0.0.1:5432 postgres_replica
3031
3132start_pgcat " info"
3233
34+ export PGPASSWORD=sharding_user
35+
3336# pgbench test
34- pgbench -i -h 127.0.0.1 -p 6432
35- pgbench -h 127.0.0.1 -p 6432 -t 500 -c 2 --protocol simple -f tests/pgbench/simple.sql
36- pgbench -h 127.0.0.1 -p 6432 -t 500 -c 2 --protocol extended
37+ pgbench -U sharding_user - i -h 127.0.0.1 -p 6432
38+ pgbench -U sharding_user - h 127.0.0.1 -p 6432 -t 500 -c 2 --protocol simple -f tests/pgbench/simple.sql
39+ pgbench -U sharding_user - h 127.0.0.1 -p 6432 -t 500 -c 2 --protocol extended
3740
3841# COPY TO STDOUT test
39- psql -h 127.0.0.1 -p 6432 -c ' COPY (SELECT * FROM pgbench_accounts LIMIT 15) TO STDOUT;' > /dev/null
42+ psql -U sharding_user - h 127.0.0.1 -p 6432 -c ' COPY (SELECT * FROM pgbench_accounts LIMIT 15) TO STDOUT;' > /dev/null
4043
4144# Query cancellation test
42- (psql -h 127.0.0.1 -p 6432 -c ' SELECT pg_sleep(5)' || true) &
45+ (psql -U sharding_user - h 127.0.0.1 -p 6432 -c ' SELECT pg_sleep(5)' || true) &
4346killall psql -s SIGINT
4447
4548# Sharding insert
46- psql -e -h 127.0.0.1 -p 6432 -f tests/sharding/query_routing_test_insert.sql
49+ psql -U sharding_user - e -h 127.0.0.1 -p 6432 -f tests/sharding/query_routing_test_insert.sql
4750
4851# Sharding select
49- psql -e -h 127.0.0.1 -p 6432 -f tests/sharding/query_routing_test_select.sql > /dev/null
52+ psql -U sharding_user - e -h 127.0.0.1 -p 6432 -f tests/sharding/query_routing_test_select.sql > /dev/null
5053
5154# Replica/primary selection & more sharding tests
52- psql -e -h 127.0.0.1 -p 6432 -f tests/sharding/query_routing_test_primary_replica.sql > /dev/null
55+ psql -U sharding_user - e -h 127.0.0.1 -p 6432 -f tests/sharding/query_routing_test_primary_replica.sql > /dev/null
5356
5457#
5558# ActiveRecord tests
@@ -61,15 +64,15 @@ cd tests/ruby && \
6164cd ../..
6265
6366# Admin tests
64- psql -e -h 127.0.0.1 -p 6432 -d pgbouncer -c ' SHOW STATS' > /dev/null
65- psql -h 127.0.0.1 -p 6432 -d pgbouncer -c ' RELOAD' > /dev/null
66- psql -h 127.0.0.1 -p 6432 -d pgbouncer -c ' SHOW CONFIG' > /dev/null
67- psql -h 127.0.0.1 -p 6432 -d pgbouncer -c ' SHOW DATABASES' > /dev/null
68- psql -h 127.0.0.1 -p 6432 -d pgbouncer -c ' SHOW LISTS' > /dev/null
69- psql -h 127.0.0.1 -p 6432 -d pgbouncer -c ' SHOW POOLS' > /dev/null
70- psql -h 127.0.0.1 -p 6432 -d pgbouncer -c ' SHOW VERSION' > /dev/null
71- psql -h 127.0.0.1 -p 6432 -d pgbouncer -c " SET client_encoding TO 'utf8'" > /dev/null # will ignore
72- (! psql -e -h 127.0.0.1 -p 6432 -d random_db -c ' SHOW STATS' > /dev/null)
67+ psql -U sharding_user - e -h 127.0.0.1 -p 6432 -d pgbouncer -c ' SHOW STATS' > /dev/null
68+ psql -U sharding_user - h 127.0.0.1 -p 6432 -d pgbouncer -c ' RELOAD' > /dev/null
69+ psql -U sharding_user - h 127.0.0.1 -p 6432 -d pgbouncer -c ' SHOW CONFIG' > /dev/null
70+ psql -U sharding_user - h 127.0.0.1 -p 6432 -d pgbouncer -c ' SHOW DATABASES' > /dev/null
71+ psql -U sharding_user - h 127.0.0.1 -p 6432 -d pgbouncer -c ' SHOW LISTS' > /dev/null
72+ psql -U sharding_user - h 127.0.0.1 -p 6432 -d pgbouncer -c ' SHOW POOLS' > /dev/null
73+ psql -U sharding_user - h 127.0.0.1 -p 6432 -d pgbouncer -c ' SHOW VERSION' > /dev/null
74+ psql -U sharding_user - h 127.0.0.1 -p 6432 -d pgbouncer -c " SET client_encoding TO 'utf8'" > /dev/null # will ignore
75+ (! psql -U sharding_user - e -h 127.0.0.1 -p 6432 -d random_db -c ' SHOW STATS' > /dev/null)
7376
7477# Start PgCat in debug to demonstrate failover better
7578start_pgcat " trace"
@@ -79,7 +82,7 @@ toxiproxy-cli toxic add -t latency -a latency=300 postgres_replica
7982sleep 1
8083
8184# Note the failover in the logs
82- timeout 5 psql -e -h 127.0.0.1 -p 6432 << -EOF
85+ timeout 5 psql -U sharding_user - e -h 127.0.0.1 -p 6432 << -EOF
8386SELECT 1;
8487SELECT 1;
8588SELECT 1;
@@ -97,7 +100,7 @@ sed -i 's/pool_mode = "transaction"/pool_mode = "session"/' pgcat.toml
97100kill -SIGHUP $( pgrep pgcat)
98101
99102# Prepared statements that will only work in session mode
100- pgbench -h 127.0.0.1 -p 6432 -t 500 -c 2 --protocol prepared
103+ pgbench -U sharding_user - h 127.0.0.1 -p 6432 -t 500 -c 2 --protocol prepared
101104
102105# Attempt clean shut down
103106killall pgcat -s SIGINT
0 commit comments