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

Commit3e707fb

Browse files
committed
psql: add \dconfig command to show server's configuration parameters.
Plain \dconfig is basically equivalent to SHOW except that you cangive it a pattern with wildcards, either to match multiple GUCs orbecause you don't exactly remember the name you want.\dconfig+ adds type, context, and access-privilege information,mainly because every other kind of object privilege has a psql commandto show it, so GUC privileges should too. (A form of this command wasin some versions of the patch series leading up to commita0ffa88.We pulled it out then because of doubts that the design and code wereup to snuff, but I think subsequent work has resolved that.)In passing, fix incorrect completion of GUC names in GRANT/REVOKEON PARAMETER:a0ffa88 neglected to use the VERBATIM form ofCOMPLETE_WITH_QUERY, so it misbehaved for custom (qualified) GUCnames.Mark Dilger and Tom LaneDiscussion:https://postgr.es/m/3118455.1649267333@sss.pgh.pa.us
1 parent16acf7f commit3e707fb

File tree

10 files changed

+127
-6
lines changed

10 files changed

+127
-6
lines changed

‎doc/src/sgml/ddl.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2205,7 +2205,7 @@ REVOKE ALL ON accounts FROM PUBLIC;
22052205
<entry><literal>PARAMETER</literal></entry>
22062206
<entry><literal>sA</literal></entry>
22072207
<entry>none</entry>
2208-
<entry>none</entry>
2208+
<entry><literal>\dconfig+</literal></entry>
22092209
</row>
22102210
<row>
22112211
<entry><literal>SCHEMA</literal></entry>

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,23 @@ testdb=&gt;
13801380
</varlistentry>
13811381

13821382

