DBLINK_CLOSE(3)

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

okay so this is dblink_close, straight out of the PostgreSQL 16.15 Documentation (manual section 3, mwah πŸ’–). yes it's a whole manpage about closing a cursor in a remote database. and honestly? it ate. let's get into it.


✨ NAME ✨

dblink_close β€” closes a cursor in a remote database πŸŽ€

like, that's her whole job. one cursor. remote. closed. iconic.


πŸ¦‹ SYNOPSIS πŸ¦‹

dblink_close(text cursorname [, bool fail_on_error]) returns text
dblink_close(text connname, text cursorname [, bool fail_on_error]) returns text

two flavors, pick your fighter ✨ β€” with or without naming the connection.


🌸 DESCRIPTION 🌸

dblink_close closes a cursor that you already opened with dblink_open.

that's it. that's the whole vibe. you opened it, now you're closing it. closure is self-care fr fr 🫢


πŸ’œ ARGUMENTS πŸ’œ

  • connname β€” the name of the connection to use. omit this parameter and you get the unnamed connection instead. no name, no problem πŸ’…
  • cursorname β€” the name of the cursor you're closing. say bye πŸ‘‹
  • fail_on_error β€” if this is true (which is the default when you omit it), then an error thrown on the remote side of the connection also causes an error to be thrown locally. if it's false, the remote error gets reported locally as a NOTICE instead, and the function's return value is set to ERROR. so like... true = both sides freak out together. false = remote side freaks out, local side just takes notes πŸ“

πŸ”₯ RETURN VALUE πŸ”₯

returns a status, and that status is either OK or ERROR. two options, no in-between, main character energy only πŸ‘‘


πŸ‘‘ NOTES πŸ‘‘

okay this part matters, listen up 🫢 β€” if dblink_open started an explicit transaction block, and this is the last remaining open cursor in this connection, then dblink_close will issue the matching COMMIT.

so like... last one out turns off the lights and commits the transaction. no cap πŸ’‘


πŸŽ€ EXAMPLES πŸŽ€

connect first:

SELECT dblink_connect('dbname=postgres options=-csearch_path=');
 dblink_connect
----------------
 OK
(1 row)

open yourself a cursor (foo, cute name):

SELECT dblink_open('foo', 'select proname, prosrc from pg_proc');
 dblink_open
-------------
 OK
(1 row)

and now the star of the show β€” close it:

SELECT dblink_close('foo');
 dblink_close
--------------
 OK
(1 row)

slay. it worked. ✨


🌈 reminder bestie: that COMMIT in NOTES only fires when it's the last open cursor on the connection and dblink_open kicked off an explicit transaction block. don't let it sneak up on you πŸ’€

okay that's the whole page!! mwah!! this was PostgreSQL 16.15, documented in 2026, page DBLINK_CLOSE(3) β€” go close some cursors responsibly, ily, bye πŸ¦‹πŸ’–πŸŽ€

πŸ“¦ where this page comes from