@@ -13,6 +13,7 @@ function start_pgcat() {
13
13
14
14
# Setup the database with shards and user
15
15
PGPASSWORD=postgres psql -e -h 127.0.0.1 -p 5432 -U postgres -f tests/sharding/query_routing_setup.sql
16
+
16
17
PGPASSWORD=sharding_user pgbench -h 127.0.0.1 -U sharding_user shard0 -i
17
18
PGPASSWORD=sharding_user pgbench -h 127.0.0.1 -U sharding_user shard1 -i
18
19
PGPASSWORD=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
30
31
31
32
start_pgcat " info"
32
33
34
+ export PGPASSWORD=sharding_user
35
+
33
36
# 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
37
40
38
41
# 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
40
43
41
44
# 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) &
43
46
killall psql -s SIGINT
44
47
45
48
# 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
47
50
48
51
# 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
50
53
51
54
# 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
53
56
54
57
#
55
58
# ActiveRecord tests
@@ -61,15 +64,15 @@ cd tests/ruby && \
61
64
cd ../..
62
65
63
66
# 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)
73
76
74
77
# Start PgCat in debug to demonstrate failover better
75
78
start_pgcat " trace"
@@ -79,7 +82,7 @@ toxiproxy-cli toxic add -t latency -a latency=300 postgres_replica
79
82
sleep 1
80
83
81
84
# 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
83
86
SELECT 1;
84
87
SELECT 1;
85
88
SELECT 1;
@@ -97,7 +100,7 @@ sed -i 's/pool_mode = "transaction"/pool_mode = "session"/' pgcat.toml
97
100
kill -SIGHUP $( pgrep pgcat)
98
101
99
102
# 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
101
104
102
105
# Attempt clean shut down
103
106
killall pgcat -s SIGINT
0 commit comments