Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slave don't connect to master #14

Closed
jmcollin78 opened this issue Dec 1, 2016 · 2 comments
Closed

Slave don't connect to master #14

jmcollin78 opened this issue Dec 1, 2016 · 2 comments

Comments

@jmcollin78
Copy link

jmcollin78 commented Dec 1, 2016

Hello,

First I would like to thank you for this very usefull Docker clusterisation of Postgresql which is a mess.

I've got a strange behaviour I would like to expose when trying to start containers once by once (and not with Docker compose):

  1. I start the first pg Container as master with this command:
docker run --rm --name Pg1 --env INITIAL_NODE_TYPE=master --env NODE_ID=1 --env NODE_NAME=node1 --env CLUSTER_NODE_NETWORK_NAME=pgmaster --env POSTGRES_PASSWORD=monkey_pass --env POSTGRES_USER=monkey_user --env POSTGRES_DB=monkey_db --env
 CONFIGS="listen_addresses:'*',logging_collector:on" --env CLUSTER_NAME=pg_cluster --env REPLICATION_DB=replication_db --env REPLICATION_USER=replication_user --env REPLICATION_PASSWORD=replication_pass --env FORCE_CLEAN=1 -p 5432:5432 -v
 /data/pg1:/var/lib/postgresql/data paunin/postgresql-cluster-pgsql

The PG is active and all seams to be OK.

  1. I try to start the 2nd pg Container as slave with this command:
docker run --rm --name Pg2 --env INITIAL_NODE_TYPE=standby --env NODE_ID=2 --env NODE_NAME=node2 --env CLUSTER_NODE_NETWORK_NAME=pgstandby --env CONFIGS="listen_addresses:'*',logging_collector:'on'" --env CLUSTER_NAME=pg_cluster --env REP
LICATION_UPSTREAM_NODE_ID=1 --env FORCE_CLEAN=1 --env REPLICATION_PRIMARY_HOST=localhost --env REPLICATION_PRIMARY_PORT=5432 -p 5433:5432 -v /data/pg2:/var/lib/postgresql/data paunin/postgresql-cluster-pgsql

but the PG embedded in this container never start and never connect to master. Here are the logs:

For node with initial type standby you have to setup REPLICATION_UPSTREAM_NODE_ID
>>> Will wait db replication_db on pgstandby:5432, will try 50 times with delay 5 seconds
>>> Will wait db replication_db on localhost:5432, will try 50 times with delay 5 seconds
psql: could not connect to server: Connection refused
	Is the server running on host "pgstandby" (127.0.0.1) and accepting
	TCP/IP connections on port 5432?
psql: could not connect to server: Connection refused
	Is the server running on host "localhost" (::1) and accepting
	TCP/IP connections on port 5432?
could not connect to server: Connection refused
	Is the server running on host "localhost" (127.0.0.1) and accepting
	TCP/IP connections on port 5432?
...

Any help would be grealty appreciated.

EDIT:
The docker run for pg2 was wrong. I fix it.

EDIT2:
The first server is running and listening:
$ netstat -an | grep 5432
tcp6 0 0 :::5432 :::* LISTEN

@jmcollin78
Copy link
Author

jmcollin78 commented Dec 1, 2016

When looking to entreypoint.sh I see that Postgresql in not started in case of not master server:

if [[ "$INITIAL_NODE_TYPE" == "master" ]]; then
    cp -f /usr/local/bin/cluster/primary.entrypoint.sh /docker-entrypoint-initdb.d/
    /docker-entrypoint.sh "$@" &
else
    /usr/local/bin/cluster/standby.entrypoint.sh "$@" &
fi

Postgres is started by the /docker-entrypoint.sh shell and it is not called in case of slave server.
Do I miss something ?

@jmcollin78
Copy link
Author

OK, I found what is going wrong. My Pg2 container must be linked to the Pg1 as pgmaster. The correct docker run for Pg2 is:

docker run --rm --name Pg2 --link Pg1:pgmaster --env INITIAL_NODE_TYPE=standby --env NODE_ID=2 --env NODE_NAME=node2 --env CLUSTER_NODE_NETWORK_NAME=Pg2 --env REPLICATION_UPSTREAM_NODE_ID=1 --env FORCE_CLEAN=1 --env REPLICATION_PRIMARY_HO
ST=pgmaster --env REPLICATION_PRIMARY_PORT=5432 --env CLUSTER_NAME=pg_cluster --env REPLICATION_DB=replication_db --env REPLICATION_USER=replication_user --env REPLICATION_PASSWORD=replication_pass -p 5433:5432 -v /data/pg2:/var/lib/postg
resql/data paunin/postgresql-cluster-pgsql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant