maxpiter opened a new issue, #10242:
URL: https://github.com/apache/seatunnel/issues/10242

   ### Search before asking
   
   - [x] I had searched in the 
[issues](https://github.com/apache/seatunnel/issues?q=is%3Aissue+label%3A%22bug%22)
 and found no similar issues.
   
   
   ### What happened
   
   When trying to use SeaTunnel JDBC connector to write data to PostgreSQL, the 
job fails with the following error:
   
   ```
   org.postgresql.util.PSQLException: Protocol error. Session setup failed.
       at 
org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:839)
       at 
org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:172)
       ...
   ```
   
   ### SeaTunnel Version
   
   - SeaTunnel Version: 2.3.12
   - PostgreSQL Version: 14 / 16
   - Deployment: Docker (apache/seatunnel image)
   - Java Version: OpenJDK 1.8.0_342
   
   ### SeaTunnel Config
   
   ```conf
   Default
   ```
   
   ### Running Command
   
   ```shell
   {
           
           "env": {
               "job.name": "Mssql_to_postgres",
               "job.mode": "BATCH",
               "parallelism": 1
               
           },
           "source": [
               {
                   "plugin_name": "Jdbc",
                   "plugin_output": "ReceiptsMS",
                   "driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
                   "url": 
"jdbc:sqlserver://172.19.96.1:1433;databaseName=test;trustServerCertificate=true",
                   "user": "sqlserver",
                   "password": "h5CttXm8uOcjizA0v5j5gCp1",
                   "database": "test",
                   "query": "select * from dbo.Receipts",
                   "fetch_size": 10000
               }
           ],
           "sink": [
               {
                   "plugin_name": "Jdbc",
                   "plugin_input": "ReceiptsMS",
                   "url": 
"jdbc:postgresql://postgres:5432/testdb?gssEncMode=disable",
                   "driver": "org.postgresql.Driver",                
                   "username": "postgres",
                   "password": "postgres",
                   "database": "testdb",                
                   "generate_sink_sql": true,
                   "schema_save_mode": "CREATE_SCHEMA_WHEN_NOT_EXIST",
                   "data_save_mode": "APPEND_DATA",                             
                  
                   "table": "public.MSSQL_Receipts"
                   
           }
           ]
       }
   ```
   
   ### Error Exception
   
   ```log
   ErrorCode:[API-03], ErrorDescription:[Catalog initialize failed] - Failed 
connecting to jdbc:postgresql://postgres:5432/testdb via JDBC.\n\tat 
   
org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.AbstractJdbcCatalog.getConnection(AbstractJdbcCatalog.java:155)\n\tat
 
   
org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.AbstractJdbcCatalog.open(AbstractJdbcCatalog.java:172)\n\tat
 
   
org.apache.seatunnel.api.sink.DefaultSaveModeHandler.open(DefaultSaveModeHandler.java:78)\n\tat
 
   
org.apache.seatunnel.engine.server.master.JobMaster.handleSaveMode(JobMaster.java:562)\n\t...
 21 more\nCaused by: org.postgresql.util.PSQLException: Protocol error.  
Session setup 
   failed.\n\tat 
org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:839)\n\tat
 
   
org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:172)\n\tat
 
   
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:254)\n\tat
 
org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:53)\n\tat
 
   org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:269)\n\tat 
org.postgresql.Driver.makeConnection(Driver.java:564)\n\tat 
org.postgresql.Driver.connect(Driver.java:316)\n\tat 
   java.sql.DriverManager.getConnection(DriverManager.java:664)\n\tat 
java.sql.DriverManager.getConnection(DriverManager.java:208)\n\tat 
   
org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.AbstractJdbcCatalog.getConnection(AbstractJdbcCatalog.java:151)\n\t...
 24 more\n"
   ```
   
   ### Zeta or Flink or Spark Version
   
   _No response_
   
   ### Java or Scala Version
   
   - Java Version: OpenJDK 1.8.0_342
   
   ### Screenshots
   
   ### Issue Title
   PostgreSQL connection fails with "Protocol error. Session setup failed" due 
to OpenGauss JDBC driver conflict
   
   ### Environment
   - SeaTunnel Version: 2.3.12
   - PostgreSQL Version: 14 / 16
   - Deployment: Docker (apache/seatunnel image)
   - Java Version: OpenJDK 1.8.0_342
   
   ### Problem Description
   When trying to use SeaTunnel JDBC connector to write data to PostgreSQL, the 
job fails with the following error:
   
   ```
   org.postgresql.util.PSQLException: Protocol error. Session setup failed.
       at 
org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:839)
       at 
org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:172)
       ...
   ```
   
   ### Root Cause
   The SeaTunnel distribution includes `opengauss-jdbc-5.1.0.jar` in the 
`/opt/seatunnel/lib/` directory. This OpenGauss JDBC driver uses the same Java 
package namespace `org.postgresql` as the official PostgreSQL JDBC driver.
   
   When Java loads classes, it may load `org.postgresql.Driver` and related 
classes from the OpenGauss JAR instead of the official PostgreSQL JDBC driver. 
Since OpenGauss has a different authentication protocol than standard 
PostgreSQL, this causes the "Protocol error. Session setup failed" error.
   
   ### Evidence
   1. Direct Java connection test using PostgreSQL JDBC driver works:
   ```java
   Class.forName("org.postgresql.Driver");
   Connection conn = DriverManager.getConnection(
       "jdbc:postgresql://postgres:5432/testdb", "postgres", "postgres");
   // SUCCESS
   ```
   
   2. SeaTunnel job with the same connection parameters fails with protocol 
error.
   
   3. Inspection of `opengauss-jdbc-5.1.0.jar` reveals conflicting classes:
   ```
   $ unzip -l opengauss-jdbc-5.1.0.jar | grep org/postgresql
   org/postgresql/Driver.class
   org/postgresql/core/v3/ConnectionFactoryImpl.class
   ... (many more)
   ```
   
   ### Solution / Workaround
   Rename or remove the OpenGauss JDBC driver:
   ```bash
   mv /opt/seatunnel/lib/opengauss-jdbc-5.1.0.jar 
/opt/seatunnel/lib/opengauss-jdbc-5.1.0.jar.bak
   ```
   
   After removing the conflicting JAR, PostgreSQL connections work correctly.
   
   ### Suggested Fix
   1. **Option A**: Remove `opengauss-jdbc-5.1.0.jar` from the default 
SeaTunnel distribution, or move it to a separate optional connectors directory.
   
   2. **Option B**: Use a classloader isolation mechanism to prevent class 
conflicts between different JDBC drivers.
   
   3. **Option C**: Rename the OpenGauss JDBC driver package to avoid namespace 
collision (requires coordination with OpenGauss project).
   
   ### Affected Users
   Any user trying to use SeaTunnel JDBC connector with standard PostgreSQL 
database while having the default SeaTunnel distribution.
   
   ### Are you willing to submit PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to