apache/beam · error · IllegalArgumentException

Postgres does not support connectionInitSql.

Error message

Postgres does not support connectionInitSql.

What it means

Thrown by ReadFromPostgresSchemaTransformProvider.from() when a connectionInitSql list is supplied. The Postgres read path does not execute connection initialization SQL statements, so accepting the option silently would do nothing; the provider fails fast instead. The same provider also force-overrides disableAutoCommit to true because Postgres reads require it.

Source

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

  }

  @Override
  public @UnknownKeyFor @NonNull @Initialized SchemaTransform from(
      JdbcReadSchemaTransformConfiguration 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.");
    }

    Boolean disableAutoCommit = configuration.getDisableAutoCommit();
    if (disableAutoCommit != null && !disableAutoCommit) {
      LOG.warn("Postgres reads require disableAutoCommit to be true, overriding to true.");
    }

    // Override "connectionInitSql" and "disableAutoCommit" for postgres
    configuration =
        configuration.toBuilder()
            .setConnectionInitSql(Collections.emptyList())
            .setDisableAutoCommit(true)
            .build();
    return new PostgresReadSchemaTransform(configuration);
  }

  public static class PostgresReadSchemaTransform extends JdbcReadSchemaTransform {
    public PostgresReadSchemaTransform(JdbcReadSchemaTransformConfiguration config) {

View on GitHub (pinned to 12126d8942)

Solutions

  1. Remove the connectionInitSql entries from the Postgres read configuration
  2. If you need init SQL (e.g. SET TIME ZONE), run it outside Beam on the database/user defaults, or use a Postgres-compatible mechanism like ALTER ROLE ... SET
  3. Move the read to a provider/dialect that supports connectionInitSql if the statements are mandatory

Example fix

// before
builder().setConnectionInitSql(ImmutableList.of("SET search_path TO myschema"))
// after
builder() // connectionInitSql not set; ensure search_path is the role/database default
Defensive patterns

Strategy: validation

Validate before calling

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

Prevention

When it happens

Trigger: Calling ReadFromPostgresSchemaTransformProvider.from()/builder with connectionInitSql set to a non-empty list of SQL statements.

Common situations: Reusing a shared JDBC connection configuration (originally written for MySQL or SQL Server where connectionInitSql is honored) for a Postgres read; templated pipeline configs that always populate connectionInitSql.

Related errors


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