I have added a configured postgres database add-on to a heroku app.
When I try to connect to the database outside the heroku (from my local machine) it always gives an error
SSL SYSCALL error: Connection reset by peer (0x00002746/10054)
I have tried connection from Heroku CLI as well as PGAdmin. I have tried configuring SSL mode to Require.
psql -h ec2-79-125-6-82.eu-west-1.compute.amazonaws.com -U d168639egmjee csjpgbglovnmah
Any idea how can I connect to the postgres DB added in heroku app?
Any help will be appreciated.
Related
Is it possible to run pgbench on heroku?
I see here it's a CLI argument (not a postgres command)
As of nearly 10 years ago, it wasn't a thing. But is it now? https://github.com/heroku/heroku-pg-extras/issues/7
When you connect to your Heroku database using heroku pg:psql you actually use a psql running locally on your machine to connect to the remote server.
Similarly, you should be able to use a local pgbench even though there isn't a Heroku CLI wrapper for it. Retrieve your database connection information using heroku config:get DATABASE_URL or heroku pg:credentials, then run the command with the common connection options:
pgbench -h HOST -p 5432 -U USER DATABASE_NAME
Since it is a standard URI, you can pull the hostname, username, password, and port out of Heroku's database URL like so:
postgres://user:password#host:port/database
i had running my app on heroku for almost a year without any problem, my app update a postgres database on one external server and read from it, suddenly my app stopped writing and reading to/from my database apparently at the end of February, what i found in logs is that heroku is trying to connect to heroku postgres servers instead of my external database:
2022-04-16T18:32:21.042608+00:00 app[web.1]: original: error: no pg_hba.conf entry for host "52.50.8.208", user "username", database "database", SSL off
The ip 52.50.8.208 is not mine, that ip is changing every xx time, so that is why i think is from the heroku postgres service
heroku is ignoring my config var "DATABASE_URL" where i have: postgres://username:password#myserverip:port/database but heroku is trying to connect to their heroku postgres servers instead of my server ip, heroku is trying to connect with the username, password, port and database on my config var but its ignoring my server ip...
Does anyone knows if there was a change or why is ignoring my server ip on my config vars?
I have a Heroku app and it has a Heroku postgres addon attached. Im trying to connect to the remote heroku database from the Gitpod (online IDE) command line.
heroku pg:psql -a my-heroku-app
But its giving the following error:
--> Connecting to postgresql-rigid-XXXXX
psql: error: could not connect to server: FATAL: role "xxxxxxxxxxxxxxx" does not exist
And I get the same error when I try to connect with the connection URL
psql postgres://xxxxxxxxxxxxxxx:ppppppppppppppppp#ec2-0000000000.compute-1.amazonaws.com:5432/ddddddddddddd
I have properly installed postgres and heroku-cli in Gitpod and they work fine.
Appreciate your help.
Thanks!
Ok I found the answer thanks to this and this.
heroku pg:psql does'nt seem to work in Gitpod. So I followed this to import a db dump file into heroku postgres. From Gitpot command line I did
pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump
and got the db dump file from my local (Gitpod) database. Uploaded it to my google drive and got the publicly downloadable link. Then did
heroku pg:backups:restore https://drive.google.com/u/0/uc?xxxxxxxx DATABASE_URL -a my-heroku-app
Now I have all the data in my heroku postgres database.
Cheers!
I'm trying to get my GCP Compute Engine instance, Ubuntu 16.04, connected to a GCP Cloud SQL PostgreSQL database.
I've followed all the instructions in the documentation, but when I enter the command to connect to the database:
psql -h [CLOUD_SQL_PUBLIC_IP_ADDR] -U postgres
The result is:
psql: FATAL: Peer authentication failed for user "postgres"
I've done the authentication on both the CloudSQL side and the ComputeEngine side, so I'm not sure why this is going wrong.
The database I'm trying to connect to is in the same project, and the command
gcloud sql instances list
shows the database in the listings. However, the command
sudo -u postgres psql my-db
returns
psql: FATAL: database "my-db" does not exist
The expected result is that a psql connection opens, but instead I get a psql: FATAL: Peer authentication failed for user "postgres".
I've followed the instructions from the documentation you posted and I was able to connect successfully from my Compute Engine instance (Ubuntu 16.04) using a public IP address.
The steps I've followed are documented in "Connecting using a public IP address":
1- Added a static IPv4 IP address to the Compute Engine instance. To do this, navigate to the Cloud console > VPC Network > External IP addresses and click in the button "Reserve static address".
2- Authorize the static IP address of the Compute Engine instance as a network that can connect to the Cloud SQL instance.
3- Connect via SSH button to your Compute Engine instance.
4- Install the psql client:
$ sudo apt-get update
$ sudo apt-get install postgresql-client
5- find the CLOUD_SQL_PUBLIC_IP_ADDR
$ gcloud sql instances list:
6- And connect to the Cloud SQL instance with the psql client making sure both user and database do exist:
$ psql -h [CLOUD_SQL_PUBLIC_IP_ADDR] -U [USER] -d [DATABASE]
Also, the command below worked fine for me:
$ psql [USER] -h [CLOUD_SQL_PUBLIC_IP_ADDR] -d [DATABASE]
Then you will be asked for the user's password and voilĂ .
Could you please try following the instructions above to verify if it works fine for you?
Did you configure an encrypted connection before using SSL?
I have Amazon EC2 instance running Ubuntu. I have installed and configured PostgreSQL.
Contents of the file /etc/postgresql/9.3/main/pg_hba.conf:
local all all md5
host all all 0.0.0.0/0 md5
Also in postgresql.conf
I have set listen_addresses='*'.
The test command below is successfully starting psql console.
psql -U postgres testdb
Now I am trying to connect pgAdmin4 from MacOS.
I have created a SSH tunnel with following command:
ssh -i ~/.ssh/test.pem -fN -L 5433:localhost:5432 ubuntu#mytestdomain.com
Now I have following details in pgAdmin:
When I save, I get this output:
Unable to connect to server: server closed the connection unexpectedly. This probably means the server terminated abnormally before or while processing the request.
What am I doing wrong ?
Here is the solution,
install pgadmin 4 into your system. and configure the below-added configurations. if the below configurations do not work then please check that DB user permissions on AWS. because of the restriction on IP level so it may not be able to access.