DBLINK_OPEN(3)
πΈ dblink_open β the manual page, bestie πΈ
okay so this is DBLINK_OPEN(3), straight out of the PostgreSQL 17.11 Documentation (section 3, the library calls girlies) β and it's literally about opening a cursor in a remote database. stay with me, it's gonna slay π
β¨ NAME β¨
dblink_open β opens a cursor in a remote database π¦
β¨ 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 flavors, pick your fighter π
β¨ DESCRIPTION β¨
dblink_open() opens a cursor in a remote database. that's the whole vibe.
and once that cursor exists? you can lowkey boss it around with dblink_fetch() and dblink_close(). it's giving teamwork fr fr π«Ά
β¨ ARGUMENTS β¨
connnameβ the name of the connection you wanna use. omit this parameter and you get the unnamed connection instead (she's the default, no name needed π ).cursornameβ the name you're assigning to this cursor. yes, you pick it. main character energy β¨sqlβ theSELECTstatement you wish to execute in the remote database, for exampleselect * from pg_class. iconic query, no notes πfail_on_errorβ iftrue(and that's the default when omitted, so don't stress) then an error thrown on the remote side of the connection causes an error to also be thrown locally. iffalse, the remote error gets reported locally as aNOTICEinstead, and the function's return value is set toERROR. so like, soft-launch the failure instead of screaming π
β¨ RETURN VALUE β¨
Returns status, either OK or ERROR. that's it. that's the tea β
β¨ NOTES β¨
so here's the lore you actually need π β since a cursor can only persist within a transaction, dblink_open starts an explicit transaction block (BEGIN) on the remote side, if the remote side wasn't already within a transaction. this transaction gets closed again when the matching dblink_close is executed. periodt.
β οΈ okay this part is the serious one, bestie. 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. gone. deceased. do not do this ππ
β¨ EXAMPLES β¨
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)
look at that. two OKs. we love a clean run πβ
and that's the page, gorgeous π sign-off szn: this was PostgreSQL 17.11, dated 2026, filed under DBLINK_OPEN(3). go open some cursors responsibly, mwah ππ¦
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17-docs 17.11-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms