DBLINK_CLOSE(3)
π DBLINK_CLOSE(3) β bestie, let's talk about closing cursors
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 istrue(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'sfalse, the remote error gets reported locally as aNOTICEinstead, and the function's return value is set toERROR. 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: thatCOMMITin NOTES only fires when it's the last open cursor on the connection anddblink_openkicked 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
- opensuse-leap 16.0: postgresql16-docs 16.15-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