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

Commitc0e4520

Browse files
committed
Add option to pg_ctl to choose event source for logging
pg_ctl will log to the Windows event log when it is running as a service,which is the primary way of running PostgreSQL on Windows. This optionmakes it possible to specify which event source to use for this, in orderto separate different instances. The server logging itself is still controlledby the regular logging parameters, including a separate setting for the eventsource. The parameter to pg_ctl only controlls the logging from pg_ctl itself.MauMau, review in many iterations by Amit Kapila and me.
1 parentaa68872 commitc0e4520

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,22 @@ PostgreSQL documentation
419419
<title>Options for Windows</title>
420420

421421
<variablelist>
422+
<varlistentry>
423+
<term><option>-e <replaceable class="parameter">source</replaceable></option></term>
424+
<listitem>
425+
<para>
426+
Name of the event source for <application>pg_ctl</application> to use
427+
for logging to the event log when running as a Windows service. The
428+
default is <literal>PostgreSQL</literal>. Note that this only controls
429+
the logging from <application>pg_ctl</application> itself - once
430+
started, the server will use the event source specified
431+
by <xref linkend="guc-event-source">. Should the server fail during
432+
early startup, it may also log using the default event
433+
source <literal>PostgreSQL</literal>.
434+
</para>
435+
</listitem>
436+
</varlistentry>
437+
422438
<varlistentry>
423439
<term><option>-N <replaceable class="parameter">servicename</replaceable></option></term>
424440
<listitem>

‎src/backend/utils/error/elog.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,8 @@ write_eventlog(int level, const char *line, int len)
19891989

19901990
if (evtHandle==INVALID_HANDLE_VALUE)
19911991
{
1992-
evtHandle=RegisterEventSource(NULL,event_source ?event_source :"PostgreSQL");
1992+
evtHandle=RegisterEventSource(NULL,
1993+
event_source ?event_source :DEFAULT_EVENT_SOURCE);
19931994
if (evtHandle==NULL)
19941995
{
19951996
evtHandle=INVALID_HANDLE_VALUE;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3019,7 +3019,7 @@ static struct config_string ConfigureNamesString[] =
30193019
NULL
30203020
},
30213021
&event_source,
3022-
"PostgreSQL",
3022+
DEFAULT_EVENT_SOURCE,
30233023
NULL,NULL,NULL
30243024
},
30253025

‎src/bin/pg_ctl/pg_ctl.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ static char *post_opts = NULL;
8989
staticconstchar*progname;
9090
staticchar*log_file=NULL;
9191
staticchar*exec_path=NULL;
92+
staticchar*event_source=NULL;
9293
staticchar*register_servicename="PostgreSQL";/* FIXME: + version ID? */
9394
staticchar*register_username=NULL;
9495
staticchar*register_password=NULL;
@@ -178,7 +179,8 @@ write_eventlog(int level, const char *line)
178179

179180
if (evtHandle==INVALID_HANDLE_VALUE)
180181
{
181-
evtHandle=RegisterEventSource(NULL,"PostgreSQL");
182+
evtHandle=RegisterEventSource(NULL,
183+
event_source ?event_source :DEFAULT_EVENT_SOURCE);
182184
if (evtHandle==NULL)
183185
{
184186
evtHandle=INVALID_HANDLE_VALUE;
@@ -1406,6 +1408,9 @@ pgwin32_CommandLine(bool registration)
14061408
free(dataDir);
14071409
}
14081410

1411+
if (registration&&event_source!=NULL)
1412+
appendPQExpBuffer(cmdLine," -e \"%s\"",event_source);
1413+
14091414
if (registration&&do_wait)
14101415
appendPQExpBuffer(cmdLine," -w");
14111416

@@ -1878,6 +1883,10 @@ do_help(void)
18781883
printf(_("\nCommon options:\n"));
18791884
printf(_(" -D, --pgdata=DATADIR location of the database storage area\n"));
18801885
printf(_(" -s, --silent only print errors, no informational messages\n"));
1886+
#if defined(WIN32)|| defined(__CYGWIN__)
1887+
printf(_(" -e SOURCE event source to use for logging when running\n"
1888+
" as a service\n"));
1889+
#endif
18811890
printf(_(" -t, --timeout=SECS seconds to wait when using -w option\n"));
18821891
printf(_(" -V, --version output version information, then exit\n"));
18831892
printf(_(" -w wait until operation completes\n"));
@@ -2140,7 +2149,7 @@ main(int argc, char **argv)
21402149
/* process command-line options */
21412150
while (optind<argc)
21422151
{
2143-
while ((c=getopt_long(argc,argv,"cD:l:m:N:o:p:P:sS:t:U:wW",long_options,&option_index))!=-1)
2152+
while ((c=getopt_long(argc,argv,"cD:e:l:m:N:o:p:P:sS:t:U:wW",long_options,&option_index))!=-1)
21442153
{
21452154
switch (c)
21462155
{
@@ -2168,6 +2177,9 @@ main(int argc, char **argv)
21682177
case'm':
21692178
set_mode(optarg);
21702179
break;
2180+
case'e':
2181+
event_source=pg_strdup(optarg);
2182+
break;
21712183
case'N':
21722184
register_servicename=pg_strdup(optarg);
21732185
break;

‎src/bin/pgevent/pgevent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ HANDLEg_module = NULL;/* hModule of DLL */
2626
* The maximum length of a registry key is 255 characters.
2727
* http://msdn.microsoft.com/en-us/library/ms724872(v=vs.85).aspx
2828
*/
29-
charevent_source[256]="PostgreSQL";
29+
charevent_source[256]=DEFAULT_EVENT_SOURCE;
3030

3131
/* Prototypes */
3232
HRESULTDllInstall(BOOLbInstall,LPCWSTRpszCmdLine);

‎src/include/pg_config_manual.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@
154154
*/
155155
#defineDEFAULT_PGSOCKET_DIR "/tmp"
156156

157+
/*
158+
* This is the default event source for Windows event log.
159+
*/
160+
#defineDEFAULT_EVENT_SOURCE "PostgreSQL"
161+
157162
/*
158163
* The random() function is expected to yield values between 0 and
159164
* MAX_RANDOM_VALUE. Currently, all known implementations yield

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp