Trouble performing backups
I get the following error when trying to do a backup:
pg_basebackup: could not connect to server: FATAL: number of requested standby connections exceeds max_wal_senders (currently 0)
Got it working, but had to set the following manually in postgresql.conf (in persistent data dir):
wal_level = hot_standby
max_wal_senders = 16
wal_keep_segments = 4
max_replication_slots = 2
I was under the impression that it should work out of the box:)
Yes, it should have worked out of the box as long as a replication user/pass exists on the primary instance.
Can you share the image version that you are/were using. Are you able to reproduce the issue with a fresh setup. That you help me track down the issue.
(Sorry for the late reply.)
I am running 9.4-22 (incrementally updated from 9.4). I can reproduce this by running the following compose file:
version: '2'
services:
master:
image: sameersbn/postgresql:9.4
environment:
REPLICATION_USER: 'repl'
REPLICATION_PASS: 'repl'
# slave:
# image: sameersbn/postgresql:9.4-22
# environment:
# REPLICATION_USER: 'repl'
# REPLICATION_PASS: 'repl'
# REPLICATION_MODE: 'slave'
# REPLICATION_HOST: 'master'
Stopping it, and running it again with:
version: '2'
services:
master:
image: sameersbn/postgresql:9.4-22
environment:
REPLICATION_USER: 'repl'
REPLICATION_PASS: 'repl'
slave:
image: sameersbn/postgresql:9.4-22
environment:
REPLICATION_USER: 'repl'
REPLICATION_PASS: 'repl'
REPLICATION_MODE: 'slave'
REPLICATION_HOST: 'master'
This will result in the following output:
Recreating pgtest_master_1
Creating pgtest_slave_1
Attaching to pgtest_slave_1, pgtest_master_1
slave_1 | Initializing datadir...
master_1 | Initializing datadir...
slave_1 | Initializing certdir...
slave_1 | Initializing logdir...
slave_1 | Initializing rundir...
slave_1 | Setting resolv.conf ACLs...
master_1 | Initializing certdir...
master_1 | Initializing logdir...
master_1 | Initializing rundir...
master_1 | Setting resolv.conf ACLs...
master_1 | ‣ Setting postgresql.conf parameter: data_directory = '/var/lib/postgresql/9.4/main'
master_1 | ‣ Setting postgresql.conf parameter: log_directory = '/var/log/postgresql'
master_1 | ‣ Setting postgresql.conf parameter: log_filename = 'postgresql-9.4-main.log'
master_1 | ‣ Setting postgresql.conf parameter: ssl = 'off'
master_1 | Creating replication user: repl
master_1 | Starting PostgreSQL 9.4...
master_1 | LOG: database system was shut down at 2016-08-08 06:17:27 UTC
master_1 | LOG: MultiXact member wraparound protections are now enabled
master_1 | LOG: autovacuum launcher started
master_1 | LOG: database system is ready to accept connections
slave_1 | Waiting for master to accept connections (60s timeout)...
slave_1 | Replicating initial data from master...
master_1 | FATAL: number of requested standby connections exceeds max_wal_senders (currently 0)
slave_1 | pg_basebackup: could not connect to server: FATAL: number of requested standby connections exceeds max_wal_senders (currently 0)
slave_1 |
pgtest_slave_1 exited with code 1
Running the 9.4-22 compose file directly will make replication work out of the box, so this seems connected to the incremental upgrades from 9.4.
+1
I used
docker run --name postgresql-backup -it --rm \
--link postgresql-master:master \
--env 'REPLICATION_MODE=backup' --env 'REPLICATION_SSLMODE=prefer' \
--env 'REPLICATION_HOST=master' --env 'REPLICATION_PORT=5432' \
--env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \
--volume /srv/docker/backups/postgresql.$(date +%Y%m%d%H%M%S):/var/lib/postgresql \
sameersbn/postgresql:9.5-1
I see a new folder getting created but it's empty.
Also about:
Restoring the backup involves starting a container with the data in /srv/docker/backups/postgresql.XXXXXXXXXXXX.
I'm confused here. If I relaunch the container it might take the a backup while I don't want to ?
I had the same issue and solved it with the following:
docker exec -it postgresql bash
source ${PG_APP_HOME}/functions
configure_hot_standby
@pascalandy no, you have to change the --volume parameter to point to your backup directory