postgresql errors in spring boot - postgresql

I'm trying to use the Heroku postgresql add-on in my spring boot application (locally first). In my application properties, I removed the local server information and updated it with the Heroku credentials. I also added the posgresql dependency in my gradle file.
My code:
spring.datasource.url=jdbc:postgres://qfxqpoceljdtfo:f50b14498b7be95f0a1f4cf466b09b54ed8bbefaac9aa28a97b14719d0625e56#ec2-23-21-201-255.compute-1.amazonaws.com:5432/d6eqamh4egp1g0
spring.datasource.username=qfxqpoceljdtfo
spring.datasource.password=***Password***
spring.datasource.driver-class-name=org.postgresql.Driver
Heroku Credentials:
Host: ec2-23-21-201-255.compute-1.amazonaws.com
Database: d6eqamh4egp1g0
User: qfxqpoceljdtfo
Port: 5432
Password: ***Password***
URI postgres://qfxqpoceljdtfo:f50b14498b7be95f0a1f4cf466b09b54ed8bbefaac9aa28a97b14719d0625e56#ec2-23-21-201-255.compute-1.amazonaws.com:5432/d6eqamh4egp1g0
Heroku CLI: heroku pg:psql postgresql-metric-82455 --app battlesh1p
The resulting error is:
java.sql.SQLException: Driver:org.postgresql.Driver#20999517 returned null for URL
I've also tried using:
jdbc:postgresql://ec2-23-21-201-255.compute-1.amazonaws.com:5432/d6eqamh4egp1g0?sslmode=require
Which results in this error
org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "94.248.76.191", user "qfxqpoceljdtfo", database "d6eqamh4egp1g0", SSL off

In case anyone comes across this. The Heroku documentation worked fine in configuring my application to use the postgres database plug-in in production. But I could never get my spring app to run locally and access the host DB.

Related

Does heroku blocked connect to external databases? (postgres)

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?

How to run postgresql from Command line and know available Databases in Windows

I am very new to postgreSQL and struggling to create a connection in my Eclipese.
Here is what I have done till now:
Installed DBeaver plugin for eclipse from marketplace.
Installed PostgreSQL version 10 from https://www.postgresql.org/download/windows/
Now I attempt to create a connection in Eclipse but I get an error "FATAL: password authentication failed for user "testuser"
I checked through a similar thread (
Getting authentication failed error with postgresql from command line
) but could not resolve the issue.
Could you please help.
To connect the PostgreSQL via Command line you have to install a PostgreSQL provided tool called "psql" if not installed already.
Then use the below command to connect to PostgreSQL database.
psql -h localhost -p 5432 -U postgres
Explanation:
localhost: is the hostname of machine where PostgreSQL is installed.
5432 : is the default PostgreSQL port
postgres : is the username of to connect to DB
Solution for your issue:
FATAL: password authentication failed for user "testuser"
As error message specified, either user not exists on database or the password that you supplied to connect is incorrect. Re-verify your user and password, and try again.
All the best.

Heroku Postgres database : connecting from outside Heroku

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.

Heroku iOS Tutorial using Postgres

I am following the tutorial on Heroku on how to use heroku on iOS. The example uses a postgres database to store images and geolocation. I downloaded the postgres app on my Lion OSX and it says the postgres server running correctly. Now I am stuck on this step:
Update the config/database.yml file to reference the correct database user and password for >the development and test environments. Then create the local development database and run the >migrations.
$ bundle exec rake db:create db:migrate
== CreatePhotos: migrating ===========
-- create_table(:photos)
...
But I receive the following error:
could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
....
What did I do wrong? I tried to manually create the postgres database using the createdb command but I go the same connectivity error.
This error occurs when PostgreSQL is not listening on the socket specified. Causes can include (in order to check)
PostgreSQL not properly installed
PostgreSQL stopped or not running.
PostgreSQL listening on a different socket or in a different directory. This information is specified in the postgresql.conf.

How to create new database on heroku server with postgres

I want to create a PostgreSQL database on a Heroku server.
My database.yml is
production:
adapter: postgresql
encoding: utf8
database: ddb
username: postgres
port: 5432
password: admin
host: localhost
When I run heroku rake db:create it gives me the error:
mydatabase already exists
(in /disk1/home/slugs/181380_8d7032f_f439-4fe4f5a6-f181-4150-a968-fadcf45f0af5/mnt)
I have tried it for various different database names, but get the same message.
How can I resolve this error?
heroku autogenerates database.yml on the deploy. Reads like: it doesn't matter what you put in your database.yml, which to me is nice, as I can include it in git without worrying about production db passwords.
You may choose another database by setting the ENV['DATABASE_URL'] (use heroku config:add DATABASE_URL=....)
Check heroku documentation
https://devcenter.heroku.com/articles/ruby-support#build-behavior