DBLINK_CLOSE(3)
π DBLINK_CLOSE β ok so we're closing a cursor in a remote database, bestie
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 istrue(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'sfalse, then the remote error gets reported locally as aNOTICEinstead, and the function's return value is set toERROR. 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
- opensuse-leap 16.0: postgresql13-docs 13.23-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