I can't connect to db using this code in application.conf:
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgres:my_db123_dev"
db.default.user=my_user
db.default.password=123
The error: play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
I'm not specifying localhost in there because it should be it by default.
I believe it should be postgresql, not postgres in your db.default.url.
Also, while the stuff below might not matter completely, it's good best practice:
Change db.default.url to jdbc:postgresql://localhost/my_db123_dev (having localhost there is always good).
Put quotes around your username and password, because it's good form.
Related
I am build REST api using play framework 2.8 , I am able to start the application and call some service. Facing issue when trying to connecting with postgres database. Logs are below -
Error opening connection for database: {}org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "3.87.112.32", user "abc", database "xyz", SSL off
Tried looking solution for this and foudn have to add sslmode=require in query param while connection to database.
When log the url sslmode is already mentioned.
jdbc:postgresql://abc.amazonaws.com:5432/xyz?password=1234&sslmode=require&user=xyz
I am reading this property from heroku env variable JDBC_DATABASE_URL for obtaining database connection.
This issue can be fixed by adding addition query parameters apart from sslmode=require which are ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory after adding this the new URL become jdbc:postgresql://abc.amazonaws.com:5432/xyz?password=1234&sslmode=require&user=xyzssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory
I have database connection settings and pgAdmin (it is all that i have). Can I connect to the database through the pgAdmin to make the necessary changes in the database using these settings? If so, how?
I have not found how I can do this. Other answers here (and in google too) suggest writing Java-code - this is not what i need. I want to use pgAdmin interface for it. Can I make changes without using Java-code?
Here example of settings that i have:
jdbc.driverClassName - org.postgresql.Driver
jdbc.url - jdbc:postgresql://localhost:4444/
jdbc.username - username
jdbc.password - password
I don't understand why people don't understand what he's trying to do. He just wants to connect to db using pgAdmin. He just doesn't understand how to use the connection string in pgAdmin.
Basically, just remove all prefixes and suffixes (eg. jdbc:postgresql://). So your hostname is localhost. Type localhost in host name, 4444 in port name as well as your username and password. Also give it a name in General tab Then you'll see the databases on the left. Click Tools > Query Tool and write your select/insert etc. scripts.
I have postgres with hba configuration file and pgbouncer for connection pooling.
I want to connect to pgbouncer (instead of postgres) only by changing the port number of the connection string (6543 instead of 5432). Both postgres and pgbouncer run on the same server.
So far, I've been able to have pgbouncer run with its own hba file with duplicated user/password. It's not maintainable (or at least very painful) to manually sync postgres and pgbouncer user/password.
Is there any way I can make pgbouncer forward user/password login attempts to postgres as-is? Or am I trying to work my conf against the way things should go?
Which version of pgbouncer do you use? Starting from 1.6 it is able to load users/passwords directly from database. You just need to specify "auth_query"
in your config file.
https://pgbouncer.github.io/config.html
Update: It seems to be problem with ElephantSQL, the service I'm using according to this
However, I dont know where to add this.
Exact error:
FATAL: 28000: no pg_hba.conf entry for host "host", user "username", database "template1", SSL off
Similar error to this problem. Even after adding SslMode=require, I still couldn't connect to the database.
<add name="DefaultConnection" connectionString="Server=serverip;Port=5432;Database=dbname;User Id=username;Password=pass;CommandTimeout=60;Preload Reader=True;"/>
Weird thing is that it tried to connect to template1 instead of database specified in the connection string.
Connecting through pgadmin is fine though.
It's because you're on a shared ElphantSQL plan and can only connect to your own database. Npgsql tries to connect to template1 for some reason when it's checking server version, creating new databases etc, ignoring the database name given in the connection string. We'll submit a bug report to Npgsql.
I am 4 years late to this party but had this issue with npgsql also and this question came up so hopefully this helps someone else in the same boat next time.
I was able to fix it by adding "EF Template Database=[MyDatabase]" to my connection string. The default for that value is "template1" according to npgsql documentation
For a system that I am using, I run into the problem pasted on the title when I try to drop a database and recreate it. More specifically, this is the exact problem that I am facing:
Couldn't drop staging_databse : #<PG::ConnectionBad: FATAL: no pg_hba.conf entry for host xxx.xx.xxxx.xxx, user "ruby", database "postgres", SSL off
I've done some research regarding this problem and it seems that the solution is simply to turn on SSL. I've consulted Postgresql Documentation on pg_hba.conf but I'm unable to find this configuration file.
I typed in locate postgresql and I noticed that there is a postgresql-client-9.2 installed on the system. From what I have determined, I won't find this pg_hba.conf file because the client doesn't have it. I've also looked for the postgresql.conf file on SSL according to the official documentation but this file is not included either.
Finally, the documentation shows me this configuration option of the pgsql 9.2 client shown below:
libpq reads the system-wide OpenSSL configuration file. By default,
this file is named openssl.cnf and is located in the directory reported by
openssl version -d. This default can be overridden by setting environment
variable OPENSSL_CONF to the name of the desired configuration file.
However, this too isn't in my system. I've run the linux find command and this file doesn't seem to be there. I've run out of leagues and I have a sneaking suspicion that I am overlooking something very simple. Is there any other leads I can go on? Thanks.
Based on this message and the rest of the context:
FATAL: no pg_hba.conf entry for host xxx.xx.xxxx.xxx, user "ruby", database "postgres", SSL off
It looks plausible that:
you're connecting to a remote PostgreSQL instance which you don't administrate because you're acting as developer, not admin.
the db management layer tries to connect to the database named postgres in order to drop another database (staging_database) . It's necessary indeed because we can't drop a database when we're connected to it (in fact, a database can't be dropped when anyone is connected to it).
the admin policy established by the remote pg_hba.conf is such that your login and IP address together are not allowed to connect to the database named postgres
These facts combined together imply that you're missing the necessary rights to drop your database, even if indirectly.
At this point you want to submit the problem to the admin responsible for that PostgreSQL server.