Backport from branch: 9.6-2.4

Fix default datadir

- Change into default datadir
- Add small unittest
pull/105/head
Rizky Maulana Nugraha 2018-04-24 17:41:55 +07:00
rodzic 240f45414f
commit 6f30fba235
6 zmienionych plików z 91 dodań i 0 usunięć

27
.travis.yml 100644
Wyświetl plik

@ -0,0 +1,27 @@
sudo: required
language: python
services:
- docker
virtualenv:
system_site_packages: true
python:
- '2.7'
script:
- ./build.sh
- pushd sample/replication
- make up
- make status
# Check for database status
- until make check-master-running; do echo "Retrying"; sleep 5; done
- until make check-slave-running; do echo "Retrying"; sleep 5; done
# Check replications
- until make check-master-replication; do echo "Retrying"; make master-log-tail; sleep 5; done
- sleep 60 # Wait replication finished
- until make check-slave-replication; do echo "Retrying"; make slave-log-tail; sleep 5; done
- popd

Wyświetl plik

@ -24,3 +24,27 @@ master-log:
slave-log:
docker-compose logs -f --tail=30 pg-slave
# These commands were used for travis
master-log-tail :
docker-compose logs --tail=30 pg-master
slave-log-tail:
docker-compose logs --tail=30 pg-slave
check-master-running:
@echo "Check master is running"
@docker-compose logs --tail=1 pg-master | grep 'database system is ready to accept connections' &> /dev/null
check-master-replication:
@docker-compose exec pg-master /bin/sh -c "su - postgres -c \"/tests/replication_test_master.sh\""
check-slave-running:
@echo "Check slave is running"
@docker-compose logs pg-slave | grep 'database system is ready to accept read only connections' &> /dev/null
@docker-compose logs pg-slave | grep 'started streaming WAL from primary' &> /dev/null
check-slave-replication:
@docker-compose exec pg-slave /bin/sh -c "su - postgres -c \"/tests/replication_test_slave.sh\""

Wyświetl plik

@ -9,6 +9,7 @@ services:
# observe how the slave will behave after restarts.
volumes:
- './pg-master:/var/lib/postgresql'
- './tests:/tests'
environment:
# ALLOW_IP_RANGE option is used to specify additionals allowed domains
# in pg_hba.
@ -31,6 +32,7 @@ services:
# runtime
volumes:
- './pg-slave:/var/lib/postgresql'
- './tests:/tests'
environment:
# ALLOW_IP_RANGE option is used to specify additionals allowed domains
# in pg_hba.

Wyświetl plik

@ -0,0 +1,19 @@
#!/bin/sh
. /env-data.sh
set -e
echo "Check master replication"
# Create a new table
echo "Create new table"
psql -d ${POSTGRES_DBNAME} -c "CREATE TABLE test_replication_table ();"
# Check table exists in master
echo "Check table exists"
psql -d ${POSTGRES_DBNAME} -c "\dt" | grep test_replication_table
exit $?

Wyświetl plik

@ -0,0 +1,14 @@
#!/bin/sh
. /env-data.sh
set -e
echo "Check slave replication"
# Check table exists in slave
echo "Check table exists"
psql -d ${POSTGRES_DBNAME} -c "\dt" | grep test_replication_table
exit $?

Wyświetl plik

@ -25,6 +25,7 @@ done
if [[ "$DESTROY_DATABASE_ON_RESTART" =~ [Tt][Rr][Uu][Ee] ]]; then
echo "Get initial database from master"
chown -R postgres:postgres $(getent passwd postgres | cut -d: -f6)
su - postgres -c "echo \"${REPLICATE_FROM}:${REPLICATE_PORT}:*:${POSTGRES_USER}:${POSTGRES_PASS}\" > ~/.pgpass"
su - postgres -c "chmod 0600 ~/.pgpass"
@ -32,6 +33,10 @@ if [[ "$DESTROY_DATABASE_ON_RESTART" =~ [Tt][Rr][Uu][Ee] ]]; then
do
echo "Waiting for master to connect..."
sleep 1s
if [ "$(ls -A $DATADIR)" ]; then
echo "Need empty folder. Cleaning directory..."
rm -rf $DATADIR/*
fi
done
fi