FATAL: too many connections for role "kong"

Hello,

I’m running Kong in DB mode with Postgres and I’m finding it’s exhausting all my DB connections. My suspicion is that Kong isn’t releasing/closing DB connections properly after it uses them.

I’ve setup a “kong” postgres user that’s the owner of the “kong” database. I set the max_connections for the “kong” PG user to 200. Seems like 200 max connections should be more than enough for an API gateway proxy.

However, frequently Kong is throwing an error like the one below.

2019/10/09 17:54:05 [error] 31#0: *37149566 [kong] init.lua:98 FATAL: too many connections for role “kong”, client: 127.0.0.1, server: kong_admin, request: “GET /services HTTP/1.1”, host: “localhost:8444”

  1. Is the Kong Admin API the only component that connects to the DB or does Kong ingress controller connect to the DB too?

  2. Assuming Kong is properly closing its DB connections what would you recommend for max_connections? Disabling max_connection on the “kong” DB user results in all PG connection slots being exhausted and my other apps fail to acquire a DB connection because Kong takes all the connection slots.

  3. Is there any other suggestions you’d recommend to resolve this issue?

Have a look at the pg_max_concurrent_queries config value (https://docs.konghq.com/1.3.x/configuration/#postgres-settings); it was implemented exactly for this problem :slight_smile:

1 Like

I tried this config in my test environment, and it does not work

We’re facing the same issue since last week in production.

We’re running kong gateway as KIC setup with both proxy and ingress containera running inside pod replicated to 3 on separate worker nodes. DB is postgres and on progress max connections settings it is allowed to have 1000 max connections.

Twice kong gateway has restarted with errors showing the same error- too many connections for the Role kong. Errors keep on occurring resulting to auto pod restart. As checked on Postgres end max connections reached to only 50-55.

Can anyone help here to check what’s wrong with Kong? And how to troubleshoot why kong is restarting without reaching to postgres max connections limit.