akka.presistance.postgresql too many clients already

33 views Asked by At

I'm using the akka.presistance.postgresql library and due to a large amount of actors running in parallel, I'm facing the "sorry, too many clients" exception.

I wonder what is the best way to deal with it, as far as I can see, limiting the creation of the actors is not ideal as I am ignoring the parallelization benefits of the actor system.

I can raise the max_connection in my postgres, but this is not scalable. I can maybe set a limit to the actor system (is it possible to set this?), though again this means I'm limiting my system, and with more then one app calling the postgres not scaleable. Is there a way to deal with it in code, in a way that will not forcibly slow down the actor system?

1

There are 1 answers

2
David Ogren On

All Akka persistence plugins that I know of use connection pooling; the Postgres ones certainly do.

Look at the reference config for your persistence plugin: https://doc.akka.io/docs/akka-persistence-r2dbc/current/config.html or https://doc.akka.io/docs/akka-persistence-jdbc/current/configuration.html#reference-configuration

It looks like the default is to use a max of 5 connections for the old plugin and 20 for R2DBC. Both would be per node, per plugin. So you could either adjust the pool in Akka to be smaller or increase your max_connections to be bigger. But it has absolutely nothing to do with the number of Actors: there is a connection pool in use.