From d13e903beaecd45a3721e4c2a7f9ff842ce94a79 Mon Sep 17 00:00:00 2001 From: Neil Conway Date: Thu, 12 Apr 2007 06:53:49 +0000 Subject: RESET SESSION, plus related new DDL commands. Patch from Marko Kreen, reviewed by Neil Conway. This patch adds the following DDL command variants: RESET SESSION, RESET TEMP, RESET PLANS, CLOSE ALL, and DEALLOCATE ALL. RESET SESSION is intended for use by connection pool software and the like, in order to reset a client session to something close to its initial state. Note that while most of these command variants can be executed inside a transaction block (but are not transaction-aware!), RESET SESSION cannot. While this is inconsistent, it is intended to catch programmer mistakes: RESET SESSION in an open transaction block is probably unintended. --- src/backend/utils/misc/guc.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'src/backend/utils/misc/guc.c') diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index f921c75a60b..385411c0582 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -10,7 +10,7 @@ * Written by Peter Eisentraut . * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.383 2007/03/19 23:38:30 wieck Exp $ + * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.384 2007/04/12 06:53:47 neilc Exp $ * *-------------------------------------------------------------------- */ @@ -32,6 +32,7 @@ #include "access/xact.h" #include "catalog/namespace.h" #include "commands/async.h" +#include "commands/prepare.h" #include "commands/vacuum.h" #include "commands/variable.h" #include "commands/trigger.h" @@ -61,6 +62,7 @@ #include "utils/memutils.h" #include "utils/pg_locale.h" #include "utils/plancache.h" +#include "utils/portal.h" #include "utils/ps_status.h" #include "utils/tzparser.h" #include "utils/xml.h" @@ -4951,14 +4953,45 @@ GetPGVariableResultDesc(const char *name) return tupdesc; } +/* + * RESET SESSION command. + */ +static void +ResetSession(bool isTopLevel) +{ + /* + * Disallow RESET SESSION in a transaction block. This is arguably + * inconsistent (we don't make a similar check in the command + * sequence that RESET SESSION is equivalent to), but the idea is + * to catch mistakes: RESET SESSION inside a transaction block + * would leave the transaction still uncommitted. + */ + PreventTransactionChain(isTopLevel, "RESET SESSION"); + + SetPGVariable("session_authorization", NIL, false); + ResetAllOptions(); + DropAllPreparedStatements(); + PortalHashTableDeleteAll(); + Async_UnlistenAll(); + ResetPlanCache(); + ResetTempTableNamespace(); +} + /* * RESET command */ void -ResetPGVariable(const char *name) +ResetPGVariable(const char *name, bool isTopLevel) { if (pg_strcasecmp(name, "all") == 0) ResetAllOptions(); + else if (pg_strcasecmp(name, "session") == 0) + ResetSession(isTopLevel); + else if (pg_strcasecmp(name, "temp") == 0 || + pg_strcasecmp(name, "temporary") == 0) + ResetTempTableNamespace(); + else if (pg_strcasecmp(name, "plans") == 0) + ResetPlanCache(); else set_config_option(name, NULL, -- cgit v1.2.3