1383+
<varlistentry>
1384+
<term><literal>\dconfig[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1385+
<listitem>
1386+
<para>
1387+
Lists server configuration parameters and their values.
1388+
If <replaceable class="parameter">pattern</replaceable>
1389+
is specified, only parameters whose names match the pattern are
1390+
listed.
1391+
If <literal>+</literal> is appended to the command name, each
1392+
parameter is listed with its data type, context in which the
1393+
parameter can be set, and access privileges (if non-default access
1394+
privileges have been granted).
1395+
</para>
1396+
</listitem>
1397+
</varlistentry>
1398+
1399+
13831400
<varlistentry>
13841401
<term><literal>\dC[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
13851402
<listitem>

‎src/bin/psql/command.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,14 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
780780
success=describeTablespaces(pattern,show_verbose);
781781
break;
782782
case'c':
783-
success=listConversions(pattern,show_verbose,show_system);
783+
if (strncmp(cmd,"dconfig",7)==0)
784+
success=describeConfigurationParameters(pattern,
785+
show_verbose,
786+
show_system);
787+
else
788+
success=listConversions(pattern,
789+
show_verbose,
790+
show_system);
784791
break;
785792
case'C':
786793
success=listCasts(pattern,show_verbose);

‎src/bin/psql/describe.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4364,6 +4364,68 @@ listConversions(const char *pattern, bool verbose, bool showSystem)
43644364
return true;
43654365
}
43664366

4367+
/*
4368+
* \dconfig
4369+
*
4370+
* Describes configuration parameters.
4371+
*/
4372+
bool
4373+
describeConfigurationParameters(constchar*pattern,boolverbose,
4374+
boolshowSystem)
4375+
{
4376+
PQExpBufferDatabuf;
4377+
PGresult*res;
4378+
printQueryOptmyopt=pset.popt;
4379+
4380+
initPQExpBuffer(&buf);
4381+
printfPQExpBuffer(&buf,
4382+
"SELECT s.name AS \"%s\", "
4383+
"pg_catalog.current_setting(s.name) AS \"%s\"",
4384+
gettext_noop("Parameter"),
4385+
gettext_noop("Value"));
4386+
4387+
if (verbose)
4388+
{
4389+
appendPQExpBuffer(&buf,
4390+
", s.vartype AS \"%s\", s.context AS \"%s\", ",
4391+
gettext_noop("Type"),
4392+
gettext_noop("Context"));
4393+
if (pset.sversion >=150000)
4394+
printACLColumn(&buf,"p.paracl");
4395+
else
4396+
appendPQExpBuffer(&buf,"NULL AS \"%s\"",
4397+
gettext_noop("Access privileges"));
4398+
}
4399+
4400+
appendPQExpBufferStr(&buf,"\nFROM pg_catalog.pg_settings s\n");
4401+
4402+
if (verbose&&pset.sversion >=150000)
4403+
appendPQExpBufferStr(&buf,
4404+
" LEFT JOIN pg_catalog.pg_parameter_acl p\n"
4405+
" ON pg_catalog.lower(s.name) = p.parname\n");
4406+
4407+
processSQLNamePattern(pset.db,&buf,pattern,
4408+
false, false,
4409+
NULL,"pg_catalog.lower(s.name)",NULL,
4410+
NULL);
4411+
4412+
appendPQExpBufferStr(&buf,"ORDER BY 1;");
4413+
4414+
res=PSQLexec(buf.data);
4415+
termPQExpBuffer(&buf);
4416+
if (!res)
4417+
return false;
4418+
4419+
myopt.nullPrint=NULL;
4420+
myopt.title=_("List of configuration parameters");
4421+
myopt.translate_header= true;
4422+
4423+
printQuery(res,&myopt,pset.queryFout, false,pset.logfile);
4424+
4425+
PQclear(res);
4426+
return true;
4427+
}
4428+
43674429
/*
43684430
* \dy
43694431
*

‎src/bin/psql/describe.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ extern bool listDomains(const char *pattern, bool verbose, bool showSystem);
7676
/* \dc */
7777
externboollistConversions(constchar*pattern,boolverbose,boolshowSystem);
7878

79+
/* \dconfig */
80+
externbooldescribeConfigurationParameters(constchar*pattern,boolverbose,
81+
boolshowSystem);
82+
7983
/* \dC */
8084
externboollistCasts(constchar*pattern,boolverbose);
8185

‎src/bin/psql/help.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ slashUsage(unsigned short int pager)
166166
* Use "psql --help=commands | wc" to count correctly. It's okay to count
167167
* the USE_READLINE line even in builds without that.
168168
*/
169-
output=PageOutput(137,pager ?&(pset.popt.topt) :NULL);
169+
output=PageOutput(138,pager ?&(pset.popt.topt) :NULL);
170170

171171
fprintf(output,_("General\n"));
172172
fprintf(output,_(" \\copyright show PostgreSQL usage and distribution terms\n"));
@@ -231,6 +231,7 @@ slashUsage(unsigned short int pager)
231231
fprintf(output,_(" \\dAp[+] [AMPTRN [OPFPTRN]] list support functions of operator families\n"));
232232
fprintf(output,_(" \\db[+] [PATTERN] list tablespaces\n"));
233233
fprintf(output,_(" \\dc[S+] [PATTERN] list conversions\n"));
234+
fprintf(output,_(" \\dconfig[+] [PATTERN] list configuration parameters\n"));
234235
fprintf(output,_(" \\dC[+] [PATTERN] list casts\n"));
235236
fprintf(output,_(" \\dd[S] [PATTERN] show object descriptions not displayed elsewhere\n"));
236237
fprintf(output,_(" \\dD[S+] [PATTERN] list domains\n"));

‎src/bin/psql/tab-complete.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ static const SchemaQuery Query_for_trigger_of_table = {
10041004
"SELECT nspname FROM pg_catalog.pg_namespace "\
10051005
" WHERE nspname LIKE '%s'"
10061006

1007+
/* Use COMPLETE_WITH_QUERY_VERBATIM with these queries for GUC names: */
10071008
#defineQuery_for_list_of_alter_system_set_vars \
10081009
"SELECT name FROM "\
10091010
" (SELECT pg_catalog.lower(name) AS name FROM pg_catalog.pg_settings "\
@@ -1690,7 +1691,7 @@ psql_completion(const char *text, int start, int end)
16901691
"\\connect","\\conninfo","\\C","\\cd","\\copy",
16911692
"\\copyright","\\crosstabview",
16921693
"\\d","\\da","\\dA","\\dAc","\\dAf","\\dAo","\\dAp",
1693-
"\\db","\\dc","\\dC","\\dd","\\ddp","\\dD",
1694+
"\\db","\\dc","\\dconfig","\\dC","\\dd","\\ddp","\\dD",
16941695
"\\des","\\det","\\deu","\\dew","\\dE","\\df",
16951696
"\\dF","\\dFd","\\dFp","\\dFt","\\dg","\\di","\\dl","\\dL",
16961697
"\\dm","\\dn","\\do","\\dO","\\dp","\\dP","\\dPi","\\dPt",
@@ -3780,7 +3781,7 @@ psql_completion(const char *text, int start, int end)
37803781
TailMatches("GRANT|REVOKE",MatchAny,MatchAny,"ON","PARAMETER")||
37813782
TailMatches("REVOKE","GRANT","OPTION","FOR",MatchAny,"ON","PARAMETER")||
37823783
TailMatches("REVOKE","GRANT","OPTION","FOR",MatchAny,MatchAny,"ON","PARAMETER"))
3783-
COMPLETE_WITH_QUERY(Query_for_list_of_alter_system_set_vars);
3784+
COMPLETE_WITH_QUERY_VERBATIM(Query_for_list_of_alter_system_set_vars);
37843785

37853786
elseif (TailMatches("GRANT",MatchAny,"ON","PARAMETER",MatchAny)||
37863787
TailMatches("GRANT",MatchAny,MatchAny,"ON","PARAMETER",MatchAny))
@@ -4532,6 +4533,8 @@ psql_completion(const char *text, int start, int end)
45324533
COMPLETE_WITH_QUERY(Query_for_list_of_access_methods);
45334534
elseif (TailMatchesCS("\\db*"))
45344535
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
4536+
elseif (TailMatchesCS("\\dconfig*"))
4537+
COMPLETE_WITH_QUERY_VERBATIM(Query_for_list_of_show_vars);
45354538
elseif (TailMatchesCS("\\dD*"))
45364539
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_domains);
45374540
elseif (TailMatchesCS("\\des*"))

