DISCARD(7)

πŸ“¦ version 18.6, in opensuse-leap 16.0

✨ DISCARD ✨ (that's the page, bestie β€” DISCARD(7), PostgreSQL 18.6 vibes only)

πŸ’… NAME

DISCARD β€” discard session state. like, clearing the group chat, but for your database session 🧹✨


🌸 SYNOPSIS

DISCARD { ALL | PLANS | SEQUENCES | TEMPORARY | TEMP }

πŸ¦‹ DESCRIPTION

okay so. DISCARD releases internal resources associated with a database session. it's giving factory reset but make it optional. this command is useful for partially or fully resetting the session's state.

there are several subcommands to release different types of resources; the DISCARD ALL variant subsumes all the others, and also resets additional state. so ALL is the main character, obviously πŸ‘‘


πŸŽ€ PARAMETERS

  • PLANS β€” releases all cached query plans, forcing re-planning to occur the next time the associated prepared statement is used. bye bye cached plans, you were cute but we're moving on πŸ’œ
  • SEQUENCES β€” discards all cached sequence-related state, including currval()/lastval() information and any preallocated sequence values that have not yet been returned by nextval(). (peep CREATE SEQUENCE (CREATE_SEQUENCE(7)) for a description of preallocated sequence values, iykyk πŸ”₯)
  • TEMPORARY or TEMP β€” drops all temporary tables created in the current session. poof. gone. not a single trace left 😭
  • ALL β€” releases all temporary resources associated with the current session and resets the session to its initial state. the full glow-up ✨

currently, this has the same effect as executing the following sequence of statements:

CLOSE ALL;
SET SESSION AUTHORIZATION DEFAULT;
RESET ALL;
DEALLOCATE ALL;
UNLISTEN *;
SELECT pg_advisory_unlock_all();
DISCARD PLANS;
DISCARD TEMP;
DISCARD SEQUENCES;

like... she does it ALL. no cap 🫢


⚠️ NOTES

DISCARD ALL cannot be executed inside a transaction block. that's the rule bestie, no exceptions, it will not be negotiated with πŸ’€

🌈 COMPATIBILITY

DISCARD is a PostgreSQL extension. homegrown, iconic, one of ours πŸ‘‘


and that's the whole page fr fr πŸ“ tysm for reading, this was DISCARD(7) from the PostgreSQL 18.6 documentation, dated 2026. stan a clean session, mwah πŸ’–βœ¨

πŸ“¦ where this page comes from