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

Commit38fb906

Browse files
committed
> Joe Conway <mail@joeconway.com> writes:
>>ISTM that "source" is worth knowing.>> Hm, possibly. Any other opinions?This version has the seven fields I proposed, including "source". Here'san example that shows why I think it's valuable:regression=# \xExpanded display is on.regression=# select * from pg_settings where name = 'enable_seqscan';-[ RECORD 1 ]-----------name | enable_seqscansetting | oncontext | uservartype | boolsource | defaultmin_val |max_val |regression=# update pg_settings set setting = 'off' where name ='enable_seqscan';-[ RECORD 1 ]---set_config | offregression=# select * from pg_settings where name = 'enable_seqscan';-[ RECORD 1 ]-----------name | enable_seqscansetting | offcontext | uservartype | boolsource | sessionmin_val |max_val |regression=# alter user postgres set enable_seqscan to 'off';ALTER USER(log out and then back in again)regression=# \xExpanded display is on.regression=# select * from pg_settings where name = 'enable_seqscan';-[ RECORD 1 ]-----------name | enable_seqscansetting | offcontext | uservartype | boolsource | usermin_val |max_val |In the first case, enable_seqscan is set to its default value. Aftersetting it to off, it is obvious that the value has been changed for thesession only. In the third case, you can see that the value has been setspecifically for the user.Joe Conway
1 parenta265b7f commit38fb906

File tree

8 files changed

+204
-55
lines changed

8 files changed

+204
-55
lines changed

‎doc/src/sgml/runtime.sgml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.195 2003/07/23 20:30:35 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.196 2003/07/27 04:35:53 momjian Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -571,14 +571,45 @@ SET ENABLE_SEQSCAN TO OFF;
571571
<row>
572572
<entry><literal>name</literal></entry>
573573
<entry><type>text</type></entry>
574-
<entry>The name of therun-time configuration parameter</entry>
574+
<entry>run-time configuration parameter name</entry>
575575
</row>
576576

577577
<row>
578578
<entry><literal>setting</literal></entry>
579579
<entry><type>text</type></entry>
580-
<entry>Thecurrent value of the run-time configuration parameter</entry>
580+
<entry>current value of the parameter</entry>
581581
</row>
582+
583+
<row>
584+
<entry><literal>context</literal></entry>
585+
<entry><type>text</type></entry>
586+
<entry>context required to set the parameter's value</entry>
587+
</row>
588+
589+
<row>
590+
<entry><literal>vartype</literal></entry>
591+
<entry><type>text</type></entry>
592+
<entry>parameter type</entry>
593+
</row>
594+
595+
<row>
596+
<entry><literal>source</literal></entry>
597+
<entry><type>text</type></entry>
598+
<entry>source of the current parameter value</entry>
599+
</row>
600+
601+
<row>
602+
<entry><literal>min_val</literal></entry>
603+
<entry><type>text</type></entry>
604+
<entry>minimum allowed value of the parameter</entry>
605+
</row>
606+
607+
<row>
608+
<entry><literal>max_val</literal></entry>
609+
<entry><type>text</type></entry>
610+
<entry>maximum allowed value of the parameter</entry>
611+
</row>
612+
582613
</tbody>
583614
</tgroup>
584615
</table>

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

Lines changed: 147 additions & 32 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-
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.139 2003/07/25 20:17:56 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.140 2003/07/27 04:35:53 momjian Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -155,6 +155,47 @@ static char *timezone_string;
155155
staticchar*XactIsoLevel_string;
156156

157157

