sleep 5
echo "Creating databases"
-psql -p $PG_PORT -l |grep p0 > /dev/null || {
- psql -p $PG_PORT -c "create user bouncer" template1
+psql -X -p $PG_PORT -l | grep p0 > /dev/null || {
+ psql -X -o /dev/null -p $PG_PORT -c "create user bouncer" template1
createdb -p $PG_PORT p0
createdb -p $PG_PORT p1
createdb -p $PG_PORT p3
}
-psql -p $PG_PORT -d p0 -c "select * from pg_user" | grep pswcheck > /dev/null || {
- psql -p $PG_PORT p0 -c "create user pswcheck with superuser createdb password 'pgbouncer-check';" || return 1
- psql -p $PG_PORT p0 -c "create user someuser with password 'anypasswd';" || return 1
+psql -X -p $PG_PORT -d p0 -c "select * from pg_user" | grep pswcheck > /dev/null || {
+ psql -X -o /dev/null -p $PG_PORT -c "create user pswcheck with superuser createdb password 'pgbouncer-check';" p0 || return 1
+ psql -X -o /dev/null -p $PG_PORT -c "create user someuser with password 'anypasswd';" p0 || return 1
}
echo "Starting bouncer"
}
admin() {
- psql -h /tmp -U pgbouncer pgbouncer -c "$@;" || die "Cannot contact bouncer!"
+ psql -X -h /tmp -U pgbouncer -d pgbouncer -c "$@;" || die "Cannot contact bouncer!"
}
runtest() {
# server_lifetime
test_server_lifetime() {
admin "set server_lifetime=2"
- psql -c "select now()" p0
+ psql -X -c "select now()" p0
sleep 3
- rc=`psql -p $PG_PORT -tAqc "select count(1) from pg_stat_activity where usename='bouncer' and datname='p0'" p0`
- psql -c "select now()" p0
+ rc=`psql -X -p $PG_PORT -tAqc "select count(1) from pg_stat_activity where usename='bouncer' and datname='p0'" p0`
+ psql -X -c "select now()" p0
return $rc
}
# server_idle_timeout
test_server_idle_timeout() {
admin "set server_idle_timeout=2"
- psql -c "select now()" p0
+ psql -X -c "select now()" p0
sleep 3
- rc=`psql -p $PG_PORT -tAqc "select count(1) from pg_stat_activity where usename='bouncer' and datname='p0'" p0`
- psql -c "select now()" p0
+ rc=`psql -X -p $PG_PORT -tAq -c "select count(1) from pg_stat_activity where usename='bouncer' and datname='p0'" p0`
+ psql -X -c "select now()" p0
return $rc
}
# query_timeout
test_query_timeout() {
admin "set query_timeout=3"
- psql -c "select pg_sleep(5)" p0 && return 1
+ psql -X -c "select pg_sleep(5)" p0 && return 1
return 0
}
# client_idle_timeout
test_client_idle_timeout() {
admin "set client_idle_timeout=2"
- psql --set ON_ERROR_STOP=1 p0 <<-PSQL_EOF
+ psql -X --set ON_ERROR_STOP=1 p0 <<-PSQL_EOF
select now();
\! sleep 3
select now();
(pgctl -m fast stop; sleep 3; pgctl start) &
sleep 1
- psql -c "select now()" p0
+ psql -X -c "select now()" p0
rc=$?
wait
return $rc
sleep 2
admin "set query_timeout=3"
admin "set server_connect_timeout=2"
- psql -c "select now()" p2
+ psql -X -c "select now()" p2
# client will always see query_timeout, need to grep for connect timeout
grep "closing because: connect timeout" $BOUNCER_LOG
rc=$?
admin "set query_timeout=5"
admin "set server_connect_timeout=3"
fw_drop_port $PG_PORT
- psql -c "select now()" p0
+ psql -X -c "select now()" p0
fw_reset
# client will always see query_timeout, need to grep for connect timeout
grep "closing because: connect failed" $BOUNCER_LOG
admin "set server_login_retry=3"
admin "set query_timeout=10"
- psql p0 -c "select now()"
+ psql -X -c "select now()" p0
fw_reject_port $PG_PORT
sleep 3
- psql -tAq p0 -c "select 1" >$LOGDIR/test.tmp &
+ psql -X -tAq -c "select 1" p0 >$LOGDIR/test.tmp &
sleep 1
fw_reset
echo `date` rules flushed
admin "show config"
for i in {1..4}; do
- psql p1 -c "select now() as sleeping from pg_sleep(3);" &
+ psql -X -c "select now() as sleeping from pg_sleep(3);" p1 &
done
# last conn allowed
- psql p1 -c "select now() as last_conn" || return 1
+ psql -X -c "select now() as last_conn" p1 || return 1
# exhaust it
- psql p1 -c "select now() as sleeping from pg_sleep(3);" &
+ psql -X -c "select now() as sleeping from pg_sleep(3);" p1 &
sleep 1
# shouldn't be allowed
- psql p1 -c "select now() as exhausted" && return 1
+ psql -X -c "select now() as exhausted" p1 && return 1
# should be ok
echo 'waiting for clients to complete ...'
wait
- psql p1 -c "select now() as ok" || return 1
+ psql -X -c "select now() as ok" p1 || return 1
return 0
}
docount() {
for i in {1..10}; do
- psql $1 -c "select pg_sleep(0.5)" &
+ psql -X -c "select pg_sleep(0.5)" $1 &
done
wait
- cnt=`psql -tAqc "select count(1) from pg_stat_activity where usename='bouncer' and datname='$1'" $1`
+ cnt=`psql -X -tAq -c "select count(1) from pg_stat_activity where usename='bouncer' and datname='$1'" $1`
echo $cnt
}
echo "`date` attempt $i"
for j in {1..5}; do
- psql -c "select now() as sleeping from pg_sleep(2)" p1 &
+ psql -X -c "select now() as sleeping from pg_sleep(2)" p1 &
done
pid1=`cat $BOUNCER_PID`
test_pause_resume() {
rm -f $LOGDIR/test.tmp
for i in {1..50}; do
- psql -tAq p0 -c 'select 1 from pg_sleep(0.1)' >>$LOGDIR/test.tmp
+ psql -X -tAq -c 'select 1 from pg_sleep(0.1)' p0 >>$LOGDIR/test.tmp
done &
for i in {1..5}; do
test_suspend_resume() {
rm -f $LOGDIR/test.tmp
for i in {1..50}; do
- psql -tAq p0 -c 'select 1 from pg_sleep(0.1)' >>$LOGDIR/test.tmp
+ psql -X -tAq -c 'select 1 from pg_sleep(0.1)' p0 >>$LOGDIR/test.tmp
done &
for i in {1..5}; do
- psql -h /tmp -p $BOUNCER_PORT pgbouncer -U pgbouncer <<-PSQL_EOF
+ psql -X -h /tmp -p $BOUNCER_PORT -d pgbouncer -U pgbouncer <<-PSQL_EOF
suspend;
\! sleep 1
resume;
# test pause/resume
test_enable_disable() {
rm -f $LOGDIR/test.tmp
- psql -tAq p0 -c "select 'enabled 1'" >>$LOGDIR/test.tmp 2>&1
+ psql -X -tAq -c "select 'enabled 1'" >>$LOGDIR/test.tmp p0 2>&1
admin "disable p0"
- psql -tAq p0 -c "select 'disabled 1'" >>$LOGDIR/test.tmp 2>&1
+ psql -X -tAq -c "select 'disabled 1'" >>$LOGDIR/test.tmp p0 2>&1
admin "enable p0"
- psql -tAq p0 -c "select 'enabled 2'" >>$LOGDIR/test.tmp 2>&1
+ psql -X -tAq -c "select 'enabled 2'" >>$LOGDIR/test.tmp p0 2>&1
grep -q "enabled 1" $LOGDIR/test.tmp || return 1
grep -q "enabled 2" $LOGDIR/test.tmp || return 1
test_database_restart() {
admin "set server_login_retry=1"
- psql p0 -c "select now() as p0_before_restart"
+ psql -X -c "select now() as p0_before_restart" p0
pgctl -m fast restart
echo `date` restart 1
- psql p0 -c "select now() as p0_after_restart" || return 1
+ psql -X -c "select now() as p0_after_restart" p0 || return 1
# do with some more clients
for i in {1..5}; do
- psql p0 -c "select pg_sleep($i)" &
- psql p1 -c "select pg_sleep($i)" &
+ psql -X -c "select pg_sleep($i)" p0 &
+ psql -X -c "select pg_sleep($i)" p1 &
done
pgctl -m fast restart
echo `date` restart 2
wait
- psql p0 -c "select now() as p0_after_restart" || return 1
+ psql -X -c "select now() as p0_after_restart" p0 || return 1
}
# test connect string change
test_database_change() {
admin "set server_lifetime=2"
- db1=`psql -tAq p1 -c "select current_database()"`
+ db1=`psql -X -tAq -c "select current_database()" p1`
cp test.ini test.ini.bak
sed '/^p1 =/s/dbname=p1/dbname=p0/g' test.ini >test2.ini
kill -HUP `cat $BOUNCER_PID`
sleep 3
- db2=`psql -tAq p1 -c "select current_database()"`
+ db2=`psql -X -tAq -c "select current_database()" p1`
echo "db1=$db1 db2=$db2"
cp test.ini.bak test.ini
# test connect string change
test_auth_user() {
admin "set auth_type='md5'"
- curuser=`psql -d "dbname=authdb user=someuser password=anypasswd" -tAq -c "select current_user;"`
+ curuser=`psql -X -d "dbname=authdb user=someuser password=anypasswd" -tAq -c "select current_user;"`
echo "curuser=$curuser"
test "$curuser" = "someuser" || return 1
- curuser2=`psql -d "dbname=authdb user=nouser password=anypasswd" -tAq -c "select current_user;"`
+ curuser2=`psql -X -d "dbname=authdb user=nouser password=anypasswd" -tAq -c "select current_user;"`
echo "curuser2=$curuser2"
test "$curuser2" = "" || return 1
- curuser2=`psql -d "dbname=authdb user=someuser password=badpasswd" -tAq -c "select current_user;"`
+ curuser2=`psql -X -d "dbname=authdb user=someuser password=badpasswd" -tAq -c "select current_user;"`
echo "curuser2=$curuser2"
test "$curuser2" = "" || return 1