Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
systemtests: fix systemtest-fd-plugin-postgresql
- Loading branch information
Showing
4 changed files
with
86 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 57 additions & 15 deletions
72
systemtests/tests/python-fd-plugin-postgres-test/database/setup_local_db.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,65 @@ | ||
#!/bin/bash | ||
|
||
pg_ctl -D data stop | ||
local_db_stop_server() { | ||
echo "Stop db server" | ||
pg_ctl --silent --pgdata=data stop | ||
tries=10 | ||
while psql --host="$1" --list > /dev/null 2>&1; do | ||
echo " -- $tries -- " | ||
[ $((tries-=1)) -eq 0 ] && { | ||
echo "Could not stop postgres server" | ||
return 1 | ||
} | ||
sleep 0.3 | ||
done | ||
} | ||
|
||
local_db_prepare_files() { | ||
echo "Prepare files" | ||
rm --recursive --force tmp data log | ||
mkdir tmp data log wal_archive | ||
LANG= pg_ctl --silent --pgdata=data --log=log/postgres.log initdb | ||
|
||
rm --recursive --force tmp data log | ||
mkdir tmp data log wal_archive | ||
LANG= pg_ctl -D data -l log/postgres.log initdb | ||
sed -i.bak "s@#listen_addresses.*@listen_addresses = ''@g" data/postgresql.conf | ||
sed -i.bak "s@#unix_socket_directories.*@unix_socket_directories = \'$1\'@g" data/postgresql.conf | ||
|
||
sed -i.bak "s@#listen_addresses.*@listen_addresses = ''@g" data/postgresql.conf | ||
sed -i.bak "s@#unix_socket_directories.*@unix_socket_directories = \'$(pwd)/tmp\'@g" data/postgresql.conf | ||
{ | ||
# for online backups we need wal_archiving | ||
echo "wal_level = archive" | ||
echo "archive_mode = on" | ||
echo "archive_command = 'cp %p ../wal_archive'" | ||
echo "max_wal_senders = 10" | ||
} >> data/postgresql.conf | ||
} | ||
|
||
# for online backups we need wal_archiving | ||
echo "wal_level = archive" >> data/postgresql.conf | ||
echo "archive_mode = on" >> data/postgresql.conf | ||
echo "archive_command = 'cp %p @current_test_directory@/database/wal_archive'" >> data/postgresql.conf | ||
echo "max_wal_senders = 10" >> data/postgresql.conf | ||
local_db_start_server() { | ||
echo "Start db server" | ||
pg_ctl --silent --pgdata=data --log=log/logfile start | ||
|
||
pg_ctl -D data -l log/logfile start | ||
sleep 10 | ||
tries=10 | ||
while ! psql --host="$1" --list > /dev/null 2>&1; do | ||
[ $((tries-=1)) -eq 0 ] && { | ||
echo "Could not start postgres server" | ||
return 1 | ||
} | ||
sleep 0.1 | ||
done | ||
|
||
echo "CREATE ROLE root WITH SUPERUSER CREATEDB CREATEROLE REPLICATION LOGIN" |psql -h @current_test_directory@/database/tmp postgres | ||
return 0 | ||
} | ||
|
||
local_db_create_superuser_role() { | ||
echo "CREATE ROLE root WITH SUPERUSER CREATEDB CREATEROLE REPLICATION LOGIN" |psql -h "$1" postgres | ||
} | ||
|
||
setup_local_db() { | ||
local_db_stop_server "$1" | ||
local_db_prepare_files "$1" | ||
if ! local_db_start_server "$1"; then return 1; fi | ||
local_db_create_superuser_role "$1" | ||
|
||
echo stop server with "pg_ctl --pgdata=data stop" | ||
|
||
return 0 | ||
} | ||
|
||
echo stop server with "pg_ctl -D data stop" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters