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

Commitcf796cc

Browse files
committed
A client_encoding specification coming from the connection request has
to be processed by GUC before InitPostgres, because any required lookupof the encoding conversion function has to be done during InitializeClientEncoding.So, I broke this last week by moving GUC processing to after InitPostgres :-(.What we can do as a compromise is process non-SUSET variables duringcommand line scanning (the same as before), and postpone the processingof only SUSET variables. None of the SUSET variables need to be setbefore InitPostgres.
1 parent5597fee commitcf796cc

File tree

3 files changed

+78
-43
lines changed

3 files changed

+78
-43
lines changed

‎src/backend/tcop/postgres.c

Lines changed: 59 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.438 2004/11/20 00:48:58 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.439 2004/11/24 19:50:59 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -2205,7 +2205,7 @@ PostgresMain(int argc, char *argv[], const char *username)
22052205
boolsecure;
22062206
interrs=0;
22072207
intdebug_flag=-1;/* -1 means not given */
2208-
List*guc_names=NIL;/* forpossibly-SUSET options */
2208+
List*guc_names=NIL;/* for SUSET options */
22092209
List*guc_values=NIL;
22102210
GucContextctx;
22112211
GucSourcegucsource;
@@ -2456,8 +2456,15 @@ PostgresMain(int argc, char *argv[], const char *username)
24562456

24572457
/*
24582458
* s - report usage statistics (timings) after each query
2459+
*
2460+
* Since log options are SUSET, we need to postpone unless
2461+
* still in secure context
24592462
*/
2460-
PendingConfigOption("log_statement_stats","true");
2463+
if (ctx==PGC_BACKEND)
2464+
PendingConfigOption("log_statement_stats","true");
2465+
else
2466+
SetConfigOption("log_statement_stats","true",
2467+
ctx,gucsource);
24612468
break;
24622469

24632470
case't':
@@ -2490,7 +2497,12 @@ PostgresMain(int argc, char *argv[], const char *username)
24902497
break;
24912498
}
24922499
if (tmp)
2493-
PendingConfigOption(tmp,"true");
2500+
{
2501+
if (ctx==PGC_BACKEND)
2502+
PendingConfigOption(tmp,"true");
2503+
else
2504+
SetConfigOption(tmp,"true",ctx,gucsource);
2505+
}
24942506
break;
24952507

24962508
case'v':
@@ -2527,7 +2539,14 @@ PostgresMain(int argc, char *argv[], const char *username)
25272539
optarg)));
25282540
}
25292541

2530-
PendingConfigOption(name,value);
2542+
/*
2543+
* If a SUSET option, must postpone evaluation, unless
2544+
* we are still reading secure switches.
2545+
*/
2546+
if (ctx==PGC_BACKEND&&IsSuperuserConfigOption(name))
2547+
PendingConfigOption(name,value);
2548+
else
2549+
SetConfigOption(name,value,ctx,gucsource);
25312550
free(name);
25322551
if (value)
25332552
free(value);
@@ -2540,6 +2559,32 @@ PostgresMain(int argc, char *argv[], const char *username)
25402559
}
25412560
}
25422561

2562+
/*
2563+
* Process any additional GUC variable settings passed in startup
2564+
* packet. These are handled exactly like command-line variables.
2565+
*/
2566+
if (MyProcPort!=NULL)
2567+
{
2568+
ListCell*gucopts=list_head(MyProcPort->guc_options);
2569+
2570+
while (gucopts)
2571+
{
2572+
char*name;
2573+
char*value;
2574+
2575+
name=lfirst(gucopts);
2576+
gucopts=lnext(gucopts);
2577+
2578+
value=lfirst(gucopts);
2579+
gucopts=lnext(gucopts);
2580+
2581+
if (IsSuperuserConfigOption(name))
2582+
PendingConfigOption(name,value);
2583+
else
2584+
SetConfigOption(name,value,PGC_BACKEND,PGC_S_CLIENT);
2585+
}
2586+
}
2587+
25432588
/* Acquire configuration parameters, unless inherited from postmaster */
25442589
if (!IsUnderPostmaster)
25452590
{
@@ -2677,10 +2722,8 @@ PostgresMain(int argc, char *argv[], const char *username)
26772722
SetProcessingMode(NormalProcessing);
26782723

26792724
/*
2680-
* Now that we know if client is a superuser, we can apply GUC options
2681-
* that came from the client. (For option switches that are definitely
2682-
* not SUSET, we just went ahead and applied them above, but anything
2683-
* that is or might be SUSET has to be postponed to here.)
2725+
* Now that we know if client is a superuser, we can try to apply SUSET
2726+
* GUC options that came from the client.
26842727
*/
26852728
ctx=am_superuser ?PGC_SUSET :PGC_USERSET;
26862729

@@ -2703,41 +2746,19 @@ PostgresMain(int argc, char *argv[], const char *username)
27032746
}
27042747
}
27052748

