Sign inSign up

yurinek/postgres_slave

By yurinek

•Updated about 6 years ago

Dockerized Postgres Replication Slave Database as a service

Image
Databases & storage
0

1.2K

yurinek/postgres_slave repository overview

⁠HowTo run container

$ docker network create pgreplication_net

$ docker run -dit --name=postgres_slave \
--network=pgreplication_net \
-v slave_vol:/data/postgresql/12/rep \
-p 5433:5432 \
yurinek/postgres_slave:12

# Connect from host ( default password: mysecret )
$ psql -h localhost -p 5433 -U postgres mydb -W

psql: error: connection to server at "localhost" (::1), port 5433 failed: FATAL: no pg_hba.conf entry for host "192.168.65.1", user "postgres", database "mydb"

# if the above error happens, db access from local ip needs to be granted
docker container exec -it postgres_slave su - postgres -c "echo 'host all all 192.168.65.1/32 md5' >>/etc/postgresql/12/rep/pg_hba.conf"
docker container exec -it postgres_slave su - postgres -c "/usr/bin/pg_ctlcluster 12 rep reload"

⁠Customize password, database name and master host (container) name

$ export RUNTIME_ENV_PG_DB=yourdb
$ export POSTGRES_PASSWORD=yoursecret
$ export RUNTIME_ENV_MASTER_HOST=yourcontainername

$ docker run -dit --name=postgres_slave \
--network=pgreplication_net \
-e RUNTIME_ENV_PG_DB=$RUNTIME_ENV_PG_DB \
-e RUNTIME_ENV_MASTER_HOST=$RUNTIME_ENV_MASTER_HOST \
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
-v slave_vol:/data/postgresql/12/rep \
-p 5433:5432 \
yurinek/postgres_slave:12

# Connect from host
$ psql -h localhost -p 5433 -U postgres $RUNTIME_ENV_PG_DB -W

# Database name and password need to be the same as in master container
# Master host (container) name needs to be the same as $RUNTIME_ENV_MASTER_HOST, See yurinek/postgres_master⁠

⁠Kubernetes

For Kubernetes tag 12_k8s can be used

Tag summary

Content type

Image

Digest

Size

108.8 MB

Last updated

over 6 years ago

docker pull yurinek/postgres_slave