158+
/*
159+
* Used for pg_settings. Keep in sync with config_type enum above
160+
*/
161+
staticchar*config_type_name[]=
162+
{
163+
"bool",
164+
"integer",
165+
"real",
166+
"string"
167+
};
168+
169+
/*
170+
* Used for pg_settings. Keep in sync with GucContext enum in guc.h
171+
*/
172+
staticchar*GucContextName[]=
173+
{
174+
"internal",
175+
"postmaster",
176+
"sighup",
177+
"backend",
178+
"super-user",
179+
"user"
180+
};
181+
182+
/*
183+
* Used for pg_settings. Keep in sync with GucSource enum in guc.h
184+
*/
185+
staticchar*GucSourceName[]=
186+
{
187+
"default",
188+
"environment variable",
189+
"configuration file",
190+
"command line",
191+
"database",
192+
"user",
193+
"client",
194+
"override",
195+
"session"
196+
};
197+
198+
158199
/* Macros for freeing malloc'd pointers only if appropriate to do so */
159200
/* Some of these tests are probably redundant, but be safe ... */
160201
#defineSET_STRING_VARIABLE(rec,newval) \
@@ -3323,23 +3364,102 @@ GetConfigOptionByName(const char *name, const char **varname)
33233364
* Return GUC variable value by variable number; optionally return canonical
33243365
* form of name. Return value is palloc'd.
33253366
*/
3326-
char*
3327-
GetConfigOptionByNum(intvarnum,constchar**varname,bool*noshow)
3367+
void
3368+
GetConfigOptionByNum(intvarnum,constchar**values,bool*noshow)
33283369
{
3329-
structconfig_generic*conf;
3370+
charbuffer[256];
3371+
structconfig_generic*conf;
33303372

33313373
/* check requested variable number valid */
33323374
Assert((varnum >=0)&& (varnum<num_guc_variables));
33333375

33343376
conf=guc_variables[varnum];
33353377

3336-
if (varname)
3337-
*varname=conf->name;
3338-
33393378
if (noshow)
33403379
*noshow= (conf->flags&GUC_NO_SHOW_ALL) ? true : false;
33413380

3342-
return_ShowOption(conf);
3381+
/* first get the generic attributes */
3382+
3383+
/* name */
3384+
values[0]=conf->name;
3385+
3386+
/* setting : use _ShowOption in order to avoid duplicating the logic */
3387+
values[1]=_ShowOption(conf);
3388+
3389+
/* context */
3390+
values[2]=GucContextName[conf->context];
3391+
3392+
/* vartype */
3393+
values[3]=config_type_name[conf->vartype];
3394+
3395+
/* source */
3396+
values[4]=GucSourceName[conf->source];
3397+
3398+
/* now get the type specifc attributes */
3399+
switch (conf->vartype)
3400+
{
3401+
casePGC_BOOL:
3402+
{
3403+
/* min_val */
3404+
values[5]=NULL;
3405+
3406+
/* max_val */
3407+
values[6]=NULL;
3408+
}
3409+
break;
3410+
3411+
casePGC_INT:
3412+
{
3413+
structconfig_int*lconf= (structconfig_int*)conf;
3414+
3415+
/* min_val */
3416+
snprintf(buffer,sizeof(buffer),"%d",lconf->min);
3417+
values[5]=pstrdup(buffer);
3418+
3419+
/* max_val */
3420+
snprintf(buffer,sizeof(buffer),"%d",lconf->max);
3421+
values[6]=pstrdup(buffer);
3422+
}
3423+
break;
3424+
3425+
casePGC_REAL:
3426+
{
3427+
structconfig_real*lconf= (structconfig_real*)conf;
3428+
3429+
/* min_val */
3430+
snprintf(buffer,sizeof(buffer),"%g",lconf->min);
3431+
values[5]=pstrdup(buffer);
3432+
3433+
/* max_val */
3434+
snprintf(buffer,sizeof(buffer),"%g",lconf->max);
3435+
values[6]=pstrdup(buffer);
3436+
}
3437+
break;
3438+
3439+
casePGC_STRING:
3440+
{
3441+
/* min_val */
3442+
values[5]=NULL;
3443+
3444+
/* max_val */
3445+
values[6]=NULL;
3446+
}
3447+
break;
3448+
3449+
default:
3450+
{
3451+
/*
3452+
* should never get here, but in case we do, set 'em to NULL
3453+
*/
3454+
3455+
/* min_val */
3456+
values[5]=NULL;
3457+
3458+
/* max_val */
3459+
values[6]=NULL;
3460+
}
3461+
break;
3462+
}
33433463
}
33443464

