Can someone explaining why I am receiving this error when I run 'mvn test' at the root of my project? It is a Spring JPA application. Database configuration is in the application.properties file in the test/resources folder. It is specified in standard JDBC URL format:
spring.datasource.url=jdbc:postgresql://localhost:5432/wds_fin
spring.datasource.username=postgres
spring.datasource.password=password
There are three databases under the schema - 'postgres', 'amigoscode' and 'wds_fin'. All three belong to user 'postgres'.
I can connect to the server as a connection and see all three databases in both the pgAdmin tool and in IntelliJ DB browser. Using the user 'postgress' and password 'password'.
If I change the Spring JPA properties file URL suffix to /postgres, the stack trace does not appear as it seems to connect to that database fine. But for the other 2 it throws the exception.
This is the problem with Spring - its abstractions mean it is difficult to debug when something is wrong. Any help much appreciated. Thanks.
UPDATE:
Hi
Ok, sorry I misused the term schema. I should have said server.
The pgAdmin view of the server connection is this:
As you can see it contains the databases ‘amigoscode’, ‘postgres’ and ‘wds_fin’. Each of these databases have the user owner postgres which has full privileges.
The connection details for the 'PostgreSQL11' server are:
Host name/address : localhost
Port: 5432
Maintenance database: postgres
Username: postgres
I have configured the application.properties file in my Spring Data JPA as follows:
spring.application.name=cryptoManager
spring.datasource.url=jdbc:postgresql://localhost:5432/wds_fin
spring.datasource.username=postgres
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=
org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.format_sql=true
The datasource URL is the same as the PgAdmin PostgresSQL11 server connection and the wds_fin DB is specified.
When I run ‘mvn test’ at the root of the project the test suite runs but a stack trace is output:
org.postgresql.util.PSQLException: FATAL: database "wds_fin" does not exist at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2713) at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2825) at org.postgresql.core.v3.QueryExecutorImpl.(QueryExecutorImpl.java:175) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:313) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:54) at org.postgresql.jdbc.PgConnection.(PgConnection.java:263) at org.postgresql.Driver.makeConnection(Driver.java:443) at org.postgresql.Driver.connect(Driver.java:297) at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:359) at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201) at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:470) at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:100) at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
Spring JPA is obviously doing its stuff in the background and attempting a connection as specified in the properties file.
If I change the spring.datasource.url property to :
jdbc:postgresql://localhost:5432/postgres
I no longer get the stack trace. So it seems to connect to the right server but can only access the ‘postgres’ database.
I have checked the properties for each of the databases and they are the same. The only distinction I can see is that postgres is the ‘maintenance database’ of the server.
Many Thanks