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

Commita5c43b8

Browse files
committed
Add new system view, pg_config
Move and refactor the underlying code for the pg_config clientapplication to src/common in support of sharing it with a newsystem information SRF called pg_config() which makes the sameinformation available via SQL. Additionally wrap the SRF with anew system view, as called pg_config.Patch by me with extensive input and review by Michael Paquierand additional review by Alvaro Herrera.
1 parentf1f5ec1 commita5c43b8

File tree

16 files changed

+491
-410
lines changed

16 files changed

+491
-410
lines changed

‎doc/src/sgml/catalogs.sgml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7349,6 +7349,11 @@
73497349
<entry>available versions of extensions</entry>
73507350
</row>
73517351

7352+
<row>
7353+
<entry><link linkend="view-pg-config"><structname>pg_config</structname></link></entry>
7354+
<entry>compile-time configuration parameters</entry>
7355+
</row>
7356+
73527357
<row>
73537358
<entry><link linkend="view-pg-cursors"><structname>pg_cursors</structname></link></entry>
73547359
<entry>open cursors</entry>
@@ -7609,6 +7614,53 @@
76097614
</para>
76107615
</sect1>
76117616

7617+
<sect1 id="view-pg-config">
7618+
<title><structname>pg_config</structname></title>
7619+
7620+
<indexterm zone="view-pg-config">
7621+
<primary>pg_config</primary>
7622+
</indexterm>
7623+
7624+
<para>
7625+
The view <structname>pg_config</structname> describes the
7626+
compile-time configuration parameters of the currently installed
7627+
version of <productname>PostgreSQL</>. It is intended, for example, to
7628+
be used by software packages that want to interface to
7629+
<productname>PostgreSQL</> to facilitate finding the required header
7630+
files and libraries. It provides the same basic information as the
7631+
<xref linkend="app-pgconfig"> <productname>PostgreSQL</> Client
7632+
Application.
7633+
</para>
7634+
7635+
<table>
7636+
<title><structname>pg_config</> Columns</title>
7637+
<tgroup cols="3">
7638+
<thead>
7639+
<row>
7640+
<entry>Name</entry>
7641+
<entry>Type</entry>
7642+
<entry>Description</entry>
7643+
</row>
7644+
</thead>
7645+
7646+
<tbody>
7647+
<row>
7648+
<entry><structfield>name</structfield></entry>
7649+
<entry><type>text</type></entry>
7650+
<entry>The parameter name</entry>
7651+
</row>
7652+
7653+
<row>
7654+
<entry><structfield>setting</structfield></entry>
7655+
<entry><type>text</type></entry>
7656+
<entry>The parameter value</entry>
7657+
</row>
7658+
</tbody>
7659+
</tgroup>
7660+
</table>
7661+
7662+
</sect1>
7663+
76127664
<sect1 id="view-pg-cursors">
76137665
<title><structname>pg_cursors</structname></title>
76147666

‎src/backend/catalog/system_views.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,12 @@ CREATE VIEW pg_timezone_abbrevs AS
433433
CREATEVIEWpg_timezone_namesAS
434434
SELECT*FROM pg_timezone_names();
435435

436+
CREATEVIEWpg_configAS
437+
SELECT*FROM pg_config();
438+
439+
REVOKE ALLon pg_configFROM PUBLIC;
440+
REVOKE EXECUTEON FUNCTION pg_config()FROM PUBLIC;
441+
436442
-- Statistics views
437443

438444
CREATEVIEWpg_stat_all_tablesAS

‎src/backend/utils/misc/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ include $(top_builddir)/src/Makefile.global
1414

1515
overrideCPPFLAGS := -I. -I$(srcdir)$(CPPFLAGS)
1616

17-
OBJS = guc.o help_config.opg_rusage.ops_status.o rls.o\
18-
sampling.o superuser.o timeout.o tzparser.o
17+
OBJS = guc.o help_config.opg_config.opg_rusage.o\
18+
ps_status.o rls.osampling.o superuser.o timeout.o tzparser.o
1919

