dblink_plus
dblink_plus · Run SQL against external PostgreSQL, Oracle, MySQL, and SQLite databases from PostgreSQL.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100072 | dblink_plus | dblink_plus | 1.0.11 | FDW | BSD-3-Clause | C |
Usage
Sources:
dblink_plus 1.0.11 executes SQL on external PostgreSQL, Oracle, MySQL, or SQLite databases through connector plugins. Unlike core dblink, it can coordinate a remote transaction with the local transaction using two-phase commit when use_xa is enabled.
Core Workflow
Create a foreign-data-wrapper definition, server, and user mapping for the compiled connector, then open a named connection:
Because dblink.query and dblink.call return SETOF record, callers must provide the expected column names and types. Passing a server name instead of a named connection creates an anonymous connection that is closed at transaction end.
Important Objects
dblink.connect(...)anddblink.disconnect(text)manage persistent named connections.dblink.query(...)returns rows, whiledblink.exec(text, text)returns the affected-row count for a remote command.dblink.open(...),dblink.fetch(...), anddblink.close(...)provide transaction-scoped cursor access.dblink.call(...)invokes a stored function and returns records.dblink.connectionsreports connection name, server OID, status,use_xa, and whether the connection is kept.dblink.postgres,dblink.oracle,dblink.mysql, anddblink.sqlite3are connector validators present in the source tree.
Transaction and Configuration Boundaries
dblink_plus.use_xa controls automatic transaction management for anonymous connections and defaults to on. An explicit use_xa argument to dblink.connect takes precedence; omitting that argument starts an XA-enabled connection even if the GUC is off. PostgreSQL remote servers need max_prepared_transactions greater than zero for two-phase commit. Commands forbidden inside a transaction block, such as PostgreSQL VACUUM or many Oracle DDL commands, require a connection created with use_xa = false.
No preload is required. The connector libraries and client dependencies are selected at build time, so verify which of PostgreSQL, Oracle, MySQL, and SQLite is actually present in the installed binary.
Operational Notes
The XA path uses a deferred delete trigger in dblink.atcommit; it cannot run in a read-only or hot-standby transaction, where use_xa must be disabled. Large remote results are materialized in the local backend and can consume substantial memory. Oracle max_value_len and fetch-size settings directly affect buffer size, and the official documentation lists unsupported Oracle LOB/raw types. Grant non-superusers only the required USAGE on schema dblink, function EXECUTE, and the documented DELETE privilege on the internal table. Test rollback, prepared-transaction recovery, logging, credential storage, and remote failure behavior before production use.