I am trying to deploy a spring boot app connecting to postgresql
yvsivateja
FREEOP

4 months ago

Hello Railway Support Team,

I am having trouble connecting my Spring Boot application to PostgreSQL.

-- connection config
spring.datasource.url=jdbc:${DATABASE_URL}
spring.datasource.username=${PGUSER}
spring.datasource.password=${PGPASSWORD}


2026-02-23T10:29:52.031Z ERROR 1 --- [           main] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution [The connection attempt failed.] [n/a]


Both services are in the same Railway project. 
Solved$10 Bounty

3 Replies

Status changed to Awaiting Railway Response Railway 4 months ago


Are you trying to connect to the database during the build time?

Also, is your database online, running, and healthy?


yvsivateja
FREEOP

4 months ago

Yes my database is healthy and trying to connect during the deploy. Also when I give the values directly it is able to connect. Only problem I see is when trying to connect through variables.


yvsivateja
FREEOP

4 months ago

I have modified the variables to PG_ as prefix(e.g., PG_USER) and assigned the values to it. Also I changed my url to

spring.datasource.url=jdbc:postgresql://${PG_HOST:localhost}:${PGPORT:5432}/${PG_DATABASE:postgres}

Then for some reason it worked without any issues.


Status changed to Solved sam-a 4 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...