CLOSE(7)

๐Ÿ“ฆ version 18.6, in opensuse-leap 16.0

๐Ÿ’– 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 COMMIT or ROLLBACK. ๐Ÿซถ
  • 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 CLOSE is 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