1

I am working on the free and fair use of Heroku for a Rails Postgres application. Regarding the pricing on Heroku Postgres, I can see a connection limit (set to 120 for the cheapest offer).

What does this connection limit mean? I have seen it which may deal with the parameter max_connections but even that, I do not really get how it works.

If I have my rails server receiving an order and request my database for an update or simple select with always the same database Postgres user: does it count for one connection? I do not think so but I would like to get more details on this limit.

Thank you very much.

1 Answer 1

1

max_connection defines the number of Postgres instances running simultaneously to serve queries. max_connections open up multiple connection for same postgres user. It can increase performance in some cases but this can lead to poor performance like these:

  • Disk contention: If you are using disk(not RAM) then more tables and indexes to be accessed at the same time, causing heavier seeking all over the disk
  • RAM: This leads more RAM usage.
  • Synchronization: You need to handle synchronization of multiple instances which will effect the overall throughput.

If you are user base increases, then you may face too many clients error due to limited number of connections. Then there is a concept of

The solution is to two fold:

  • pool connections: If Postgres is failing to handle the situation, you can use tools like pgbouncer, repmgr and PgPool to handle pool connection before going to Postgres.
  • Application optimization: Try to open as less connections as possible and close the connection as soon as work is done.

You can study further on this from following links:

You can study particularly for Ruby here: https://devcenter.heroku.com/articles/concurrency-and-database-connections#maximum-database-connections

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.