No internet connection
  1. Home
  2. Support

Database connection error and a question

By Radu @radu.crisan2018-09-21 13:07:09.498Z2018-09-21 13:46:48.802Z

Hello,

I want to ask if I need to create the Postgres database "talkyard" and user "talkyard" myself or is automatically created on the host machine ? And the POSTGRES_PASSWORD from ".env" should be the password for global access to Postgres databases or only the user ?

I have the following error :

500 Internal Server Error

Play Framework cannot connect to the database. Wrong database password? Or the database user doesn't exist? [EsE500BPWD]


debiki.Globals$DatabasePoolInitializationException: com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: FATAL: password authentication failed for user "talkyard"
	at debiki.Globals.tryCreateStateUntilKilled(Globals.scala:761)
	at debiki.Globals.$anonfun$startStuff$1(Globals.scala:680)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:655)
	at scala.util.Success.$anonfun$map$1(Try.scala:251)
	at scala.util.Success.map(Try.scala:209)
	at scala.concurrent.Future.$anonfun$map$1(Future.scala:289)
	at scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:29)
	at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:29)
	at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
	at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
	at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:81)
	at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:91)
	at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40)
	at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:43)
	at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
	at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
	at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
	at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: FATAL: password authentication failed for user "talkyard"
	at com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException(HikariPool.java:576)
	at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:562)
	at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
	at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)
	at debiki.Debiki$.createPostgresHikariDataSource(Debiki.scala:127)
	at debiki.Globals.tryCreateStateUntilKilled(Globals.scala:737)
	... 20 more
Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "talkyard"
	at org.postgresql.Driver$ConnectThread.getResult(Driver.java:403)
	at org.postgresql.Driver.connect(Driver.java:261)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:247)
	at org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:94)
	at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369)
	at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198)
	at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467)
	at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541)
	... 24 more

and in docker-compose logs app I have :

app_1      | {"message":"Error connecting to database, for HikariPool-332 [EsE7JK4]\ncom.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: FATAL: password authentication failed for user \"talkyard\"\n\tat com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException(HikariPool.java:576)\n\tat com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:562)\n\tat com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)\n\tat com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)\n\tat debiki.Debiki$.createPostgresHikariDataSource(Debiki.scala:127)\n\tat debiki.Globals.tryCreateStateUntilKilled(Globals.scala:737)\n\tat debiki.Globals.$anonfun$startStuff$1(Globals.scala:680)\n\tat scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)\n\tat scala.concurrent.Future$.$anonfun$apply$1(Future.scala:655)\n\tat scala.util.Success.$anonfun$map$1(Try.scala:251)\n\tat scala.util.Success.map(Try.scala:209)\n\tat scala.concurrent.Future.$anonfun$map$1(Future.scala:289)\n\tat scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:29)\n\tat scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:29)\n\tat scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)\n\tat akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)\n\tat akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)\n\tat scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)\n\tat scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:81)\n\tat akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:91)\n\tat akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40)\n\tat akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:43)\n\tat akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)\n\tat akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)\n\tat akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)\n\tat akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)\nCaused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user \"talkyard\"\n\tat org.postgresql.Driver$ConnectThread.getResult(Driver.java:403)\n\tat org.postgresql.Driver.connect(Driver.java:261)\n\tat java.sql.DriverManager.getConnection(DriverManager.java:664)\n\tat java.sql.DriverManager.getConnection(DriverManager.java:247)\n\tat org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:94)\n\tat com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369)\n\tat com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198)\n\tat com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467)\n\tat com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541)\n\t... 24 more\n","severity":"ERROR","serviceContext":{"service":"ed-app","version":"0.0.1"},"context":{"reportLocation":{"filePath":"Debiki.scala","lineNumber":130,"functionName":"createPostgresHikariDataSource","className":"debiki.Debiki$"}}}

Thank you for you answer!

Solved in post #2, click to view
  • 1 replies
  1. KajMagnus @KajMagnus2018-09-22 01:39:54.732Z2018-09-22 01:48:02.337Z

    Hi Radu!

    if I need to create the Postgres database "talkyard" and user "talkyard" myself or is automatically created on the host machine ?

    The talkyard user and database are created automatically, you don't need to do anything.

    created on the host machine ?

    Hmm no database is installed or needed on the host machine. Instead, there's a Docker container, with a PostgreSQL database. And it runs this setup script: https://github.com/debiki/talkyard/blob/master/docker/rdb/docker-entrypoint-initdb.d/init.sh, with does this: (among other things)

    create user talkyard password '$POSTGRES_PASSWORD';
    create database talkyard;
    grant all privileges on database talkyard to talkyard;
    

    The $POSTGRES_PASSWORD above is from the container's environment variables — and the environment variables come from the .env file. So, once you've typed a password in .env, you don't need to type it anywhere else — It gets added automatically to the PostgreSQL container environment, and, as you can see above, gets used automatically when creating the talkyard user.

    And the POSTGRES_PASSWORD from ".env" should be the password for global access to Postgres databases or only the user ?

    Only the user, and everything happens automatically (you just need to type a password in .env). Have a look above: create user talkyard password '$POSTGRES_PASSWORD';.


    Ok, so now it seems the PostgreSQL container, and the Play Framework config file, somehow use different passwords. Play Framework is the application server, and it uses the password in .env always, because of this line: talkyard.postgresql.password=${?POSTGRES_PASSWORD} in file /opt/talkyard/conf/play-framework.conf. (That line means "use the value of that environment variable", which comes from .env)

    However, PostgreSQL won't pick up changes, in .env, because the database user has been created already. So you need to do this, to update the PostgreSQL user's password:

    cd /opt/talkyard   # as root
    cat .env   # and copy the databas password
    docker-compose exec rdb psql talkyard talkyard   # logs in as user Talkyard to the Talkyard database
    talkyard=> alter user talkyard password '... the password ...';
    

    Thereafter, Play Framework should be able to connect and login to the database.

    (Maybe you'll need to do this: docker-compose restart app but I don't think so)

    (If there's any database on the host machine, it actually won't be accessible to Play Framework — Docker containers cannot access ports on the host machine. B.t.w. thanks for including the error messages and stack traces.)


    I'll update the installation instructions and add the below text, to make things clearer for others in the future :- )

       - A PostgreSQL database user named `talkyard` gets created automatically, with the
         password you type in the `.env` file (in `nano .env` above).
    
    ReplySolution