Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6378fdd

Browse files
committed
Add RESET CONNECTION, to reset all aspects of a session.
Hans-J?rgen Sch?nig
1 parent11fbdf2 commit6378fdd

File tree

12 files changed

+128
-20
lines changed

12 files changed

+128
-20
lines changed

‎doc/src/sgml/ref/reset.sgml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/reset.sgml,v 1.26 2003/12/14 00:15:03 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/reset.sgml,v 1.27 2006/04/25 14:09:06 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -11,7 +11,8 @@ PostgreSQL documentation
1111

1212
<refnamediv>
1313
<refname>RESET</refname>
14-
<refpurpose>restore the value of a run-time parameter to the default value</refpurpose>
14+
<refpurpose>restore the value of a run-time parameter to the default value,
15+
or reset all aspects of a session</refpurpose>
1516
</refnamediv>
1617

1718
<indexterm zone="sql-reset">
@@ -22,6 +23,7 @@ PostgreSQL documentation
2223
<synopsis>
2324
RESET <replaceable class="PARAMETER">name</replaceable>
2425
RESET ALL
26+
RESET CONNECTION
2527
</synopsis>
2628
</refsynopsisdiv>
2729

@@ -50,8 +52,11 @@ SET <replaceable class="parameter">parameter</replaceable> TO DEFAULT
5052

5153
<para>
5254
See the <command>SET</> reference page for details on the
53-
transaction behavior of <command>RESET</>.
55+
transaction behavior of <command>RESET</>. <command>RESET
56+
CONNECTION</command> can be used to reset all aspects of
57+
a session, not just parameter values.
5458
</para>
59+
5560
</refsect1>
5661

5762
<refsect1>
@@ -76,7 +81,20 @@ SET <replaceable class="parameter">parameter</replaceable> TO DEFAULT
7681
</para>
7782
</listitem>
7883
</varlistentry>
84+
85+
<varlistentry>
86+
<term><literal>CONNECTION</literal></term>
87+
<listitem>
88+
<para>
89+
Reset the all aspects of a session, including runtime parameters,
90+
transaction status, temporary tables, <literal>WITH HOLD</literal>
91+
cursors, prepared statements, and <command>LISTEN</command>
92+
registrations.
93+
</para>
94+
</listitem>
95+
</varlistentry>
7996
</variablelist>
97+
8098
</refsect1>
8199

82100
<refsect1>

‎src/backend/catalog/namespace.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.82 2006/03/05 15:58:22 momjian Exp $
16+
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.83 2006/04/25 14:09:08 momjian Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -134,7 +134,6 @@ char *namespace_search_path = NULL;
134134
/* Local functions */
135135
staticvoidrecomputeNamespacePath(void);
136136
staticvoidInitTempTableNamespace(void);
137-
staticvoidRemoveTempRelations(OidtempNamespaceId);
138137
staticvoidRemoveTempRelationsCallback(intcode,Datumarg);
139138
staticvoidNamespaceCallback(Datumarg,Oidrelid);
140139

