0

I am using node Postgress and I would like to use connection pooling with it. I have simple repository like this:

Init

    const pool = new Pool({
        connectionString: process.env.DATABASE_URL,
    })

    await pool.connect()

Example SELECT code..

export default (
    {
        pgPool,
    }: Object
) => {
    return { 
        getExampleData: async (uid: string) => {
            const result = await pgPool.query('SELECT data FROM public.results_table WHERE uid = $1::text;', [uid])
            return result.rows
        },
    }
}

My problem is, that under pressure (a lot of requests) I am getting the following error:

error: remaining connection slots are reserved for non-replication superuser connections

I am not sure, if I am using pool correctly.

ford04
  • 66,267
  • 20
  • 199
  • 171
jimodefax
  • 53
  • 5
  • How much is 'a lot of requests'? We use pgpool, haproxy, PHP. Apache and have a lot of clients and don't get any issues. However, we have tuned everything to have abut 2000 simultaneous clients. Two servers, one master, one slave and 8 cores with 16GB ram and 2TB HDDs using NFS. – Mr. de Silva Sep 28 '19 at 07:53
  • 20/s :-D It is testing DB, there is a 25 connections slots, 1GB ram... – jimodefax Sep 28 '19 at 07:59

1 Answers1

0

Part of our pgpool.conf:

# - Pool size -

num_init_children = 100
                                   # Number of pools
                                   # (change requires restart)
max_pool = 3
                                   # (change requires restart)

# - Life time -

child_life_time = 120
                                   # Pool exits after being idle for this many seconds
child_max_connections = 0
                                   # Pool exits after receiving that many connections
                                   # 0 means no exit
connection_life_time = 90
                                   # Connection to backend closes after being idle for this many seconds
                                   # 0 means no close
client_idle_limit = 0
                                   # Client is disconnected after being idle for that many seconds
                                   # (even inside an explicit transactions!)
                                   # 0 means no disconnection

The following question/answers also should help you:

Heroku “psql: FATAL: remaining connection slots are reserved for non-replication superuser connections”

Trust this helps.

Mr. de Silva
  • 382
  • 2
  • 11