DBLINK_OPEN(3)

πŸ“¦ version 17.11, in opensuse-leap 16.0

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 β€” the SELECT statement you wish to execute in the remote database, for example select * from pg_class. iconic query, no notes πŸŽ€
  • fail_on_error β€” if true (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. if false, the remote error gets reported locally as a NOTICE instead, and the function's return value is set to ERROR. 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 use dblink_exec to change data between dblink_open and dblink_close, and then an error occurs or you use dblink_disconnect before dblink_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