Sorry too many clients when trying to connect to PostgreSQL database server – solution

Q. I am running PostgreSQL server for my web application and I am getting an error “Sorry too many clients when trying to connect to PostgreSQL”. How do I troubleshoot this database error?

ADVERTISEMENTS

A. This error indicates that you have reached the default limit set in your configuration postgresql.conf file. Under FreeBSD default limit is 40 database session. You need to increase this level.

Please note that increasing this level costs about 500 byes of shared memory per connection slot, in addition to costs from shared_buffers and max_locks_per_transaction.

Edit file /usr/local/pgsql/data/postgresql.conf (FreeBSD) or /var/lib/pgsql/data/postgresql.conf (Red Hat Linux) or /etc/postgresql/postgresql.conf (Debian Linux):

# vi /usr/local/pgsql/data/postgresql.conf

Locate parameter max_connections and set new value. For example if you want to 300 database session, it should read as follows:

max_connections = 300

Save the file and restart postgresql server. If you are using FreeBSD restart postgresql with following command:

# /usr/local/etc/rc.d/010.pgsql.sh restart

On the other hand, if you are using Debian Linux, restart postgresql with following command:

# /etc/init.d/postgresql restart

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
2 comments… add one
  • Bighnaraj Swain Feb 23, 2009 @ 5:59

    I am using ubuntu in my PC. I am trying to install postgres in my PC but the following message is displaying.

    Reading package lists… Done
    Building dependency tree… Done
    Package postgresql is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    However the following packages replace it:
    postgresql-common postgresql-client-common
    E: Package postgresql has no installation candidate

    with regards
    Raj

  • Srini Mar 19, 2012 @ 12:24

    HI,

    if u r ruuning more than one Pg DB Versions. this error is beeing populated at times.

    Check u service which are versions are running. This got fixed after we stopped unused db versions.
    try from u r side.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.