Database Connect Fail

From Roaring Penguin
Jump to: navigation, search


Could not obtain DB handle: Failed to connect to database 'dbi:Pg:dbname=spam;connect_timeout=20': FATAL: ....


In the file /etc/postgresql/X.X/main/postgresql.conf (the X.X will be your PostgreSQL version number), there is a line for


the default of which is 100.

That number needs to be the sum of all MIMEDefang slaves in the cluster (determined by the line


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 the restart), 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