14

I'd like to configure PostgreSQL for my Play app, but am getting the following error:

! Internal server error, for request [GET /] ->

java.util.concurrent.TimeoutException: Futures timed out after [300000] milliseconds    at
akka.dispatch.DefaultPromise.ready(Future.scala:834)
~[akka-actor.jar:2.0]   at
akka.dispatch.DefaultPromise.result(Future.scala:838)
~[akka-actor.jar:2.0]   at akka.dispatch.Await$.result(Future.scala:74)
~[akka-actor.jar:2.0]   at
play.core.ReloadableApplication.get(ApplicationProvider.scala:108)
~[play_2.9.1.jar:2.0]   at
play.core.server.Server$class.sendHandler$1(Server.scala:59)
[play_2.9.1.jar:2.0]    at
play.core.server.Server$$anonfun$getHandlerFor$4.apply(Server.scala:89)
[play_2.9.1.jar:2.0] [error] application - 

! @6a64i2p5o - Internal server error, for request [GET /] ->

play.api.PlayException: Not initialized [?]     at
play.api.PlayException$.apply(Exceptions.scala:122)
~[play_2.9.1.jar:2.0]   at
play.core.ReloadableApplication.<init>(ApplicationProvider.scala:94)
~[play_2.9.1.jar:2.0]   at
play.core.server.NettyServer$$anonfun$mainDev$1.apply(NettyServer.scala:165)
~[play_2.9.1.jar:2.0]   at
play.core.server.NettyServer$$anonfun$mainDev$1.apply(NettyServer.scala:164)
~[play_2.9.1.jar:2.0]   at
play.utils.Threads$.withContextClassLoader(Threads.scala:17)
~[play_2.9.1.jar:2.0]   at
play.core.server.NettyServer$.mainDev(NettyServer.scala:163)
~[play_2.9.1.jar:2.0]

I use the following configuration files:

application.conf

db.default.url="postgres://play:play@localhost:9000/Play_Playground_DB"
db.default.user=play
db.default.password=play
db.default.driver=org.postgresql.Driver

project/Build.scala

val appDependencies = Seq(
  "postgresql" % "postgresql" % "9.1-901.jdbc4"
)

I set up Play_Playground_DB and can access it via terminal and the command psql Play_Playground_DB.

What could be the root cause of the issue?

Jacek Laskowski
  • 64,943
  • 20
  • 207
  • 364
Thomas Kremmel
  • 13,615
  • 21
  • 104
  • 169
  • That URL is not anything PostgreSQL would recognize; presumably the framework is taking that apart and picking out the pieces needed? Also, I recommend that you read this section and update your driver jar: http://jdbc.postgresql.org/download.html#current – kgrittn Apr 23 '12 at 15:16
  • Thanks! Updated it to the current version. – Thomas Kremmel Apr 23 '12 at 17:31

2 Answers2

24

Most probably this is the problem:

db.default.url="postgres://play:play@localhost:9000/Play_Playground_DB"

The play doku says, "db.default.url" is a plain JDBC-URL. There are two problems with your value:

  • It is not in a format recognized by PostgreSQL. Look here for allowed formats.
  • With ...default... you redefine the default datasource. By default this calls for trouble unless you do some more steps.

A valid PostgreSQL URL might look like this in your case:

jdbc:postgresql://localhost:9000/Play_Playground_DB

But:_ Are sure your database is running on port 9000? You say psql Play_Playground_DB works for you. Therefore I think your port should be the default port 5432. Then this URL is the right one:

jdbc:postgresql://localhost/Play_Playground_DB
Chris Cooper
  • 16,224
  • 8
  • 50
  • 70
A.H.
  • 57,703
  • 14
  • 82
  • 113
  • Thanks, the last URL you postet is the solution. Works now! Just wondering why it is described here differently: https://github.com/playframework/Play20/wiki/SettingsJDBC – Thomas Kremmel Apr 23 '12 at 17:32
  • I used this config: db.default.url="jdbc:postgresql://localhost/Play_Playground_DB" – Thomas Kremmel Apr 23 '12 at 17:35
  • @TomTom: Regarding the github link: This is about "BoneCP", a connection pool which is wedged between the DB and the application/framework. Using a connection pool often requires non-standard URLs. – A.H. Apr 23 '12 at 17:42
  • I am using Play 2.0.4 and got it to work without adding jdbc: to the URL. However, you are likely to be running your PostGres on the default port (5432), especially as 9000 is the default HTTP port Play uses. – Siddhu Mar 23 '13 at 12:28
  • For anyone having the same issue, this is the correct answer, however I had to execute `reload` from the Play! console because modifying Build.scala won't take effect unless you exit the console, or execute `reload`, then execute `dependencies`. – Yanick Rochon Jul 21 '13 at 10:42
5

On my OSX, I've installed PostgreSQL from homebrew and current version is 9.3.4

The connection strings described above do not work for me because they are using postresql database name. My connections are established if and only if I specify like:

db.default.url="postgres://user:password@localhost/MyDbName"

Notice that it is postgres instead of postgresql.

Surge
  • 103
  • 1
  • 8