@@ -1729,7 +1728,7 @@ AtEOSubXact_Namespace(bool isCommit, SubTransactionId mySubid,
17291728
* in order to clean out any relations that might have been created by
17301729
* a crashed backend.
17311730
*/
1732-
staticvoid
1731+
void
17331732
RemoveTempRelations(OidtempNamespaceId)
17341733
{
17351734
ObjectAddressobject;

‎src/backend/commands/async.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.129 2006/03/05 15:58:23 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.130 2006/04/25 14:09:10 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -127,7 +127,6 @@ static bool unlistenExitRegistered = false;
127127
boolTrace_notify= false;
128128

129129

130-
staticvoidAsync_UnlistenAll(void);
131130
staticvoidAsync_UnlistenOnExit(intcode,Datumarg);
132131
staticvoidProcessIncomingNotify(void);
133132
staticvoidNotifyMyFrontEnd(char*relname,int32listenerPID);
@@ -335,7 +334,7 @@ Async_Unlisten(const char *relname)
335334
*
336335
*--------------------------------------------------------------
337336
*/
338-
staticvoid
337+
void
339338
Async_UnlistenAll(void)
340339
{
341340
RelationlRel;

‎src/backend/commands/prepare.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Copyright (c) 2002-2006, PostgreSQL Global Development Group
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.50 2006/04/22 01:25:58 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.51 2006/04/25 14:09:11 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -33,7 +33,6 @@
3333
#include"utils/hsearch.h"
3434
#include"utils/memutils.h"
3535

36-
3736
/*
3837
* The hash table in which prepared queries are stored. This is
3938
* per-backend: query plans are not shared between backends.
@@ -547,6 +546,30 @@ DeallocateQuery(DeallocateStmt *stmt)
547546
DropPreparedStatement(stmt->name, true);
548547
}
549548

549+
/*
550+
* Remove all prepared plans from the backend.
551+
*/
552+
void
553+
DropAllPreparedStatements(void)
554+
{
555+
PreparedStatement*prep_statement;
556+
HASH_SEQ_STATUSstatus;
557+
558+
if(!prepared_queries)
559+
return;
560+
561+
hash_seq_init(&status,prepared_queries);
562+
563+
while ((prep_statement= (PreparedStatement*)hash_seq_search(&status)))
564+
{
565+
DropDependentPortals(prep_statement->context);
566+
567+
/* Flush the context holding the subsidiary data */
568+
MemoryContextDelete(prep_statement->context);
569+
hash_search(prepared_queries,prep_statement->stmt_name,HASH_REMOVE,NULL);
570+
}
571+
}
572+
550573
/*
551574
* Internal version of DEALLOCATE
552575
*

‎src/backend/parser/gram.y

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.540 2006/04/24 22:59:19 momjian Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.541 2006/04/25 14:09:12 momjian Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -1244,6 +1244,12 @@ VariableResetStmt:
12441244
n->name =$2;
12451245
$$ = (Node *) n;
12461246
}
1247+
|RESETCONNECTION
1248+
{
1249+
VariableResetStmt *n = makeNode(VariableResetStmt);
1250+
n->name ="connection";
1251+
$$ = (Node *) n;
1252+
}
12471253
|RESETTIMEZONE
12481254
{
12491255
VariableResetStmt *n = makeNode(VariableResetStmt);

‎src/backend/utils/misc/guc.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.315 2006/04/10 21:53:38 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.316 2006/04/25 14:09:15 momjian Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -32,6 +32,7 @@
3232
#include"catalog/namespace.h"
3333
#include"catalog/pg_type.h"
3434
#include"commands/async.h"
35+
#include"commands/prepare.h"
3536
#include"commands/variable.h"
3637
#include"commands/vacuum.h"
3738
#include"executor/executor.h"
@@ -53,6 +54,7 @@
5354
#include"postmaster/bgwriter.h"
5455
#include"postmaster/syslogger.h"
5556
#include"postmaster/postmaster.h"
57+
#include"storage/backendid.h"
5658
#include"storage/bufmgr.h"
5759
#include"storage/fd.h"
5860
#include"storage/freespace.h"
@@ -61,11 +63,13 @@
6163
#include"tcop/tcopprot.h"
6264
#include"utils/array.h"
6365
#include"utils/builtins.h"
66+
#include"utils/hsearch.h"
6467
#include"utils/memutils.h"
6568
#include"utils/pg_locale.h"
69+
#include"utils/portal.h"
70+
#include"utils/syscache.h"
6671
#include"pgstat.h"
6772

68-
6973
#ifndefPG_KRB_SRVTAB
7074
#definePG_KRB_SRVTAB ""
7175
#endif
@@ -4649,8 +4653,33 @@ GetPGVariableResultDesc(const char *name)
46494653
void
46504654
ResetPGVariable(constchar*name)
46514655
{
4656+
charnamespaceName[NAMEDATALEN];
4657+
OidnamespaceId;
4658+
46524659
if (pg_strcasecmp(name,"all")==0)
4660+
/* resetting all GUC variables */
46534661
ResetAllOptions();
4662+
elseif(pg_strcasecmp(name,"connection")==0)
4663+
{
4664+
ResetAllOptions();
4665+
4666+
/* Clean temp-tables */
4667+
snprintf(namespaceName,sizeof(namespaceName),"pg_temp_%d",
4668+
MyBackendId);
4669+
namespaceId=GetSysCacheOid(NAMESPACENAME,
4670+
CStringGetDatum(namespaceName),0,0,0);
4671+
RemoveTempRelations(namespaceId);
4672+
4673+
DropAllPreparedStatements();
4674+
4675+
Async_UnlistenAll();
4676+
4677+
/* Delete cursors, including WITH HOLD */
4678+
PortalHashTableDeleteAll();
4679+
4680+
if (IsTransactionBlock())
4681+
UserAbortTransactionBlock();
4682+
}
46544683
else
46554684
set_config_option(name,
46564685
NULL,

‎src/backend/utils/mmgr/portalmem.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.85 2006/03/05 15:58:49 momjian Exp $
15+
* $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.86 2006/04/25 14:09:16 momjian Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -402,6 +402,9 @@ DropDependentPortals(MemoryContext queryContext)
402402
HASH_SEQ_STATUSstatus;
403403
PortalHashEnt*hentry;
404404

405+
if (PortalHashTable==NULL)
406+
return;
407+
405408
hash_seq_init(&status,PortalHashTable);
406409

407410
while ((hentry= (PortalHashEnt*)hash_seq_search(&status))!=NULL)
@@ -413,6 +416,30 @@ DropDependentPortals(MemoryContext queryContext)
413416
}
414417
}
415418

419+
/*
420+
* Delete all WITH HOLD cursors, used by RESET CONNECTION
421+
*/
422+
void
423+
PortalHashTableDeleteAll(void)
424+
{
425+
HASH_SEQ_STATUSstatus;
426+
PortalHashEnt*hentry;
427+
428+
if (PortalHashTable==NULL)
429+
return;
430+
431+
hash_seq_init(&status,PortalHashTable);
432+
433+
while ((hentry= (PortalHashEnt*)hash_seq_search(&status))!=NULL)
434+
{
435+
Portalportal=hentry->portal;
436+
437+
if((portal->cursorOptions&CURSOR_OPT_HOLD)&&
438+
portal->status!=PORTAL_ACTIVE)
439+
PortalDrop(portal, false);
440+
}
441+
}
442+
416443

417444
/*
418445
* Pre-commit processing for portals.

‎src/include/catalog/namespace.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/namespace.h,v 1.39 2006/03/05 15:58:54 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/namespace.h,v 1.40 2006/04/25 14:09:16 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -74,6 +74,8 @@ extern void PopSpecialNamespace(Oid namespaceId);
7474
externOidFindConversionByName(List*conname);
7575
externOidFindDefaultConversionProc(int4for_encoding,int4to_encoding);
7676

77+
externvoidRemoveTempRelations(OidtempNamespaceId);
78+
7779
/* initialization & transaction cleanup code */
7880
externvoidInitializeSearchPath(void);
7981
externvoidAtEOXact_Namespace(boolisCommit);

‎src/include/commands/async.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/commands/async.h,v 1.31 2006/03/05 15:58:55 momjian Exp $
9+
* $PostgreSQL: pgsql/src/include/commands/async.h,v 1.32 2006/04/25 14:09:17 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -19,6 +19,7 @@ extern bool Trace_notify;
1919
externvoidAsync_Notify(constchar*relname);
2020
externvoidAsync_Listen(constchar*relname);
2121
externvoidAsync_Unlisten(constchar*relname);
22+
externvoidAsync_UnlistenAll(void);
2223

2324
/* perform (or cancel) outbound notify processing at transaction commit */
2425
externvoidAtCommit_Notify(void);

‎src/include/commands/prepare.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 2002-2006, PostgreSQL Global Development Group
88
*
9-
* $PostgreSQL: pgsql/src/include/commands/prepare.h,v 1.18 2006/03/05 15:58:55 momjian Exp $
9+
* $PostgreSQL: pgsql/src/include/commands/prepare.h,v 1.19 2006/04/25 14:09:18 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -62,6 +62,7 @@ extern void StorePreparedStatement(const char *stmt_name,
6262
externPreparedStatement*FetchPreparedStatement(constchar*stmt_name,
6363
boolthrowError);
6464
externvoidDropPreparedStatement(constchar*stmt_name,boolshowError);
65+
externvoidDropAllPreparedStatements(void);
6566
externList*FetchPreparedStatementParams(constchar*stmt_name);
6667
externTupleDescFetchPreparedStatementResultDesc(PreparedStatement*stmt);
6768
externboolPreparedStatementReturnsTuples(PreparedStatement*stmt);

‎src/include/utils/portal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
4040
* Portions Copyright (c) 1994, Regents of the University of California
4141
*
42-
* $PostgreSQL: pgsql/src/include/utils/portal.h,v 1.59 2006/03/05 15:59:07 momjian Exp $
42+
* $PostgreSQL: pgsql/src/include/utils/portal.h,v 1.60 2006/04/25 14:09:19 momjian Exp $
4343
*
4444
*-------------------------------------------------------------------------
4545
*/
@@ -200,6 +200,7 @@ extern void AtSubAbort_Portals(SubTransactionId mySubid,
200200
externvoidAtSubCleanup_Portals(SubTransactionIdmySubid);
201201
externPortalCreatePortal(constchar*name,boolallowDup,booldupSilent);
202202
externPortalCreateNewPortal(void);
203+
externvoidPortalHashTableDeleteAll(void);
203204
externvoidPortalDrop(Portalportal,boolisTopCommit);
204205
externvoidDropDependentPortals(MemoryContextqueryContext);
205206
externPortalGetPortalByName(constchar*name);

‎src/interfaces/ecpg/preproc/preproc.y

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.321 2006/03/07 01:00:19 tgl Exp $*/
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.322 2006/04/25 14:09:21 momjian Exp $*/
22

33
/* Copyright comment*/
44
%{
@@ -1196,6 +1196,8 @@ VariableResetStmt:RESET var_name
11961196
{$$ = make_str("reset transaction isolation level"); }
11971197
|RESETSESSIONAUTHORIZATION
11981198
{$$ = make_str("reset session authorization"); }
1199+
|RESETCONNECTION
1200+
{$$ = make_str("reset connection"); }
11991201
|RESETALL
12001202
{$$ = make_str("reset all"); }
12011203
;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp