Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku and Postgresql and Rails - too many connections error

I'm getting the following error with Ruby on Rails, Heroku and Postgresql:

PG::Error (FATAL:  too many connections for role "********"

I've restarted the server several times to no avail. Any ideas?

like image 908
sabes Avatar asked Aug 17 '12 02:08

sabes


People also ask

What is Heroku connection limit?

Heroku provides managed Postgres databases. Different tiered databases have different connection limits. The Hobby Tier databases are limited to 20 connections. Standard and higher tier databases have higher limits.

Can Postgres handle multiple connections?

PostgreSQL Connection Limits At provision, Databases for PostgreSQL sets the maximum number of connections to your PostgreSQL database to 115. 15 connections are reserved for the superuser to maintain the state and integrity of your database, and 100 connections are available for you and your applications.


1 Answers

Paying Heroku more money isn't always the answer.

I had this problem temporarily when I was running up against the dev-level database's row limit. Deleting rows using the console until I was below the limit solved the issue.

Another potential way you can run into this is if you're using unicorn. The number of connections used is the number of dynos times the number of unicorn workers per dyno. Heroku explains it all here, along with a way to configure it in config/unicorn.rb.

Also, seeing the number of connections being used can be useful. Just run heroku pg:info.

like image 88
Jonathan Tran Avatar answered Oct 30 '22 00:10

Jonathan Tran