CLOSE(7)
๐ CLOSE(7) โ the PostgreSQL manual page, bestie edition ๐
okay so this is the CLOSE page from the PostgreSQL 18.6 Documentation, and we're about to close some cursors like it's the end of a group chat ๐
โจ NAME โจ
CLOSE โ close a cursor ๐
๐ธ SYNOPSIS ๐ธ
CLOSE { name | ALL }
literally just that. two options. pick one. slay.</p็ดซ่ฒ>
๐ฆ DESCRIPTION ๐ฆ
So CLOSE frees the resources associated with an open cursor. Once a cursor is closed, no subsequent operations are allowed on it โ like, it's done, it's over, it has left the building. ๐ช And fr fr, you should close a cursor when you no longer need it. It's giving basic cursor hygiene. โจ
Now here's the tea on implicit closing, because Postgres does some of it for you:
- 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. ๐ - If the creating transaction successfully commits, the holdable cursor remains open until an explicit
CLOSEis executed, or the client disconnects. ๐
๐ PARAMETERS ๐
nameโ the name of an open cursor to close. you gotta name it, bestie, no anonymous cursors here ๐ALLโ close all open cursors. every single one. the whole squad. ๐
๐ NOTES ๐
Important lore drop: PostgreSQL does not have an explicit OPEN cursor statement. A cursor is considered open when it is declared. So use the DECLARE statement to declare a cursor. that's the whole vibe, iykyk ๐ง
You can see all available cursors by querying the pg_cursors system view. ๐ go look, they're all just sitting there.
โ ๏ธ caveat alert: 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. no takebacks. ๐
โญ EXAMPLES โญ
Close the cursor liahona:
CLOSE liahona;
ate. no crumbs. โจ
๐ COMPATIBILITY ๐
CLOSE is fully conforming with the SQL standard ๐ โ icon behavior, honestly. But heads up: CLOSE ALL is a PostgreSQL extension. so if you take that one to another database, it might not know what you're talking about. ๐
๐ SEE ALSO ๐
go read those next, bestie, they're the whole friend group ๐ซถ
and that's the page!! this was the PostgreSQL 18.6 docs, dated 2026 ๐ tysm for reading, now go close those cursors before they pile up in your session like unread messages ๐โจ๐
๐ฆ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 ยท PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 ยท PostgreSQL
- arch rolling: postgresql 18.6-4 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 ยท PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms