DISCARD(7)

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

🌸 DISCARD 🌸

okay bestie, welcome to the DISCARD(7) page from the PostgreSQL 16.15 docs ✨ this one is literally all about hitting reset on your database session state, and it is giving β€œclean slate” energy πŸ’…


πŸŽ€ NAME πŸŽ€

DISCARD β€” discard session state 🫢

πŸ¦‹ SYNOPSIS πŸ¦‹

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

πŸ’– DESCRIPTION πŸ’–

So DISCARD releases internal resources associated with a database session. Iconic, honestly. 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. Basically ALL is the main character here πŸ‘‘

🌈 PARAMETERS 🌈

  • PLANS β€” releases all cached query plans, forcing re-planning to occur the next time the associated prepared statement is used. The planner is gonna have to think again, no cap 🧠
  • SEQUENCES β€” discards all cached sequence-related state, including currval()/lastval() information and any preallocated sequence values that have not yet been returned by nextval(). (See CREATE SEQUENCE (CREATE_SEQUENCE(7)) for a description of preallocated sequence values.) πŸŽ€
  • TEMPORARY or TEMP β€” drops all temporary tables created in the current session. Bye-bye temp tables, you had a good run πŸ’€
  • ALL β€” releases all temporary resources associated with the current session and resets the session to its initial state. 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;

⭐ NOTES ⭐

DISCARD ALL cannot be executed inside a transaction block. fr fr, do not try to sneak it in there πŸ™ˆ

πŸ’œ COMPATIBILITY πŸ’œ

DISCARD is a PostgreSQL extension. iykyk 🌸


signing off from the PostgreSQL 16.15 docs, 2026 edition β€” stay clean, stay reset, bestie πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from