pg_basebackup fails with " too many connections for role "replication"" I am trying to set up a standby server and keep getting this error. My primary server has more than enough connections to handle the load:

listen_addresses = '*'
wal_level = hot_standby
max_wal_senders = 10
max_connections=100
checkpoint_segments = 8
wal_keep_segments = 8
archive_mode = on
archive_command = 'cp %p /var/lib/postgresql/archive/%f'


This is the command that fails on the standby server:

pg_basebackup -h ${MASTER_PORT_5432_TCP_ADDR} -D ${PGDATA} -U ${REP_USER} -vPw --xlog-method=stream


I don't understand why this happens.
Per comments, pg_roles.rolconnlimit is set to 1 for that role so it needs to be increased a bit to allow for several simultaneous connections.

Choose a more reasonable value, say 5 (or -1 for unlimited) and issue as superuser:

ALTER ROLE replication CONNECTION LIMIT 5;


...or connect with a different database user for pg_basebackup.