‎src/fe_utils/string_utils.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,8 +918,12 @@ processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern,
918918
* Convert shell-style 'pattern' into the regular expression(s) we want to
919919
* execute. Quoting/escaping into SQL literal format will be done below
920920
* using appendStringLiteralConn().
921+
*
922+
* If the caller provided a schemavar, we want to split the pattern on
923+
* ".", otherwise not.
921924
*/
922-
patternToSQLRegex(PQclientEncoding(conn),NULL,&schemabuf,&namebuf,
925+
patternToSQLRegex(PQclientEncoding(conn),NULL,
926+
(schemavar ?&schemabuf :NULL),&namebuf,
923927
pattern,force_escape);
924928

925929
/*

‎src/test/regress/expected/psql.out

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5090,6 +5090,23 @@ List of access methods
50905090
hash | uuid_ops | uuid | uuid | 2 | uuid_hash_extended
50915091
(5 rows)
50925092

5093+
-- check \dconfig
5094+
set work_mem = 10240;
5095+
\dconfig work_mem
5096+
List of configuration parameters
5097+
Parameter | Value
5098+
-----------+-------
5099+
work_mem | 10MB
5100+
(1 row)
5101+
5102+
\dconfig+ work*
5103+
List of configuration parameters
5104+
Parameter | Value | Type | Context | Access privileges
5105+
-----------+-------+---------+---------+-------------------
5106+
work_mem | 10MB | integer | user |
5107+
(1 row)
5108+
5109+
reset work_mem;
50935110
-- check \df, \do with argument specifications
50945111
\df *sqrt
50955112
List of functions

‎src/test/regress/sql/psql.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,12 @@ drop role regress_partitioning_role;
12411241
\dAp+ btree float_ops
12421242
\dAp*pg_catalog.uuid_ops
12431243

1244+
-- check \dconfig
1245+
set work_mem=10240;
1246+
\dconfig work_mem
1247+
\dconfig+ work*
1248+
reset work_mem;
1249+
12441250
-- check \df, \do with argument specifications
12451251
\df*sqrt
12461252
\df*sqrt num*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp