CLOSE(7)
π CLOSE(7) β the PostgreSQL glow-up
okay bestie, welcome to CLOSE, page 7 of the PostgreSQL 15.19 docs β¨ this is the one where we say bye-bye to a cursor, and honestly? it's giving closure (literally). let's get into it π«Ά
πΈ SYNOPSIS
CLOSE { name | ALL }
that's it. that's the whole vibe check. two ways to do it, pick your fighter π
β¨ DESCRIPTION
CLOSE frees the resources associated with an open cursor π₯ after the cursor is closed, no subsequent operations are allowed on it β like, none, bestie, it's done π a cursor should be closed when it is no longer needed.
here's the lore on when cursors get closed automatically, no cap:
- every non-holdable open cursor is implicitly closed when a transaction is terminated by
COMMITorROLLBACKπ - a holdable cursor is implicitly closed if the transaction that created it aborts via
ROLLBACK - but if the creating transaction successfully commits, the holdable cursor remains open until an explicit
CLOSEis executed, or the client disconnects π
so like, holdable cursors have main character energy and stick around. noted. π
π PARAMETERS
nameβ the name of an open cursor to close. just the one. your fave. πALLβ close all open cursors. every single one. goodbye to the whole group chat π
π¦ NOTES
okay so here's a thing that trips people up: PostgreSQL does not have an explicit OPEN cursor statement π a cursor is considered open when it is declared. use the DECLARE statement to declare a cursor. that's the whole opening ceremony, iykyk β¨
you can see all available cursors by querying the pg_cursors system view π highly recommend, it's literally the cursor group photo.
and now the caveat, listen up π₯:
if a cursor is closed after a savepoint which is later rolled back, the CLOSE is not rolled back β that is, the cursor remains closed. periodt. π
π EXAMPLES
close the cursor liahona:
CLOSE liahona;
slay. that cursor is gone. π
β COMPATIBILITY
CLOSE is fully conforming with the SQL standard β
CLOSE ALL is a PostgreSQL extension πΈ (yes, we added that ourselves, you're welcome π
)
π SEE ALSO
DECLARE(7), FETCH(7), MOVE(7) β go read those next, bestie, they're iconic π«Ά
mwah π that was CLOSE(7) from the PostgreSQL 15.19 docs, dated 2026 β go forth and close your cursors responsibly, ily πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-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