{"record":{"id":"280725abf11448d9","repo":"apache/beam","slug":"postgres-does-not-support-connectioninitsql-280725","errorCode":null,"errorMessage":"Postgres does not support connectionInitSql.","messagePattern":"Postgres does not support connectionInitSql\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/providers/WriteToPostgresSchemaTransformProvider.java","lineNumber":73,"sourceCode":"  }\n\n  @Override\n  public @UnknownKeyFor @NonNull @Initialized SchemaTransform from(\n      JdbcWriteSchemaTransformConfiguration configuration) {\n    String jdbcType = configuration.getJdbcType();\n    if (jdbcType != null && !jdbcType.isEmpty() && !jdbcType.equals(jdbcType())) {\n      LOG.warn(\n          \"Wrong JDBC type. Expected '{}' but got '{}'. Overriding with '{}'.\",\n          jdbcType(),\n          jdbcType,\n          jdbcType());\n      configuration = configuration.toBuilder().setJdbcType(jdbcType()).build();\n    }\n\n    List<@org.checkerframework.checker.nullness.qual.Nullable String> connectionInitSql =\n        configuration.getConnectionInitSql();\n    if (connectionInitSql != null && !connectionInitSql.isEmpty()) {\n      throw new IllegalArgumentException(\"Postgres does not support connectionInitSql.\");\n    }\n\n    // Override \"connectionInitSql\" for postgres\n    configuration = configuration.toBuilder().setConnectionInitSql(Collections.emptyList()).build();\n    return new PostgresWriteSchemaTransform(configuration);\n  }\n\n  public static class PostgresWriteSchemaTransform extends JdbcWriteSchemaTransform {\n    public PostgresWriteSchemaTransform(JdbcWriteSchemaTransformConfiguration config) {\n      super(config, POSTGRES);\n    }\n  }\n}\n","sourceCodeStart":55,"sourceCodeEnd":87,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/providers/WriteToPostgresSchemaTransformProvider.java#L55-L87","documentation":"Thrown by WriteToPostgresSchemaTransformProvider.from() when connectionInitSql is non-empty. Postgres writes in Beam do not execute connection initialization SQL, so the option is unsupported and the provider throws rather than silently ignoring it; it then clears the list and constructs a PostgresWriteSchemaTransform.","triggerScenarios":"Calling WriteToPostgresSchemaTransformProvider.from()/builder with a non-empty connectionInitSql list.","commonSituations":"Reusing a MySQL-targeted write configuration for Postgres; pipeline templates that unconditionally set connectionInitSql; users expecting the option to run session setup statements before batch inserts.","solutions":["Remove connectionInitSql from the Postgres write configuration","Set required session behavior via Postgres server/role defaults (ALTER ROLE ... SET) or in the SQL itself","Ensure the jdbcType/config actually matches Postgres before applying MySQL-specific options"],"exampleFix":"// before\nbuilder().setConnectionInitSql(ImmutableList.of(\"SET synchronous_commit TO off\"))\n// after\nbuilder() // configure synchronous_commit at role/database level instead","handlingStrategy":"validation","validationCode":"if (connectionInitSql != null && !connectionInitSql.isEmpty()) {\n  throw new IllegalArgumentException(\"Postgres write does not support connectionInitSql; remove it from the config\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not copy connectionInitSql from MySQL write configs into Postgres ones","Configure needed session behavior at the Postgres server/role level","Validate configs in CI with a small dry-run against each target dialect"],"tags":["jdbc","postgres","beam","configuration"],"backgroundTag":"unsupported-config-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}