2020
# This location might depend on the installation directories. Therefore
2121
# we can't subsitute it into pg_config.h.

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

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* pg_config.c
4+
*Expose same output as pg_config except as an SRF
5+
*
6+
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
7+
* Portions Copyright (c) 1994, Regents of the University of California
8+
*
9+
* IDENTIFICATION
10+
* src/backend/utils/misc/pg_config.c
11+
*
12+
*-------------------------------------------------------------------------
13+
*/
14+
15+
#include"postgres.h"
16+
17+
#include"funcapi.h"
18+
#include"miscadmin.h"
19+
#include"catalog/pg_type.h"
20+
#include"common/config_info.h"
21+
#include"utils/builtins.h"
22+
#include"utils/elog.h"
23+
#include"port.h"
24+
25+
Datum
26+
pg_config(PG_FUNCTION_ARGS)
27+
{
28+
ReturnSetInfo*rsinfo= (ReturnSetInfo*)fcinfo->resultinfo;
29+
Tuplestorestate*tupstore;
30+
HeapTupletuple;
31+
TupleDesctupdesc;
32+
AttInMetadata*attinmeta;
33+
MemoryContextper_query_ctx;
34+
MemoryContextoldcontext;
35+
ConfigData*configdata;
36+
size_tconfigdata_len;
37+
char*values[2];
38+
inti=0;
39+
40+
/* check to see if caller supports us returning a tuplestore */
41+
if (!rsinfo|| !(rsinfo->allowedModes&SFRM_Materialize))
42+
ereport(ERROR,
43+
(errcode(ERRCODE_SYNTAX_ERROR),
44+
errmsg("materialize mode required, but it is not "
45+
"allowed in this context")));
46+
47+
per_query_ctx=rsinfo->econtext->ecxt_per_query_memory;
48+
oldcontext=MemoryContextSwitchTo(per_query_ctx);
49+
50+
/* get the requested return tuple description */
51+
tupdesc=CreateTupleDescCopy(rsinfo->expectedDesc);
52+
53+
/*
54+
* Check to make sure we have a reasonable tuple descriptor
55+
*/
56+
if (tupdesc->natts!=2||
57+
tupdesc->attrs[0]->atttypid!=TEXTOID||
58+
tupdesc->attrs[1]->atttypid!=TEXTOID)
59+
ereport(ERROR,
60+
(errcode(ERRCODE_SYNTAX_ERROR),
61+
errmsg("query-specified return tuple and "
62+
"function return type are not compatible")));
63+
64+
/* OK to use it */
65+
attinmeta=TupleDescGetAttInMetadata(tupdesc);
66+
67+
/* let the caller know we're sending back a tuplestore */
68+
rsinfo->returnMode=SFRM_Materialize;
69+
70+
/* initialize our tuplestore */
71+
tupstore=tuplestore_begin_heap(true, false,work_mem);
72+
73+
configdata=get_configdata(my_exec_path,&configdata_len);
74+
for (i=0;i<configdata_len;i++)
75+
{
76+
values[0]=configdata[i].name;
77+
values[1]=configdata[i].setting;
78+
79+
tuple=BuildTupleFromCStrings(attinmeta,values);
80+
tuplestore_puttuple(tupstore,tuple);
81+
}
82+
83+
/*
84+
* no longer need the tuple descriptor reference created by
85+
* TupleDescGetAttInMetadata()
86+
*/
87+
ReleaseTupleDesc(tupdesc);
88+
89+
tuplestore_donestoring(tupstore);
90+
rsinfo->setResult=tupstore;
91+
92+
/*
93+
* SFRM_Materialize mode expects us to return a NULL Datum. The actual
94+
* tuples are in our tuplestore and passed back through
95+
* rsinfo->setResult. rsinfo->setDesc is set to the tuple description
96+
* that we actually used to build our tuples with, so the caller can
97+
* verify we did what it was expecting.
98+
*/
99+
rsinfo->setDesc=tupdesc;
100+
MemoryContextSwitchTo(oldcontext);
101+
102+
return (Datum)0;
103+
}

‎src/bin/pg_config/Makefile

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@ include $(top_builddir)/src/Makefile.global
1717

1818
OBJS= pg_config.o$(WIN32RES)
1919

20-
# don't include subdirectory-path-dependent -I and -L switches
21-
STD_CPPFLAGS :=$(filter-out -I$(top_srcdir)/src/include -I$(top_builddir)/src/include,$(CPPFLAGS))
22-
STD_LDFLAGS :=$(filter-out -L$(top_builddir)/src/port,$(LDFLAGS))
23-
24-
overrideCPPFLAGS += -DVAL_CONFIGURE="\"$(configure_args)\""
25-
overrideCPPFLAGS += -DVAL_CC="\"$(CC)\""
26-
overrideCPPFLAGS += -DVAL_CPPFLAGS="\"$(STD_CPPFLAGS)\""
27-
overrideCPPFLAGS += -DVAL_CFLAGS="\"$(CFLAGS)\""
28-
overrideCPPFLAGS += -DVAL_CFLAGS_SL="\"$(CFLAGS_SL)\""
29-
overrideCPPFLAGS += -DVAL_LDFLAGS="\"$(STD_LDFLAGS)\""
30-
overrideCPPFLAGS += -DVAL_LDFLAGS_EX="\"$(LDFLAGS_EX)\""
31-
overrideCPPFLAGS += -DVAL_LDFLAGS_SL="\"$(LDFLAGS_SL)\""
32-
overrideCPPFLAGS += -DVAL_LIBS="\"$(LIBS)\""
33-
3420
all: pg_config
3521

3622
pg_config:$(OBJS) | submake-libpgport

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp