3

this is the error I get when I'm trying to connect to my local postgresql db:

Cannot connect to database [default]

this is the database configuration. I'm convinced that there is not typo (fat finger error):

db.default.url="postgres://localhost:5432/myproject/"
db.default.user="postgres"
db.default.pass="mypassword"
db.default.driver="org.postgresql.Driver"
db.default.initSQL="SELECT 1" 

where is the problem? with pgAdmin I can connect easily
p.s.
I'm using ubuntu. I've noticed that in order to change to postgres user
I must use "su", otherwise it fails changing the current user.
is that has something to do with play! failure to connect my db?

thanks

socksocket
  • 3,837
  • 10
  • 39
  • 66

3 Answers3

2

There might be two things wrong or at least dubious in your setup.

First: The postgres:... URL syntax is not a plain JDBC URL. This format is not understood by the PostgreSQL JDBC driver. See this answer to a similar problem.

Second: You are trying to use the PostgreSQL superuser account for Play. The superuser account should be used only for administrative work, but not "normal" work. Especially not for work which includes public access to the DB via some webfrontend. Any SQL-Injection attack gives the attacker the golden key to your database - including the nuke to wreck your complete DB cluster at once or install any backdoor into you DB server.

So I recommand, that you create a new user which you configure in your Play! settings.

That said: The default password for the postgres user is not set on Ubuntu. This setup allows login to the DB user only from the same OS user. How you can fix this is explained in this answer.

If these two tips don't help: The error you quoted is very vague. There must be more detailed error logs somewhere. Please find them and attach them to your question with the "edit" button.

Community
  • 1
  • 1
A.H.
  • 57,703
  • 14
  • 82
  • 113
2

This is not an answer directly to your question, but I had the same error message and came here via Google. Using Scala Play 2.3, I had

db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://127.0.0.1:5432/noob_development"
db.default.logStatements=true

which needed to be

db.default.driver="org.postgresql.Driver"
db.default.url="jdbc:postgresql://127.0.0.1:5432/noob_development"
db.default.logStatements=true

I accidentally left the quotes around the driver name out. Now it works perfectly.

Neal
  • 4,178
  • 33
  • 33
2

here is my conf, it works:

db.default.url="jdbc:postgresql://127.0.0.1:5432/dbname"
db.default.driver="org.postgresql.Driver"

just add the jdbc: before postgresql in db.default.url.

xring
  • 668
  • 8
  • 25