Heroku + Rails + PG: ActiveRecord::StatementInvalid (PG::ConnectionBad: PQconsumeInput() SSL connection has been closed unexpectedly

前端 未结 2 1126
攒了一身酷
攒了一身酷 2021-02-20 03:52

I am receiving randomly and very frequently the following error in my logs:

Nov 06 05:31:21 lmrapp app/web.2:  [wbinternacional] [0f0965e3-e537-4aed-8f3e-311a222         


        
相关标签:
2条回答
  • 2021-02-20 04:39

    I get this problem all of the time and it is very annoying. Specially when you are trying to build an app and don't want to pay $50 / month while still in development. One of the biggest things that I have noticed helps is to make sure you don't have something like DB Visualizer or another DBMS running while you are developing. I know it seems counter intuitive but it definitely helps to keep the db pool freed up.

    Also, if you are running RoR you can try adding pool: 1 to your default connection string to ensure your app is not trying to connect to postgres more than your postgres settings will allow on Heroku.

    default: &default
      adapter: postgresql
      encoding: unicode
      pool: 1
    

    Hope this helps some people out there!

    0 讨论(0)
  • 2021-02-20 04:55

    I'm getting the exact same error. I also am on a Heroku Hobby-basic db. I raised a ticket with Heroku, here was the response:

    The "SSL connection has been closed unexpectedly" error (and a few similar ones) is a client-side error indicating your database connection has gone away. One of the limitations of the hobby tier databases is unannounced maintenance. We will occasionally need to close some connections to hobby tier databases, and when we do that, the app will often see an error like this one.

    Most apps that maintain a connection pool (like ActiveRecord in Rails) can just open a new connection to the database. However, in some cases an app won't be able reconnect. If that happens, you can heroku restart that dyno to get a new process on a new runtime.

    Running hobby tier databases in production isn't generally recommended. If you're going to, though, it's helpful to configure your app to actually crash on repeated database connection errors—that way, it will start on a new runtime with a new connection pool automatically.

    It looks like this has been happening a lot to you, though; int that case, I'd recommend a pgbackups:transfer to move the database to another shared server. Keep in mind that hobby tier rules apply to the $9 basic plan as well as the free database. Let me know if you have any further questions. Thanks!

    To me this basically means Heroku doesn't care to fix this error and wants you to upgrade to the $50 database. Now I'm running a small site where I get 4-5 users/day - there is no way I want to switch to a production site as of yet. I am getting the same error you mentioned at least 5-6 times/day and still haven't figured out a way to fix this. Try switching your db to another shared server - this does not work for me.

    0 讨论(0)
提交回复
热议问题