PG::connectionBad error in logs for Rails 5 heroku app, is mismatched IPs the reason? - postgresql

Heroku deleted my rails 5 app's database. I created a new DB, they recovered the old one and copied it to the new one, then attached it. But my site won't load. Heroku support hasn't tried to help beyond giving links to troubleshooting I've done many times. I've been trying every possible fix I can find for a week.
In the error message, I noticed the host that is listed for my database in the settings does not match the host in the timeout error.
MY HOST (per heroku settings): ec2-18-2XX-36-213.compute-1.amazonaws.com
The host in the logs: ec2-5X-83-25-2X7.compute-1.amazonaws.com
(I replaced a couple numbers with X b/c Idk if that's sensitive information)
Is that why the connection won't work? If so, how do I fix it?
FATAL -- : [465fe0b0-f387-4b4a-b215-779dbb8dbf7e] PG::ConnectionBad (connection to server at "ec2-5X-83-25-2X7.compute-1.amazonaws.com" (5X.83.25.2X7), port 5432 failed: Connection timed out

Turns out, all I needed to do was go into my new database's settings, copy the DATABASE_URL, go into the config vars of my app, and paste over the old DATABASE_URL.
So many wasted hours because heroku tech support couldn't articulate that. Took 5 seconds, then site loaded immediately. Didn't need to push anything, commit anything, change any code, etc

Related

Heroku Postgres filling up connections without any use

I have a Heroku Postgres DB(free tier) that's connected to my backend API for testing purposes. Today I tried accessing the database and I kept getting an error "too many connections for Role 'role'". Please note that I've not connected to this API today and for some reason, all 20 connections have been used up.
I can't even connect to the DB through PgAdmin to even try and kill some of the connections as I get the same error there.
Any help please?

my postgres is unable to connect ever since heroku did a maintenance update 12 hours ago

anyone facing something similar? sadly I'm on a free plan so I can't open a ticket... does anyone know of a way to restart the service/machine of the DB? maybe that would just solve it...
ok so the issue in my case is that indeed heroku performed some sort of maintenance on the DB, and apparently it's connection params (host/url/user/password) had changed... and since it was embedded throughout all my interfaces (the app, my db tools, admin app I also have) - none were able to connect (they'd timeout).
while trying to figure out, I used the wonderful CLI tools of heroku pg:info and heroku pg:diagnose and even heroku pg:psql and tested to see that my data is still there... eventually I went to the online admin and that's where I saw the connections params had changed. BTW - I have this project for 2 years and this is the first time this had happened...
I was in the same situation. Heroku will email you that your database is scheduled for maintenance. After it's complete, connecting to the database fails because of this error:
error: no pg_hba.conf entry for host "IP_ADDRESS", user "DB_USER", database "DB_NAME", no encryption
This is telling us that incorrect credentials were given, meaning the database connection string has changed. I first checked the credentials on the website for the Heroku Postgres Add-on (data.heroku.com), but the connection string was still the same as before; it has not updated or changed at all, therefore this was misleading. Instead, the updated connection string is found inside of the DATABASE_URL config variable, located in the Settings tab of your app on the Heroku dashboard (dashboard.heroku.com), under Config Vars. To avoid manually correcting this problem again, get the connection string from the DATABASE_URL config variable directly, as opposed to hard coding it in your app.
Yes, Im in the same situation. Heroku are a bunch of amateurs. They did some maintenance on the DB, and after it was done, credentials don't work, even those listed in admin/dashboard section of web. Bunch of loosers... #heroku

Cannot connect to Heroku MongoDB

I created an Ionic app with NodeJS backend and Mongo database and deployed it to Heroku (with mLab MongoDB add-on). It worked well for a day. The next day I was unable to connect to the DB. The app went to sleep in the meantime, but when I opened it in the browser it woke up. I know that because I saw the static text that I put on the index page. But a few seconds later, an error page appeared. From the console and network tabs output I could figure out that the app is unable to access the database and to fetch data.
I found a post on the internet where the author said that he had the same issue and that he deleted the db instance on Heroku and created a new one. So I did the same and then I was able to start my app normally again.
Today the same thing happened - I can't connect. When I switch the DB URI in the code to mongodb://localhost/mydbname and run the application locally, it works perfectly, so I concluded that the app code itself is fine, there's only an issue with connecting to the DB. It also wouldn't work locally if I try to target the DB on Heroku.
I thought that I might forgot the credentials, so I went to the Heroku dashboard and changed both the username and the password. Then I tried to connect through the console with mongo ds<number>.mlab.com:<port>/heroku_<name> -u <username> -p <password>. Here's the output:
MongoDB shell version v3.6.3
connecting to: mongodb://ds213239.mlab.com:13239/heroku_d3xjtj3x
2018-03-16T16:09:18.215+0100 W NETWORK [thread1] Failed to connect to 54.236.230.76:13239 after 5000ms milliseconds, giving up.
2018-03-16T16:09:18.216+0100 E QUERY [thread1] Error: couldn't connect to server ds213239.mlab.com:13239, connection attempt failed :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
Currently I'm using free version of both hosting and DB add-on, because I want only to test the app and to show it to my client (who will then decide if he wants to pay for the Heroku services). If I have nothing to show and if this happens each time, well, that would suck.
And here's the fun part: I wanted to try to open the app one more time so that I could copy and paste the exact error message here. And this time it worked normally! (???) The only thing I did is that I changed the username and pass on the DB dashboard, but I didn't push the updated code and I also didn't change it in the MONGODB_URI config variable.
Does anyone have an idea why does this happen? Is there a way to keep the DB awake and accessible (without paying extra)?
Thanks.
EDIT: It doesn't work again!!! Literally 30 seconds after submitting this post I tried to access the app again and it didn't work! There is an error page which says:
Error: Uncaught (in promise): [object Object]
at c (http://localhost:8100/build/polyfills.js:3:19752)
at c (http://localhost:8100/build/polyfills.js:3:19461)
at http://localhost:8100/build/polyfills.js:3:20233
at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15660)
at Object.onInvokeTask (http://localhost:8100/build/vendor.js:4973:33)
at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15581)
at r.runTask (http://localhost:8100/build/polyfills.js:3:10834)
at o (http://localhost:8100/build/polyfills.js:3:7894)
at e.invokeTask [as invoke] (http://localhost:8100/build/polyfills.js:3:16823)
at p (http://localhost:8100/build/polyfills.js:2:27648)
ONE MORE EDIT: I deleted the DB again, created a new one, changed the connection string in my app and pushed the changes. Now it works normally. I'll check again tomorrow and update this post.
NEW EDIT: One day later, the app doesn't connect to the DB again. And again I get the same error message.
Wtf, Heroku???

connect to localhost in MySQLWorkbench

I am trying to connect my MySQLWorkbench to localhost, so I can make a database. I have made the connection in the WorkBench, but everytime i test the connection I get a failure. The username and code is 100% correct. I also tried to make the port to 8888, but then workbench just goes in some kind of loop, where it is thinking all the time
I have made some screenshots of it, I hope anyone out there who can help me?
Best Regards
Mads
* EDIT: *
I tried to delete the connection, and made it over again. This time it seems that I can connect now. I tried to make a database ´test´ which functions. As the screenshot shows, I afterwords tried to make a database ´examples´, where I get the error in the console:
"12:59:32 CREATE DATABASE examples Error Code: 1044. Access denied for user ''#'localhost' to database 'examples' 0.000 sec"
For general informations about creating connections in MySQL Workbench watch my Youtube video: http://youtu.be/DCgRF4KOYIY?list=PLWx5a9Tn2EvH0q2WXpUBqptxi5640qk9O. It shows what can go wrong with addresses and ports.
Generally speaking, make sure that the user you are connecting with has the proper rights to 1) connect from the given machine (see in the video sometimes localhost is not equal to the IPv4 loopback address 127.0.0.1) and 2) has the rights to create objects, query them and so on. The root user usually has these rights, but sometimes, with custom installations, it can happen this has been changed.

Heroku PostgreSQL Connection reset by peer

We are using PostgreSQL Crane plan, and got a lot of log like this
app postgres - - [5-1] ... LOG: could not receive data from client: Connection reset by peer
We are using about 50 dynos.
Is PostgreSQL running out of connections with bunch of dynos?
Can someone help me explain this case?
Thanks
From what I've found the cause for the errors is the client not disconnecting at the end of the session, or a new connection not being created.
New connection solving the problem:
Postgres error on Heroku with Resque
Explicit disconnection solving the problem:
https://github.com/resque/resque/issues/367 (comment #2)
There's a Heroku FAQ entry on this: Understanding Heroku Postgres Log Statements and Common Errors: could not receive data from client: Connection reset by peer.
Although this log is emitted from postgres, the cause for the error has nothing to do with the database itself. Your application happened to crash while connected to postgres, and did not clean up its connection to the database. Postgres noticed that the client (your application) disappeared without ending the connection properly, and logged a message saying so.
If you are not seeing your application’s backtrace, you may need to ensure that you are, in fact, logging to stdout (instead of a file) and that you have stdout sync’d.