mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-03-07 19:47:50 +08:00
Add RESET CONNECTION, to reset all aspects of a session.
Hans-J?rgen Sch?nig
This commit is contained in:
parent
11fbdf2f25
commit
6378fdd971
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/reset.sgml,v 1.26 2003/12/14 00:15:03 neilc Exp $
|
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/reset.sgml,v 1.27 2006/04/25 14:09:06 momjian Exp $
|
||||
PostgreSQL documentation
|
||||
-->
|
||||
|
||||
@ -11,7 +11,8 @@ PostgreSQL documentation
|
||||
|
||||
<refnamediv>
|
||||
<refname>RESET</refname>
|
||||
<refpurpose>restore the value of a run-time parameter to the default value</refpurpose>
|
||||
<refpurpose>restore the value of a run-time parameter to the default value,
|
||||
or reset all aspects of a session</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<indexterm zone="sql-reset">
|
||||
@ -22,6 +23,7 @@ PostgreSQL documentation
|
||||
<synopsis>
|
||||
RESET <replaceable class="PARAMETER">name</replaceable>
|
||||
RESET ALL
|
||||
RESET CONNECTION
|
||||
</synopsis>
|
||||
</refsynopsisdiv>
|
||||
|
||||
@ -50,8 +52,11 @@ SET <replaceable class="parameter">parameter</replaceable> TO DEFAULT
|
||||
|
||||
<para>
|
||||
See the <command>SET</> reference page for details on the
|
||||
transaction behavior of <command>RESET</>.
|
||||
transaction behavior of <command>RESET</>. <command>RESET
|
||||
CONNECTION</command> can be used to reset all aspects of
|
||||
a session, not just parameter values.
|
||||
</para>
|
||||
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
@ -76,7 +81,20 @@ SET <replaceable class="parameter">parameter</replaceable> TO DEFAULT
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>CONNECTION</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Reset the all aspects of a session, including runtime parameters,
|
||||
transaction status, temporary tables, <literal>WITH HOLD</literal>
|
||||
cursors, prepared statements, and <command>LISTEN</command>
|
||||
registrations.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
|
@ -13,7 +13,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.82 2006/03/05 15:58:22 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.83 2006/04/25 14:09:08 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -134,7 +134,6 @@ char *namespace_search_path = NULL;
|
||||
/* Local functions */
|
||||
static void recomputeNamespacePath(void);
|
||||
static void InitTempTableNamespace(void);
|
||||
static void RemoveTempRelations(Oid tempNamespaceId);
|
||||
static void RemoveTempRelationsCallback(int code, Datum arg);
|
||||
static void NamespaceCallback(Datum arg, Oid relid);
|
||||
|
||||
@ -1729,7 +1728,7 @@ AtEOSubXact_Namespace(bool isCommit, SubTransactionId mySubid,
|
||||
* in order to clean out any relations that might have been created by
|
||||
* a crashed backend.
|
||||
*/
|
||||
static void
|
||||
void
|
||||
RemoveTempRelations(Oid tempNamespaceId)
|
||||
{
|
||||
ObjectAddress object;
|
||||
|
@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.129 2006/03/05 15:58:23 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.130 2006/04/25 14:09:10 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -127,7 +127,6 @@ static bool unlistenExitRegistered = false;
|
||||
bool Trace_notify = false;
|
||||
|
||||
|
||||
static void Async_UnlistenAll(void);
|
||||
static void Async_UnlistenOnExit(int code, Datum arg);
|
||||
static void ProcessIncomingNotify(void);
|
||||
static void NotifyMyFrontEnd(char *relname, int32 listenerPID);
|
||||
@ -335,7 +334,7 @@ Async_Unlisten(const char *relname)
|
||||
*
|
||||
*--------------------------------------------------------------
|
||||
*/
|
||||
static void
|
||||
void
|
||||
Async_UnlistenAll(void)
|
||||
{
|
||||
Relation lRel;
|
||||
|
@ -10,7 +10,7 @@
|
||||
* Copyright (c) 2002-2006, PostgreSQL Global Development Group
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.50 2006/04/22 01:25:58 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.51 2006/04/25 14:09:11 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -33,7 +33,6 @@
|
||||
#include "utils/hsearch.h"
|
||||
#include "utils/memutils.h"
|
||||
|
||||
|
||||
/*
|
||||
* The hash table in which prepared queries are stored. This is
|
||||
* per-backend: query plans are not shared between backends.
|
||||
@ -547,6 +546,30 @@ DeallocateQuery(DeallocateStmt *stmt)
|
||||
DropPreparedStatement(stmt->name, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove all prepared plans from the backend.
|
||||
*/
|
||||
void
|
||||
DropAllPreparedStatements(void)
|
||||
{
|
||||
PreparedStatement *prep_statement;
|
||||
HASH_SEQ_STATUS status;
|
||||
|
||||
if (!prepared_queries)
|
||||
return;
|
||||
|
||||
hash_seq_init(&status, prepared_queries);
|
||||
|
||||
while ((prep_statement = (PreparedStatement *) hash_seq_search(&status)))
|
||||
{
|
||||
DropDependentPortals(prep_statement->context);
|
||||
|
||||
/* Flush the context holding the subsidiary data */
|
||||
MemoryContextDelete(prep_statement->context);
|
||||
hash_search(prepared_queries, prep_statement->stmt_name, HASH_REMOVE, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Internal version of DEALLOCATE
|
||||
*
|
||||
|
@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.540 2006/04/24 22:59:19 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.541 2006/04/25 14:09:12 momjian Exp $
|
||||
*
|
||||
* HISTORY
|
||||
* AUTHOR DATE MAJOR EVENT
|
||||
@ -1244,6 +1244,12 @@ VariableResetStmt:
|
||||
n->name = $2;
|
||||
$$ = (Node *) n;
|
||||
}
|
||||
| RESET CONNECTION
|
||||
{
|
||||
VariableResetStmt *n = makeNode(VariableResetStmt);
|
||||
n->name = "connection";
|
||||
$$ = (Node *) n;
|
||||
}
|
||||
| RESET TIME ZONE
|
||||
{
|
||||
VariableResetStmt *n = makeNode(VariableResetStmt);
|
||||
|
@ -10,7 +10,7 @@
|
||||
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.315 2006/04/10 21:53:38 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.316 2006/04/25 14:09:15 momjian Exp $
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
*/
|
||||
@ -32,6 +32,7 @@
|
||||
#include "catalog/namespace.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "commands/async.h"
|
||||
#include "commands/prepare.h"
|
||||
#include "commands/variable.h"
|
||||
#include "commands/vacuum.h"
|
||||
#include "executor/executor.h"
|
||||
@ -53,6 +54,7 @@
|
||||
#include "postmaster/bgwriter.h"
|
||||
#include "postmaster/syslogger.h"
|
||||
#include "postmaster/postmaster.h"
|
||||
#include "storage/backendid.h"
|
||||
#include "storage/bufmgr.h"
|
||||
#include "storage/fd.h"
|
||||
#include "storage/freespace.h"
|
||||
@ -61,11 +63,13 @@
|
||||
#include "tcop/tcopprot.h"
|
||||
#include "utils/array.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/hsearch.h"
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/pg_locale.h"
|
||||
#include "utils/portal.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "pgstat.h"
|
||||
|
||||
|
||||
#ifndef PG_KRB_SRVTAB
|
||||
#define PG_KRB_SRVTAB ""
|
||||
#endif
|
||||
@ -4649,8 +4653,33 @@ GetPGVariableResultDesc(const char *name)
|
||||
void
|
||||
ResetPGVariable(const char *name)
|
||||
{
|
||||
char namespaceName[NAMEDATALEN];
|
||||
Oid namespaceId;
|
||||
|
||||
if (pg_strcasecmp(name, "all") == 0)
|
||||
/* resetting all GUC variables */
|
||||
ResetAllOptions();
|
||||
else if (pg_strcasecmp(name, "connection") == 0)
|
||||
{
|
||||
ResetAllOptions();
|
||||
|
||||
/* Clean temp-tables */
|
||||
snprintf(namespaceName, sizeof(namespaceName), "pg_temp_%d",
|
||||
MyBackendId);
|
||||
namespaceId = GetSysCacheOid(NAMESPACENAME,
|
||||
CStringGetDatum(namespaceName), 0, 0, 0);
|
||||
RemoveTempRelations(namespaceId);
|
||||
|
||||
DropAllPreparedStatements();
|
||||
|
||||
Async_UnlistenAll();
|
||||
|
||||
/* Delete cursors, including WITH HOLD */
|
||||
PortalHashTableDeleteAll();
|
||||
|
||||
if (IsTransactionBlock())
|
||||
UserAbortTransactionBlock();
|
||||
}
|
||||
else
|
||||
set_config_option(name,
|
||||
NULL,
|
||||
|
@ -12,7 +12,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.85 2006/03/05 15:58:49 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.86 2006/04/25 14:09:16 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -402,6 +402,9 @@ DropDependentPortals(MemoryContext queryContext)
|
||||
HASH_SEQ_STATUS status;
|
||||
PortalHashEnt *hentry;
|
||||
|
||||
if (PortalHashTable == NULL)
|
||||
return;
|
||||
|
||||
hash_seq_init(&status, PortalHashTable);
|
||||
|
||||
while ((hentry = (PortalHashEnt *) hash_seq_search(&status)) != NULL)
|
||||
@ -413,6 +416,30 @@ DropDependentPortals(MemoryContext queryContext)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete all WITH HOLD cursors, used by RESET CONNECTION
|
||||
*/
|
||||
void
|
||||
PortalHashTableDeleteAll(void)
|
||||
{
|
||||
HASH_SEQ_STATUS status;
|
||||
PortalHashEnt *hentry;
|
||||
|
||||
if (PortalHashTable == NULL)
|
||||
return;
|
||||
|
||||
hash_seq_init(&status, PortalHashTable);
|
||||
|
||||
while ((hentry = (PortalHashEnt *) hash_seq_search(&status)) != NULL)
|
||||
{
|
||||
Portal portal = hentry->portal;
|
||||
|
||||
if ((portal->cursorOptions & CURSOR_OPT_HOLD) &&
|
||||
portal->status != PORTAL_ACTIVE)
|
||||
PortalDrop(portal, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Pre-commit processing for portals.
|
||||
|
@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/catalog/namespace.h,v 1.39 2006/03/05 15:58:54 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/include/catalog/namespace.h,v 1.40 2006/04/25 14:09:16 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -74,6 +74,8 @@ extern void PopSpecialNamespace(Oid namespaceId);
|
||||
extern Oid FindConversionByName(List *conname);
|
||||
extern Oid FindDefaultConversionProc(int4 for_encoding, int4 to_encoding);
|
||||
|
||||
extern void RemoveTempRelations(Oid tempNamespaceId);
|
||||
|
||||
/* initialization & transaction cleanup code */
|
||||
extern void InitializeSearchPath(void);
|
||||
extern void AtEOXact_Namespace(bool isCommit);
|
||||
|
@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/commands/async.h,v 1.31 2006/03/05 15:58:55 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/include/commands/async.h,v 1.32 2006/04/25 14:09:17 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -19,6 +19,7 @@ extern bool Trace_notify;
|
||||
extern void Async_Notify(const char *relname);
|
||||
extern void Async_Listen(const char *relname);
|
||||
extern void Async_Unlisten(const char *relname);
|
||||
extern void Async_UnlistenAll(void);
|
||||
|
||||
/* perform (or cancel) outbound notify processing at transaction commit */
|
||||
extern void AtCommit_Notify(void);
|
||||
|
@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 2002-2006, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/commands/prepare.h,v 1.18 2006/03/05 15:58:55 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/include/commands/prepare.h,v 1.19 2006/04/25 14:09:18 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -62,6 +62,7 @@ extern void StorePreparedStatement(const char *stmt_name,
|
||||
extern PreparedStatement *FetchPreparedStatement(const char *stmt_name,
|
||||
bool throwError);
|
||||
extern void DropPreparedStatement(const char *stmt_name, bool showError);
|
||||
extern void DropAllPreparedStatements(void);
|
||||
extern List *FetchPreparedStatementParams(const char *stmt_name);
|
||||
extern TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt);
|
||||
extern bool PreparedStatementReturnsTuples(PreparedStatement *stmt);
|
||||
|
@ -39,7 +39,7 @@
|
||||
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/utils/portal.h,v 1.59 2006/03/05 15:59:07 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/include/utils/portal.h,v 1.60 2006/04/25 14:09:19 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -200,6 +200,7 @@ extern void AtSubAbort_Portals(SubTransactionId mySubid,
|
||||
extern void AtSubCleanup_Portals(SubTransactionId mySubid);
|
||||
extern Portal CreatePortal(const char *name, bool allowDup, bool dupSilent);
|
||||
extern Portal CreateNewPortal(void);
|
||||
extern void PortalHashTableDeleteAll(void);
|
||||
extern void PortalDrop(Portal portal, bool isTopCommit);
|
||||
extern void DropDependentPortals(MemoryContext queryContext);
|
||||
extern Portal GetPortalByName(const char *name);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.321 2006/03/07 01:00:19 tgl Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.322 2006/04/25 14:09:21 momjian Exp $ */
|
||||
|
||||
/* Copyright comment */
|
||||
%{
|
||||
@ -1196,6 +1196,8 @@ VariableResetStmt: RESET var_name
|
||||
{ $$ = make_str("reset transaction isolation level"); }
|
||||
| RESET SESSION AUTHORIZATION
|
||||
{ $$ = make_str("reset session authorization"); }
|
||||
| RESET CONNECTION
|
||||
{ $$ = make_str("reset connection"); }
|
||||
| RESET ALL
|
||||
{ $$ = make_str("reset all"); }
|
||||
;
|
||||
|
Loading…
Reference in New Issue
Block a user