DISCARD(7)
π 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 includescurrval()/lastval()information and any preallocated sequence values that haven't yet been returned bynextval(). (If you wanna know what preallocated sequence values even are, peepCREATE SEQUENCEβ that'sCREATE_SEQUENCE(7)β it explains the whole thing. π)TEMPORARYorTEMPβ 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
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms