apache/beam · error · IllegalArgumentException

Postgres does not support connectionInitSql.

Error message

Postgres does not support connectionInitSql.

What it means

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.

Source

Thrown at sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/providers/WriteToPostgresSchemaTransformProvider.java:73

  }

  @Override
  public @UnknownKeyFor @NonNull @Initialized SchemaTransform from(
      JdbcWriteSchemaTransformConfiguration configuration) {
    String jdbcType = configuration.getJdbcType();
    if (jdbcType != null && !jdbcType.isEmpty() && !jdbcType.equals(jdbcType())) {
      LOG.warn(
          "Wrong JDBC type. Expected '{}' but got '{}'. Overriding with '{}'.",
          jdbcType(),
          jdbcType,
          jdbcType());
      configuration = configuration.toBuilder().setJdbcType(jdbcType()).build();
    }

    List<@org.checkerframework.checker.nullness.qual.Nullable String> connectionInitSql =
        configuration.getConnectionInitSql();
    if (connectionInitSql != null && !connectionInitSql.isEmpty()) {
      throw new IllegalArgumentException("Postgres does not support connectionInitSql.");
    }

    // Override "connectionInitSql" for postgres
    configuration = configuration.toBuilder().setConnectionInitSql(Collections.emptyList()).build();
    return new PostgresWriteSchemaTransform(configuration);
  }

  public static class PostgresWriteSchemaTransform extends JdbcWriteSchemaTransform {
    public PostgresWriteSchemaTransform(JdbcWriteSchemaTransformConfiguration config) {
      super(config, POSTGRES);
    }
  }
}

View on GitHub (pinned to 12126d8942)

Solutions

  1. Remove connectionInitSql from the Postgres write configuration
  2. Set required session behavior via Postgres server/role defaults (ALTER ROLE ... SET) or in the SQL itself
  3. Ensure the jdbcType/config actually matches Postgres before applying MySQL-specific options

Example fix

// before
builder().setConnectionInitSql(ImmutableList.of("SET synchronous_commit TO off"))
// after
builder() // configure synchronous_commit at role/database level instead
Defensive patterns

Strategy: validation

Validate before calling

if (connectionInitSql != null && !connectionInitSql.isEmpty()) {
  throw new IllegalArgumentException("Postgres write does not support connectionInitSql; remove it from the config");
}

Prevention

When it happens

Trigger: Calling WriteToPostgresSchemaTransformProvider.from()/builder with a non-empty connectionInitSql list.

Common situations: 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.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/280725abf11448d9. Report an issue: GitHub.