DISCARD(7)

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

πŸ’… DISCARD(7) β€” the discard session state glow-up

ok so bestie, this is the DISCARD page from the PostgreSQL docs β€” manual name DISCARD, section 7 of the big PostgreSQL 15.19 Documentation. It's short, it's iconic, and it's literally gonna clean up your whole session vibe. Let's go ✨


🌸 NAME

DISCARD β€” discard session state 🧹

✨ SYNOPSIS

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

πŸ¦‹ DESCRIPTION

Okay so picture this: DISCARD releases internal resources associated with a database session. Basically it's the "clean your room" command for your session's state β€” lowkey obsessed with how useful this is for partially or fully resetting the session's state. 🫢

There are several subcommands, each one releasing a different type of resource. And the DISCARD ALL variant? It subsumes all the others, and also resets additional state β€” main character energy, honestly. πŸ‘‘

πŸŽ€ PARAMETERS

  • PLANS β€” releases all cached query plans. The result? Re-planning has to happen the next time the associated prepared statement is used. Forced fresh start, fr fr. πŸ”₯
  • SEQUENCES β€” discards all cached sequence-related state, and yes that includes currval()/lastval() information and any preallocated sequence values that haven't yet been returned by nextval(). (If you wanna know what preallocated sequence values even are, peep CREATE SEQUENCE β€” that's CREATE_SEQUENCE(7) β€” it explains the whole thing. πŸ‘€)
  • TEMPORARY or TEMP β€” drops all temporary tables created in the current session. Bye bestie πŸ’€
  • ALL β€” releases all temporary resources associated with the current session and resets the session to its initial state. The way that it's currently the same as executing this exact sequence of statements, no cap:
CLOSE ALL;
SET SESSION AUTHORIZATION DEFAULT;
RESET ALL;
DEALLOCATE ALL;
UNLISTEN *;
SELECT pg_advisory_unlock_all();
DISCARD PLANS;
DISCARD TEMP;
DISCARD SEQUENCES;

Look at that little routine. Ate and left no crumbs. πŸ“

⭐ NOTES

Heads up bestie β€” DISCARD ALL cannot be executed inside a transaction block. Like, it's just not happening, don't try it. 😭

🌈 COMPATIBILITY

DISCARD is a PostgreSQL extension. iykyk πŸ’…


and that's the whole page!! ✨ this lil doc dropped as part of PostgreSQL 15.19, dated 2026 β€” mwah, ty for reading, ily, go reset your session πŸ§šπŸ’œ

πŸ“¦ where this page comes from