33453465
/*
@@ -3379,6 +3499,8 @@ show_config_by_name(PG_FUNCTION_ARGS)
33793499
* show_all_settings - equiv to SHOW ALL command but implemented as
33803500
* a Table Function.
33813501
*/
3502+
#defineNUM_PG_SETTINGS_ATTS7
3503+
33823504
Datum
33833505
show_all_settings(PG_FUNCTION_ARGS)
33843506
{
@@ -3402,12 +3524,25 @@ show_all_settings(PG_FUNCTION_ARGS)
34023524
*/
34033525
oldcontext=MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
34043526

3405-
/* need a tuple descriptor representing two TEXT columns */
3406-
tupdesc=CreateTemplateTupleDesc(2, false);
3527+
/*
3528+
* need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
3529+
* of the appropriate types
3530+
*/
3531+
tupdesc=CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
34073532
TupleDescInitEntry(tupdesc, (AttrNumber)1,"name",
34083533
TEXTOID,-1,0, false);
34093534
TupleDescInitEntry(tupdesc, (AttrNumber)2,"setting",
34103535
TEXTOID,-1,0, false);
3536+
TupleDescInitEntry(tupdesc, (AttrNumber)3,"context",
3537+
TEXTOID,-1,0, false);
3538+
TupleDescInitEntry(tupdesc, (AttrNumber)4,"vartype",
3539+
TEXTOID,-1,0, false);
3540+
TupleDescInitEntry(tupdesc, (AttrNumber)5,"source",
3541+
TEXTOID,-1,0, false);
3542+
TupleDescInitEntry(tupdesc, (AttrNumber)6,"min_val",
3543+
TEXTOID,-1,0, false);
3544+
TupleDescInitEntry(tupdesc, (AttrNumber)7,"max_val",
3545+
TEXTOID,-1,0, false);
34113546

34123547
/* allocate a slot for a tuple with this tupdesc */
34133548
slot=TupleDescGetSlot(tupdesc);
@@ -3438,9 +3573,7 @@ show_all_settings(PG_FUNCTION_ARGS)
34383573

34393574
if (call_cntr<max_calls)/* do when there is more left to send */
34403575
{
3441-
char*values[2];
3442-
char*varname;
3443-
char*varval;
3576+
char*values[NUM_PG_SETTINGS_ATTS];
34443577
boolnoshow;
34453578
HeapTupletuple;
34463579
Datumresult;
@@ -3450,15 +3583,9 @@ show_all_settings(PG_FUNCTION_ARGS)
34503583
*/
34513584
do
34523585
{
3453-
varval=GetConfigOptionByNum(call_cntr,
3454-
(constchar**)&varname,
3455-
&noshow);
3586+
GetConfigOptionByNum(call_cntr, (constchar**)values,&noshow);
34563587
if (noshow)
34573588
{
3458-
/* varval is a palloc'd copy, so free it */
3459-
if (varval!=NULL)
3460-
pfree(varval);
3461-
34623589
/* bump the counter and get the next config setting */
34633590
call_cntr=++funcctx->call_cntr;
34643591

@@ -3468,24 +3595,12 @@ show_all_settings(PG_FUNCTION_ARGS)
34683595
}
34693596
}while (noshow);
34703597

3471-
/*
3472-
* Prepare a values array for storage in our slot. This should be
3473-
* an array of C strings which will be processed later by the
3474-
* appropriate "in" functions.
3475-
*/
3476-
values[0]=varname;
3477-
values[1]=varval;
3478-
34793598
/* build a tuple */
34803599
tuple=BuildTupleFromCStrings(attinmeta,values);
34813600

34823601
/* make the tuple into a datum */
34833602
result=TupleGetDatum(slot,tuple);
34843603

3485-
/* Clean up */
3486-
if (varval!=NULL)
3487-
pfree(varval);
3488-
34893604
SRF_RETURN_NEXT(funcctx,result);
34903605
}
34913606
else

‎src/bin/initdb/initdb.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
2828
# Portions Copyright (c) 1994, Regents of the University of California
2929
#
30-
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.198 2003/07/23 08:46:54 petere Exp $
30+
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.199 2003/07/27 04:35:53 momjian Exp $
3131
#
3232
#-------------------------------------------------------------------------
3333

@@ -1000,7 +1000,9 @@ CREATE VIEW pg_locks AS \
10001000
10011001
CREATE VIEW pg_settings AS\
10021002
SELECT *\
1003-
FROM pg_show_all_settings() AS A(name text, setting text);
1003+
FROM pg_show_all_settings() AS A\
1004+
(name text, setting text, context text, vartype text,\
1005+
source text, min_val text, max_val text);
10041006
10051007
CREATE RULE pg_settings_u AS\
10061008
ON UPDATE TO pg_settings\

‎src/include/utils/guc.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright 2000-2003 by PostgreSQL Global Development Group
88
* Written by Peter Eisentraut <peter_e@gmx.net>.
99
*
10-
* $Id: guc.h,v 1.35 2003/07/21 21:02:12 momjian Exp $
10+
* $Id: guc.h,v 1.36 2003/07/27 04:35:54 momjian Exp $
1111
*--------------------------------------------------------------------
1212
*/
1313
#ifndefGUC_H
@@ -55,13 +55,13 @@
5555
*/
5656
typedefenum
5757
{
58-
PGC_INTERNAL,
59-
PGC_POSTMASTER,
60-
PGC_SIGHUP,
61-
PGC_BACKEND,
62-
PGC_SUSET,
63-
PGC_USERLIMIT,
64-
PGC_USERSET
58+
PGC_INTERNAL=0,
59+
PGC_POSTMASTER=1,
60+
PGC_SIGHUP=2,
61+
PGC_BACKEND=3,
62+
PGC_SUSET=4,
63+
PGC_USERLIMIT=5,
64+
PGC_USERSET=6
6565
}GucContext;
6666

6767
/*
@@ -73,6 +73,8 @@ typedef enum
7373
* Sources <= PGC_S_OVERRIDE will set the default used by RESET, as well
7474
* as the current value. Note that source == PGC_S_OVERRIDE should be
7575
* used when setting a PGC_INTERNAL option.
76+
*
77+
* Keep in sync with GucSourceName in guc.c
7678
*/
7779
typedefenum
7880
{
@@ -92,7 +94,6 @@ typedef enum
9294
PGC_S_SESSION=9/* SET command */
9395
}GucSource;
9496

95-
9697
/* GUC vars that are actually declared in guc.c, rather than elsewhere */
9798
externboollog_statement;
9899
externboollog_duration;
@@ -132,7 +133,7 @@ extern bool set_config_option(const char *name, const char *value,
132133
externvoidShowGUCConfigOption(constchar*name,DestReceiver*dest);
133134
externvoidShowAllGUCConfig(DestReceiver*dest);
134135
externchar*GetConfigOptionByName(constchar*name,constchar**varname);
135-
externchar*GetConfigOptionByNum(intvarnum,constchar**varname,bool*noshow);
136+
externvoidGetConfigOptionByNum(intvarnum,constchar**values,bool*noshow);
136137
externintGetNumConfigOptions(void);
137138

138139
externvoidSetPGVariable(constchar*name,List*args,boolis_local);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp