1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-01 12:18:01 +03:00

Add RESET CONNECTION, to reset all aspects of a session.

Hans-J?rgen Sch?nig
This commit is contained in:
Bruce Momjian
2006-04-25 14:09:21 +00:00
parent 11fbdf2f25
commit 6378fdd971
12 changed files with 128 additions and 20 deletions

View File

@@ -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,

View File

@@ -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.