CLOSE(7)
π CLOSE(7) β the "bye bestie" of cursors
Okay so real talk: this is the CLOSE page from the PostgreSQL 17.11 Documentation (yes, she's a 7 manual page, we love a section-seven moment), and it's literally just about hanging up on a cursor when you're done with it. Short page, immaculate vibes, zero wasted words. Let's get into it π«Ά
β¨ NAME β¨
CLOSE β close a cursor, bestie. That's it. That's the whole job.
β¨ SYNOPSIS β¨
CLOSE { name | ALL }
Two ways to do it: name your cursor, or go full chaos mode with ALL. Choose your fighter π
πΈ DESCRIPTION πΈ
CLOSE frees the resources associated with an open cursor. Once the cursor is closed, no subsequent operations are allowed on it β like, the door is shut, the lights are off, we don't live there anymore. So the move is: close it when you no longer need it. A cursor should be closed when it is no longer needed. (Said twice because it matters, okay? π)
Now here's the automatic-cleanup tea β β some cursors close themselves and some need you to actually parent them:
- Every non-holdable open cursor is implicitly closed when a transaction is terminated by
COMMITorROLLBACK. Poof. Gone. You didn't even have to ask π - A holdable cursor is implicitly closed if the transaction that created it aborts via
ROLLBACK. So if it all goes sideways, she's out too. - But if the creating transaction successfully commits, the holdable cursor remains open until an explicit
CLOSEis executed, or the client disconnects. That one is YOUR responsibility, main character. She's holdable, she's holding on, she's staying π
π PARAMETERS π
nameβ the name of an open cursor to close. Just the one. Your fave.ALLβ close all open cursors. Everyone out of the pool πββοΈ
π¦ NOTES π¦
PostgreSQLdoes not have an explicitOPENcursor statement. A cursor is considered open when it is declared. Use theDECLAREstatement to declare a cursor. So there's noOPENβ she's open the moment she exists, iconic behaviour honestly β¨- You can see all available cursors by querying the
pg_cursorssystem view. Peek behind the curtain, iykyk π - β οΈ Okay this one's important: if a cursor is closed after a savepoint which is later rolled back, the
CLOSEis not rolled back β that is, the cursor remains closed. The rollback does not resurrect her. No take-backs. π
Not me warning you again: savepoint rollbacks do NOT reopen a cursor you already closed. She's closed closed. π
π EXAMPLES π
Close the cursor liahona:
CLOSE liahona;
That's it. One line. Slay. π
π COMPATIBILITY π
CLOSE is fully conforming with the SQL standard. π
CLOSE ALL is a PostgreSQL extension β so if you're bouncing between databases, know that this one's a homegrown flex, not a standard thing.
π₯ SEE ALSO π₯
Go read DECLARE(7) next if you wanna know how the cursor got here in the first place, bestie π«Ά
Anyway, that's the page β PostgreSQL 17.11, dated 2026, CLOSE(7) in the PostgreSQL 17.11 Documentation. Closing this out the only way I know how: CLOSE ALL; and disconnect πβ¨π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-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