I have strange problem. I am trying to achieve streaming replication between 2 PostgreSQL servers with version 9.2.1. The replications worked just fine then the servers was without load. The problem is that now then the servers are loaded I cannot start the replication without receiving this error:
FATAL: sorry, too many clients already
The slave server is out of the question and is stopped. I am changing only the master configuration from this setup (I will paste only the end of the file postgresql.conf because the other stuff are with default params except the listen configuration):
#------------------------------------------------------------------------------
# CUSTOMIZED OPTIONS
#------------------------------------------------------------------------------
# Add settings for extensions here
#### Postgre replication
#archive_command = 'cp -i %p /data/PostgreSQL/PostgresArchive/%f'
#archive_mode = on
#max_wal_senders = 3 # Maximum 'wal_senders', processes responsible for managing a connection with a standby server
#wal_keep_segments = 32 # How many WAL segments (=files) should be kept on the primary, whatever may happen (you won't have to copy them manually on the standby if the standby gets too far behind)
#wal_level = hot_standby
#synchronous_standby_names = 'sync_replication'
#
max_locks_per_transaction = 500
#
#------------------------------------------------------------------------------
# pgtune wizard run on 2012-10-04
# Based on 65958512 KB RAM in the server
#------------------------------------------------------------------------------
default_statistics_target = 100
maintenance_work_mem = 1GB
checkpoint_completion_target = 0.9
effective_cache_size = 44GB
work_mem = 384MB
wal_buffers = 8MB
checkpoint_segments = 16
shared_buffers = 15GB
max_connections = 80
With this setup everything is OK and no errors are observed. The command: "netstat -aonlp | grep 5432 | wc -l" return average 30 connections to PostgreSQL. When I change the configuration to:
#------------------------------------------------------------------------------
# CUSTOMIZED OPTIONS
#------------------------------------------------------------------------------
# Add settings for extensions here
#### Postgre replication
archive_command = 'cp -i %p /data/PostgreSQL/PostgresArchive/%f'
archive_mode = on
max_wal_senders = 3 # Maximum 'wal_senders', processes responsible for managing a connection with a standby server
wal_keep_segments
= 32 # How many WAL segments (=files) should be kept on the primary,
whatever may happen (you won't have to copy them manually on the standby
if the standby gets too far behind)
wal_level = hot_standby
synchronous_standby_names = 'sync_replication'
#
max_locks_per_transaction = 500
#
#------------------------------------------------------------------------------
# pgtune wizard run on 2012-10-04
# Based on 65958512 KB RAM in the server
#------------------------------------------------------------------------------
default_statistics_target = 100
maintenance_work_mem = 1GB
checkpoint_completion_target = 0.9
effective_cache_size = 44GB
work_mem = 384MB
wal_buffers = 8MB
checkpoint_segments = 16
shared_buffers = 15GB
max_connections = 80
In the log I can see this error "FATAL: sorry, too many clients already" spamming the log non stop and "netstat -aonlp | grep 5432 | wc -l" return 250 connections to PostgreSQL. I tried to change max_connections = 80 to max_connections = 300 but this do not help because for short time "netstat -aonlp | grep 5432 | wc -l" return 700 connections to PostgreSQL.
The slave server is stopped all the time. What is causing this problem and why the server work just fine without replication configuration and if I add them the server freak out ?