DBLINK_OPEN(3)
π DBLINK_OPEN(3) β bestie's guide to dblink_open π
okay so. you want to open a cursor in a remote database?? iconic. this is the page for you. it's from the PostgreSQL 18.6 Documentation, and yes we're reading a 3 manual page together, it's a whole vibe π¦
β¨ NAME β¨
dblink_open β opens a cursor in a remote database. that's it. that's the whole job. she's a one-trick pony and she slays at it π
πΈ SYNOPSIS πΈ
dblink_open(text cursorname, text sql [, bool fail_on_error]) returns text
dblink_open(text connname, text cursorname, text sql [, bool fail_on_error]) returns text
two whole forms, bestie. pick your fighter π«Ά
π DESCRIPTION π
so dblink_open() opens a cursor in a remote database. and then?? the cursor can subsequently be manipulated with dblink_fetch() and dblink_close(). it's giving teamwork. it's giving choreography. the three of them literally cannot function without each other π
π¦ ARGUMENTS π¦
connnameβ the name of the connection you wanna use. lowkey optional tho: omit this parameter to use the unnamed connection. no name? no problem β¨cursornameβ the name you're assigning to this cursor. you get to pick it. main character naming energy, use it wisely πsqlβ theSELECTstatement you wish to execute in the remote database. for exampleselect * from pg_class. fr fr, that's the actual example they gave, we keep it verbatim πfail_on_errorβ okay so if this istrue(which is the default when you omit it), then an error thrown on the remote side of the connection causes an error to also be thrown locally. equal-opportunity erroring. but if it'sfalse, then the remote error gets reported locally as aNOTICEinstead, and the function's return value is set toERROR. so it's not silent, it's just chill about it π
β RETURN VALUE β
returns status. either OK or ERROR. that's the whole menu, bestie π
π₯ NOTES π₯
okay this part actually matters so lock in π
a cursor can only persist within a transaction. because of that, dblink_open starts an explicit transaction block (BEGIN) on the remote side β if the remote side was not already within a transaction. and then that transaction gets closed again when the matching dblink_close is executed. cute, right?? it cleans up after itself π§
β οΈ BUT WAIT. if you usedblink_execto change data betweendblink_openanddblink_close, and then an error occurs, or you usedblink_disconnectbeforedblink_close, your change will be lost β because the transaction will be aborted. not "maybe lost". LOST. gone. poof π so please, for the love of everything, mind your ordering.
π EXAMPLES π
look at her go. actual working code, verbatim, no cap:
SELECT dblink_connect('dbname=postgres options=-csearch_path=');
dblink_connect
----------------
OK
(1 row)
SELECT dblink_open('foo', 'select proname, prosrc from pg_proc');
dblink_open
-------------
OK
(1 row)
connect, then open, then OK twice. it's giving flawless. it's giving ate and left no crumbs π
and that's the page!! this whole thing is PostgreSQL 18.6, dated 2026, and it lives in section 3 of the manual as DBLINK_OPEN(3). go open some cursors responsibly bestie, ily, mwah ππ
β¨
π¦ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 Β· PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 Β· PostgreSQL
- arch rolling: postgresql 18.6-4 Β· PostgreSQL
- fedora 43: postgresql-contrib 18.6-1.fc43 Β· PostgreSQL
- fedora 44: postgresql-contrib 18.6-1.fc44 Β· PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-doc-18 18.6-0ubuntu0.26.04.1 Β· PostgreSQL
- ubuntu stonking: postgresql-doc-18 18.6-3build2 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms