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

Commitaaa6e1d

Browse files
committed
Add postmaster -C option to query configuration parameters, and have
pg_ctl use that to query the data directory for config-only installs.This fixes awkward or impossible pg_ctl operation for config-onlyinstalls.
1 parent7f3bd86 commitaaa6e1d

File tree

5 files changed

+100
-10
lines changed

5 files changed

+100
-10
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,20 @@ PostgreSQL documentation
140140
</listitem>
141141
</varlistentry>
142142

143+
<varlistentry>
144+
<term><option>-C <replaceable>name</replaceable></option></term>
145+
<listitem>
146+
<para>
147+
Returns the value of a named run-time parameter, and exits.
148+
(See the <option>-c</> option above for details.) This can
149+
be used on a running server, and returns values from
150+
<filename>postgresql.conf</>, modified by any parameters
151+
supplied in this invocation. It does not reflect parameters
152+
supplied when the cluster was started.
153+
</para>
154+
</listitem>
155+
</varlistentry>
156+
143157
<varlistentry>
144158
<term><option>-d <replaceable>debug-level</replaceable></option></term>
145159
<listitem>

‎src/backend/main/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ help(const char *progname)
283283
#endif
284284
printf(_(" -B NBUFFERS number of shared buffers\n"));
285285
printf(_(" -c NAME=VALUE set run-time parameter\n"));
286+
printf(_(" -C NAME return run-time parameter\n"));
286287
printf(_(" -d 1-5 debugging level\n"));
287288
printf(_(" -D DATADIR database directory\n"));
288289
printf(_(" -e use European date input format (DMY)\n"));

‎src/backend/postmaster/postmaster.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ boolenable_bonjour = false;
203203
char*bonjour_name;
204204
boolrestart_after_crash= true;
205205

