DB Handle Error

From Roaring Penguin
Jump to: navigation, search

Symptom:

Could not obtain DB handle: Failed to connect to database 'dbi:Pg:dbname=spam;host=192.168.176.201;connect_timeout=20': FATAL: remaining connection slots are reserved for non-replication superuser connections at /usr/share/perl5/CanIt/DB/Single.pm line 271 at /usr/share/perl5/CanIt/DB/Single.pm line 271

Resolution

By default, PostgreSQL is configured to allow 100 connections in total, and when you have a Cluster or a number of users, you can exceed this arbitrary limit, so you just need to increase it. In the file /etc/postgresql/X.X/main/postgresql.conf (the X.X will be your PostgreSQL version number), there is a line for

       max_connections

The default of which is 100. That number needs to be the sum of all MIMEDefang slaves in the Cluster, as is determined by the line:

       mx_maximum=

in the [mimedefang] section) of the /etc/mail/canit/canit.conf file, PLUS the number of expected simultaneous human connections. The change takes effect when PostgreSQL is restarted, typically via

       /etc/init.d/postgresql restart

If you're using automatic DataBase failover, disable it before restarting the Master, of course, and don't forget to increase the value on it as well! If increasing max_connections causes an error like:

   Failed system call was shmget(

(which you'll see on-screen immediately upon restarting PostgreSQL) Then you need to increase that as well.

After creating the line (if it's not there already) for kernel.shmmax in:

   /etc/sysctl.conf

Set it to be slightly larger than the amount it says it needs. For example, if it wanted 128000000, you could set

   kernel.shmmax = 134217728

And to make that take effect, execute

   sysctl -p