Class PostgresSupport

All Implemented Interfaces:
DatabaseSupport
Direct Known Subclasses:
CockroachDBSupport

public class PostgresSupport extends AbstractDatabaseSupport
PostgreSQL-specific DatabaseSupport.

On top of the cross-database defaults, this registers generators for the PostgreSQL types the JDBC driver surfaces as JDBCType.OTHER, JDBCType.ARRAY, JDBCType.SQLXML, and JDBCType.BIT, dispatching on the driver-reported type name:

  • uuid, json, jsonb, inet, cidr, macaddr, macaddr8, interval, varbit (all reported as OTHER)
  • _text, _int2, _int4, _int8 arrays (reported as ARRAY)
  • xml (reported as SQLXML)
  • bit/bit(n) and boolean (both reported as BIT, distinguished by type name)

Because CockroachDB speaks the PostgreSQL wire protocol through the same JDBC driver, CockroachDBSupport extends this class and inherits all of the above.

Connection requirement: these extension types are generated as their text representations and bound as strings. PostgreSQL will not implicitly cast character varying to uuid, jsonb, inet, bit, etc., so the JDBC connection must be opened with stringtype=unspecified (e.g. jdbc:postgresql://host/db?stringtype=unspecified) for the server to infer each column's type. Standard column types do not require this.

Since:
1.0.0
See Also:
  • Constructor Details

    • PostgresSupport

      public PostgresSupport()
      Creates a PostgreSQL support instance.
  • Method Details

    • batchRewriteUrlParameter

      public String batchRewriteUrlParameter()
      Returns reWriteBatchedInserts, the PostgreSQL JDBC driver parameter that rewrites a batch of single-row INSERTs into one multi-row statement. Enabling it (e.g. jdbc:postgresql://host/db?reWriteBatchedInserts=true) drastically cuts the number of round trips and is often the single biggest fill speedup; Bloviate logs a one-time recommendation when a fill connection's URL does not set it.
      Returns:
      the reWriteBatchedInserts parameter name
      Since:
      2.10.0
    • readConstraints

      public Map<String, ColumnConstraint> readConstraints(Connection connection, String schema, String table)
      Description copied from interface: DatabaseSupport
      Reads the value constraints (CHECK constraints and enum/domain allowed values) for a table's columns, so the fill engine can generate values that satisfy them (issue #479). The default returns an empty map (no constraint awareness); database-specific implementations override it with vendor catalog queries.

      Constraint reading is best-effort and must never fail a fill: an implementation that cannot read the catalog should log and return what it has.

      Parameters:
      connection - an open connection to query the catalog with
      schema - the table's schema (may be null for the default schema)
      table - the table name
      Returns:
      constraints keyed by lower-cased column name; empty when none are found or supported
    • supportsBulkLoad

      public boolean supportsBulkLoad()
      PostgreSQL supports unordered bulk loading by suppressing foreign-key trigger firing for the session via SET session_replication_role = replica.
      Returns:
      true
      Since:
      2.17.0
    • disableConstraints

      public BulkLoadHandle disableConstraints(Connection connection, Database database) throws SQLException
      Sets session_replication_role = replica on the connection, which stops user and foreign-key triggers (including referential-integrity checks) from firing for the session. This is the cheapest bulk-load mechanism — no catalog churn and nothing to rebuild — but it requires a superuser (or rds_superuser) role. A privilege failure is reported as a BulkLoadUnsupportedException so the engine can fall back to the ordered path.
      Parameters:
      connection - an open connection whose session role is changed
      database - the database metadata (unused by this mechanism)
      Returns:
      a handle recording that session_replication_role was changed
      Throws:
      BulkLoadUnsupportedException - if the role lacks privilege to change the setting
      SQLException - if the statement otherwise fails
    • enableConstraints

      public void enableConstraints(Connection connection, Database database, BulkLoadHandle handle) throws SQLException
      Restores session_replication_role = origin, re-enabling trigger and foreign-key firing for the session before the connection is returned to the pool.
      Parameters:
      connection - the same connection passed to disableConstraints(Connection, Database)
      database - the database metadata (unused by this mechanism)
      handle - the handle returned by disableConstraints(Connection, Database)
      Throws:
      SQLException - if the statement fails
    • configure

      protected void configure(Map<JDBCType, GeneratorFactory> registry)
      Description copied from class: AbstractDatabaseSupport
      Hook for subclasses to add or replace generator factories for specific JDBC types. The supplied registry already holds the cross-database defaults; subclasses with no customizations need not override this method. Implementations must not retain a reference to the map beyond the call.
      Overrides:
      configure in class AbstractDatabaseSupport
      Parameters:
      registry - the mutable registry to customize, keyed by JDBCType