206+
char*output_config_variable=NULL;
207+
206208
/* PIDs of special child processes; 0 when not running */
207209
staticpid_tStartupPID=0,
208210
BgWriterPID=0,
@@ -537,7 +539,7 @@ PostmasterMain(int argc, char *argv[])
537539
* tcop/postgres.c (the option sets should not conflict) and with the
538540
* common help() function in main/main.c.
539541
*/
540-
while ((opt=getopt(argc,argv,"A:B:bc:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:W:-:"))!=-1)
542+
while ((opt=getopt(argc,argv,"A:B:bc:C:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:W:-:"))!=-1)
541543
{
542544
switch (opt)
543545
{
@@ -554,6 +556,10 @@ PostmasterMain(int argc, char *argv[])
554556
IsBinaryUpgrade= true;
555557
break;
556558

559+
case'C':
560+
output_config_variable=optarg;
561+
break;
562+
557563
case'D':
558564
userDoption=optarg;
559565
break;
@@ -728,6 +734,13 @@ PostmasterMain(int argc, char *argv[])
728734
if (!SelectConfigFiles(userDoption,progname))
729735
ExitPostmaster(2);
730736

737+
if (output_config_variable!=NULL)
738+
{
739+
/* permission is handled because the user is reading inside the data dir */
740+
puts(GetConfigOption(output_config_variable, false, false));
741+
ExitPostmaster(0);
742+
}
743+
731744
/* Verify that DataDir looks reasonable */
732745
checkDataDir();
733746

‎src/backend/tcop/postgres.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3170,7 +3170,7 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
31703170
* postmaster/postmaster.c (the option sets should not conflict) and with
31713171
* the common help() function in main/main.c.
31723172
*/
3173-
while ((flag=getopt(argc,argv,"A:B:bc:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:v:W:-:"))!=-1)
3173+
while ((flag=getopt(argc,argv,"A:B:bc:C:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:v:W:-:"))!=-1)
31743174
{
31753175
switch (flag)
31763176
{
@@ -3187,6 +3187,10 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
31873187
IsBinaryUpgrade= true;
31883188
break;
31893189

3190+
case'C':
3191+
/* ignored for consistency with the postmaster */
3192+
break;
3193+
31903194
case'D':
31913195
if (secure)
31923196
userDoption=strdup(optarg);
@@ -3272,7 +3276,7 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
32723276
break;
32733277

32743278
case'T':
3275-
/* ignored for consistency with postmaster */
3279+
/* ignored for consistency withthepostmaster */
32763280
break;
32773281

32783282
case't':

‎src/bin/pg_ctl/pg_ctl.c

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ static ShutdownMode shutdown_mode = SMART_MODE;
8181
staticintsig=SIGTERM;/* default */
8282
staticCtlCommandctl_command=NO_COMMAND;
8383
staticchar*pg_data=NULL;
84+
staticchar*pg_config=NULL;
8485
staticchar*pgdata_opt=NULL;
8586
staticchar*post_opts=NULL;
8687
staticconstchar*progname;
@@ -131,6 +132,7 @@ static void do_status(void);
131132
staticvoiddo_promote(void);
132133
staticvoiddo_kill(pgpid_tpid);
133134
staticvoidprint_msg(constchar*msg);
135+
staticvoidadjust_data_dir(void);
134136

135137
#if defined(WIN32)|| defined(__CYGWIN__)
136138
staticboolpgwin32_IsInstalled(SC_HANDLE);
@@ -1265,10 +1267,10 @@ pgwin32_CommandLine(bool registration)
12651267
strcat(cmdLine,"\"");
12661268
}
12671269

1268-
if (pg_data)
1270+
if (pg_config)
12691271
{
12701272
strcat(cmdLine," -D \"");
1271-
strcat(cmdLine,pg_data);
1273+
strcat(cmdLine,pg_config);
12721274
strcat(cmdLine,"\"");
12731275
}
12741276

@@ -1886,6 +1888,59 @@ set_starttype(char *starttypeopt)
18861888
}
18871889
#endif
18881890

1891+
/*
1892+
* adjust_data_dir
1893+
*
1894+
* If a configuration-only directory was specified, find the real data dir.
1895+
*/
1896+
void
1897+
adjust_data_dir(void)
1898+
{
1899+
charcmd[MAXPGPATH],filename[MAXPGPATH],*my_exec_path;
1900+
FILE*fd;
1901+
1902+
/* If there is no postgresql.conf, it can't be a config-only dir */
1903+
snprintf(filename,sizeof(filename),"%s/postgresql.conf",pg_config);
1904+
if ((fd=fopen(filename,"r"))==NULL)
1905+
return;
1906+
fclose(fd);
1907+
1908+
/* If PG_VERSION exists, it can't be a config-only dir */
1909+
snprintf(filename,sizeof(filename),"%s/PG_VERSION",pg_config);
1910+
if ((fd=fopen(filename,"r"))!=NULL)
1911+
{
1912+
fclose(fd);
1913+
return;
1914+
}
1915+
1916+
/* Must be a configuration directory, so find the data directory */
1917+
1918+
/* we use a private my_exec_path to avoid interfering with later uses */
1919+
if (exec_path==NULL)
1920+
my_exec_path=find_other_exec_or_die(argv0,"postgres",PG_BACKEND_VERSIONSTR);
1921+
else
1922+
my_exec_path=xstrdup(exec_path);
1923+
1924+
snprintf(cmd,MAXPGPATH,SYSTEMQUOTE"\"%s\" %s%s -C data_directory"SYSTEMQUOTE,
1925+
my_exec_path,pgdata_opt ?pgdata_opt :"",post_opts ?
1926+
post_opts :"");
1927+
1928+
fd=popen(cmd,"r");
1929+
if (fd==NULL||fgets(filename,sizeof(filename),fd)==NULL)
1930+
{
1931+
write_stderr(_("%s: cannot find the data directory using %s\n"),progname,my_exec_path);
1932+
exit(1);
1933+
}
1934+
pclose(fd);
1935+
free(my_exec_path);
1936+
1937+
if (strlen(filename)>0&&filename[strlen(filename)-1]=='\n')
1938+
filename[strlen(filename)-1]='\0';
1939+
free(pg_data);
1940+
pg_data=xstrdup(filename);
1941+
canonicalize_path(pg_data);
1942+
}
1943+
18891944

18901945
int
18911946
main(intargc,char**argv)
@@ -2120,14 +2175,17 @@ main(int argc, char **argv)
21202175
}
21212176

21222177
/* Note we put any -D switch into the env var above */
2123-
pg_data=getenv("PGDATA");
2124-
if (pg_data)
2178+
pg_config=getenv("PGDATA");
2179+
if (pg_config)
21252180
{
2126-
pg_data=xstrdup(pg_data);
2127-
canonicalize_path(pg_data);
2181+
pg_config=xstrdup(pg_config);
2182+
canonicalize_path(pg_config);
2183+
pg_data=xstrdup(pg_config);
21282184
}
21292185

2130-
if (pg_data==NULL&&
2186+
adjust_data_dir();
2187+
2188+
if (pg_config==NULL&&
21312189
ctl_command!=KILL_COMMAND&&ctl_command!=UNREGISTER_COMMAND)
21322190
{
21332191
write_stderr(_("%s:nodatabasedirectoryspecifiedandenvironmentvariablePGDATAunset\n"),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp