CLOSE(7)
β¨ CLOSE(7) β¨
okay so bestie, we're talking about the PostgreSQL 16.15 manual page for CLOSE β literally the "bye bye cursor" command and honestly? it's giving closure in the most literal sense π
π NAME π
CLOSE β close a cursor πΈ
π¦ SYNOPSIS π¦
CLOSE { name | ALL }
π DESCRIPTION π
so CLOSE frees the resources associated with an open cursor, periodt. Once the cursor is closed, no subsequent operations are allowed on it β like, it's done, it's not coming back, the vibe check failed and it's out π«Ά. A cursor should be closed when it is no longer needed.
Every non-holdable open cursor is implicitly closed when a transaction is terminated by COMMIT or ROLLBACK. Meanwhile a holdable cursor gets implicitly closed if the transaction that created it aborts via ROLLBACK. But β and this is the main character plot twist β if the creating transaction successfully commits, that holdable cursor remains open until an explicit CLOSE is executed, or the client disconnects. so yeah, it just chills there π
β PARAMETERS β
nameβ the name of an open cursor to close πALLβ close all open cursors. every single one. no survivors π
π NOTES π
PostgreSQL does not have an explicit OPEN cursor statement β ngl that surprises everyone. A cursor is considered open when it is declared. So use the DECLARE statement to declare a cursor π
You can see all available cursors by querying the pg_cursors system view β lowkey the best way to keep tabs on your cursor squad π
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. like, that close is permanent fr fr, no take-backs π
π EXAMPLES π
Close the cursor liahona:
CLOSE liahona;
slay, liahona is free ποΈ
π§ COMPATIBILITY π§
CLOSE is fully conforming with the SQL standard β¨ (iconic behaviour, no notes). CLOSE ALL is a PostgreSQL extension β a little extra, and we love that for us π
π SEE ALSO π
DECLARE(7), FETCH(7), MOVE(7) β go read those too bestie, they're the whole cursor friend group π«Ά
and that's the page!! brought to you by PostgreSQL 16.15, dated 2026 β mwah, drink water, close your cursors, ily πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 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