2706-
/*
2707-
* Process any additional GUC variable settings passed in startup
2708-
* packet.
2709-
*/
2710-
if (MyProcPort!=NULL)
2711-
{
2712-
ListCell*gucopts=list_head(MyProcPort->guc_options);
2713-
2714-
while (gucopts)
2715-
{
2716-
char*name;
2717-
char*value;
2718-
2719-
name=lfirst(gucopts);
2720-
gucopts=lnext(gucopts);
2721-
2722-
value=lfirst(gucopts);
2723-
gucopts=lnext(gucopts);
2724-
2725-
SetConfigOption(name,value,ctx,PGC_S_CLIENT);
2726-
}
2727-
2728-
/*
2729-
* set up handler to log session end.
2730-
*/
2731-
if (IsUnderPostmaster&&Log_disconnections)
2732-
on_proc_exit(log_disconnections,0);
2733-
}
2734-
27352749
/*
27362750
* Now all GUC states are fully set up. Report them to client if
27372751
* appropriate.
27382752
*/
27392753
BeginReportingGUCOptions();
27402754

2755+
/*
2756+
* Also set up handler to log session end; we have to wait till now
2757+
* to be sure Log_disconnections has its final value.
2758+
*/
2759+
if (IsUnderPostmaster&&Log_disconnections)
2760+
on_proc_exit(log_disconnections,0);
2761+
27412762
/*
27422763
* Send this backend's cancellation info to the frontend.
27432764
*/

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

Lines changed: 16 additions & 1 deletion
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.249 2004/11/14 19:35:33 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.250 2004/11/24 19:51:03 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -3864,6 +3864,21 @@ GetConfigOptionResetString(const char *name)
38643864
returnNULL;
38653865
}
38663866

3867+
/*
3868+
* Detect whether the given configuration option can only be set by
3869+
* a superuser.
3870+
*/
3871+
bool
3872+
IsSuperuserConfigOption(constchar*name)
3873+
{
3874+
structconfig_generic*record;
3875+
3876+
record=find_option(name,ERROR);
3877+
/* On an unrecognized name, don't error, just return false. */
3878+
if (record==NULL)
3879+
return false;
3880+
return (record->context==PGC_SUSET);
3881+
}
38673882

38683883

38693884
/*

‎src/include/utils/guc.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 2000-2004, PostgreSQL Global Development Group
88
* Written by Peter Eisentraut <peter_e@gmx.net>.
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.56 2004/11/14 19:35:35 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.57 2004/11/24 19:51:05 tgl Exp $
1111
*--------------------------------------------------------------------
1212
*/
1313
#ifndefGUC_H
@@ -44,9 +44,7 @@
4444
* given backend once it's started, but they can vary across backends.
4545
*
4646
* SUSET options can be set at postmaster startup, with the SIGHUP
47-
* mechanism, or from SQL if you're a superuser. These options cannot
48-
* be set in the connection startup packet, because when it is processed
49-
* we don't yet know if the user is a superuser.
47+
* mechanism, or from SQL if you're a superuser.
5048
*
5149
* USERSET options can be set by anyone any time.
5250
*/
@@ -177,6 +175,7 @@ extern void EmitWarningsOnPlaceholders(const char *className);
177175

178176
externconstchar*GetConfigOption(constchar*name);
179177
externconstchar*GetConfigOptionResetString(constchar*name);
178+
externboolIsSuperuserConfigOption(constchar*name);
180179
externvoidProcessConfigFile(GucContextcontext);
181180
externvoidInitializeGUCOptions(void);
182181
externboolSelectConfigFiles(constchar*userDoption,constchar*progname);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp