↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / SQL Commands

DISCARD

discard session state

English manual coverage begins with PostgreSQL 6.4. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

anchor
SQL-DISCARD
file
sql-discard.html
lang
en
name
DISCARD
purpose
discard session state
purpose zh
丢弃会话状态
sections same as
Unknown
slug
18
synopsis html
DISCARD { ALL | PLANS | SEQUENCES | TEMPORARY | TEMP }
synopsis text
DISCARD { ALL | PLANS | SEQUENCES | TEMPORARY | TEMP }

Syntax

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

Read left to right. Branches are choices, bypasses are optional, loops repeat. Select an underlined parameter to open its rule.

DISCARD ALL PLANS SEQUENCES TEMPORARY TEMP

Definition PG 18

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

Description

DISCARD releases internal resources associated with a database session. 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.

Parameters

PLANS

Releases all cached query plans, forcing re-planning to occur the next time the associated prepared statement is used.

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 for a description of preallocated sequence values.)

TEMPORARY or TEMP

Drops all temporary tables created in the current session.

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.

Compatibility

DISCARD is a PostgreSQL extension.

Compare versions

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · wiki-repair-20261023:a47272e51ee2dd74658651b66c2d7748eff75d701cb42fc82112aefd760ed857

Text language: en · wiki-repair-20261023:a47272e51ee2dd74658651b66c2d7748eff75d701cb42fc82112aefd760ed857