-1

I installed the PostgreSql-12 using homebrew on my macos. It's running fine and able to use in the PgAdmin but throwing below error while using the DB in the java Spring boot app

Caused by: org.flywaydb.core.internal.exception.FlywaySqlException: Unable to obtain connection from database: An error occurred while setting up the SSL connection.
SQL State  : 08P01
Error Code : 0
Message    : An error occurred while setting up the SSL connection.

What I have tried - disabling ssl = off in the postgresql.conf

Below is the pg_hba.conf file -

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust

Reproducing Steps -

  1. Install postgresql using brew - brew install postgresql@12
  2. datasource url used in the spring datasource -
    jdbc:postgresql://localhost:5432/test_db?reWriteBatchedInserts=true
  3. Application run failing with the SSL error

StackTrace -

SQL State  : 08P01
Error Code : 0
Message    : An error occurred while setting up the SSL connection.

at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:60) ~[flyway-core-9.16.3.jar:na]
at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:74) ~[flyway-core-9.16.3.jar:na]
at org.flywaydb.core.FlywayExecutor.execute(FlywayExecutor.java:140) ~[flyway-core-9.16.3.jar:na]
at org.flywaydb.core.Flyway.migrate(Flyway.java:140) ~[flyway-core-9.16.3.jar:na]
at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66) ~[spring-boot-autoconfigure-3.1.0.jar:3.1.0]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1816) ~[spring-beans-6.0.9.jar:6.0.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1766) ~[spring-beans-6.0.9.jar:6.0.9]
... 18 common frames omitted
Caused by: org.postgresql.util.PSQLException: An error occurred while setting up the SSL connection.
at org.postgresql.core.v3.ConnectionFactoryImpl.enableSSL(ConnectionFactoryImpl.java:624) ~[postgresql-42.6.0.jar:42.6.0]
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:191) ~[postgresql-42.6.0.jar:42.6.0]
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:258) ~[postgresql-42.6.0.jar:42.6.0]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:54) ~[postgresql-42.6.0.jar:42.6.0]
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:263) ~[postgresql-42.6.0.jar:42.6.0]
at org.postgresql.Driver.makeConnection(Driver.java:443) ~[postgresql-42.6.0.jar:42.6.0]
at org.postgresql.Driver.connect(Driver.java:297) ~[postgresql-42.6.0.jar:42.6.0]
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:681) ~[java.sql:na]
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:190) ~[java.sql:na]
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:155) ~[spring-jdbc-6.0.9.jar:6.0.9]
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:146) ~[spring-jdbc-6.0.9.jar:6.0.9]
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:205) ~[spring-jdbc-6.0.9.jar:6.0.9]
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:169) ~[spring-jdbc-6.0.9.jar:6.0.9]
at com.fareye.entityframework.multitenant.CustomConnectionProvider.getConnection(CustomConnectionProvider.java:20) ~[fareye-entity-framework-lib-1.0.1-SNAPSHOT.jar:na]
at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:48) ~[flyway-core-9.16.3.jar:na]
... 24 common frames omitted

Any help would be appreciated.

7
  • Please provide a minimal reproducible example. Commented Apr 24, 2024 at 11:38
  • @aled Here are the steps - 1. Install postgresql using brew - brew install postgresql@12 2. datasource url used in the spring datasource - jdbc:postgresql://localhost:5432/test_db?reWriteBatchedInserts=true 3. Application run failing with the SSL error Commented Apr 24, 2024 at 11:47
  • Please edit your question to add details. Commented Apr 24, 2024 at 14:47
  • That doesn't look like a PostgreSQL error message. Maybe the client library is re-interpreting the error message it gets. Can you get more details on the client side, like a literal quoting of PostgreSQL's message? Also, look in the PostgreSQL server's log file to see what it says about the situation. Commented Apr 24, 2024 at 14:57
  • "what I have tried - disabling ssl_mode to off in the postgresql.conf" postgresql.conf doesn't have a setting called ssl_mode. There is sslmode, but that is a clientside-only option. Commented Apr 24, 2024 at 15:00

1 Answer 1

0

The issue i was facing was not the obvious one. When I debugged the spring boot app, I found the below exception which was getting wrapped into FlywaySqlException-

org.postgresql.util.PSQLException: Protocol error. Session setup failed

I just changed the port from 5432 to 5434, and it worked.

Got help from this - org.postgresql.util.PSQLException: Protocol error. Session setup failed

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.