DBLINK_CLOSE(3)

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

So this is a page from the PostgreSQL 13.23 docs, and it's all about dblink_close β€” the function that literally just closes a cursor over in a remote database. It's the opposite of dblink_open, and honestly? It's giving cleanup era. ✨


🌸 NAME

dblink_close β€” closes a cursor in a remote database. That's it. That's the whole vibe. πŸŽ€


πŸ¦‹ 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, bestie β€” one for the unnamed connection, one where you name the connection. Pick your fighter. πŸ’…


✨ DESCRIPTION

dblink_close closes a cursor that you previously opened with dblink_open. That's the whole plot. No cap. If you opened it, you gotta close it β€” this is the function that does the closing. 🫢


πŸ’– ARGUMENTS

  • connname β€” name of the connection you wanna use. Omit this parameter entirely if you're rolling with the unnamed connection. Simple as that. 🌈
  • cursorname β€” the name of the cursor you want to close. Like, the actual cursor's name. Yes, you need to know it. 🎯
  • fail_on_error β€” okay so if this is true (and it's the default when you just, like, don't pass it), then any error thrown on the remote side of the connection will also be thrown locally. So you get the error too. If it's false, then the remote error gets reported locally as a NOTICE instead, and the function's return value is set to ERROR. Choose wisely, iykyk. πŸ’€

πŸ‘‘ RETURN VALUE

Returns a status, either OK or ERROR. That's it. Two possible outcomes. Very binary of it. ⭐


πŸ”₯ NOTES

Here's the tea: if dblink_open started an explicit transaction block, and this dblink_close call is the last remaining open cursor in that connection β€” then dblink_close will issue the matching COMMIT. Yes, it's out here closing cursors and committing transactions. Main character energy fr fr. πŸ’…


πŸ“ EXAMPLES

Okay so here's the whole little journey, from connecting to opening to closing:

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

Then we open a cursor named foo and pull some data out of pg_proc:

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

And then β€” drumroll β€” we close it. Bye bye cursor πŸ¦‹:

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

See? OK, OK, OK. Slay. πŸ”₯


Lowkey a reminder that this is all happening remotely β€” the cursor lives over there, and you're just telling it to wrap it up. No cap.

πŸ’œ That's the whole page, bestie β€” massive thanks to PostgreSQL 13.23, documented back in 2025. Go forth and close those cursors. Periodt. πŸŽ€βœ¨πŸ’…

πŸ“¦ where this page comes from