diff -rpcd a/doc/src/sgml/ref/pg_ctl-ref.sgml b/doc/src/sgml/ref/pg_ctl-ref.sgml *** a/doc/src/sgml/ref/pg_ctl-ref.sgml 2014-03-21 05:17:03.000000000 +0900 --- b/doc/src/sgml/ref/pg_ctl-ref.sgml 2014-04-12 16:29:38.580000000 +0900 *************** PostgreSQL documentation *** 115,120 **** --- 115,121 ---- + event-source seconds *************** PostgreSQL documentation *** 420,425 **** --- 421,436 ---- + + + + Name of the event source for pg_ctl to use for event log. The + default is PostgreSQL. + + + + + diff -rpcd a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c *** a/src/backend/utils/error/elog.c 2014-03-21 05:17:03.000000000 +0900 --- b/src/backend/utils/error/elog.c 2014-04-12 02:06:05.638000000 +0900 *************** write_eventlog(int level, const char *li *** 1989,1995 **** if (evtHandle == INVALID_HANDLE_VALUE) { ! evtHandle = RegisterEventSource(NULL, event_source ? event_source : "PostgreSQL"); if (evtHandle == NULL) { evtHandle = INVALID_HANDLE_VALUE; --- 1989,1996 ---- if (evtHandle == INVALID_HANDLE_VALUE) { ! evtHandle = RegisterEventSource(NULL, ! event_source ? event_source : DEFAULT_EVENT_SOURCE); if (evtHandle == NULL) { evtHandle = INVALID_HANDLE_VALUE; diff -rpcd a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c *** a/src/backend/utils/misc/guc.c 2014-03-21 05:17:03.000000000 +0900 --- b/src/backend/utils/misc/guc.c 2014-04-12 02:06:05.688000000 +0900 *************** static struct config_string ConfigureNam *** 3017,3023 **** NULL }, &event_source, ! "PostgreSQL", NULL, NULL, NULL }, --- 3017,3023 ---- NULL }, &event_source, ! DEFAULT_EVENT_SOURCE, NULL, NULL, NULL }, diff -rpcd a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c *** a/src/bin/pg_ctl/pg_ctl.c 2014-03-21 05:17:03.000000000 +0900 --- b/src/bin/pg_ctl/pg_ctl.c 2014-04-12 16:29:38.441000000 +0900 *************** static char recovery_file[MAXPGPATH]; *** 104,109 **** --- 104,110 ---- static char promote_file[MAXPGPATH]; #if defined(WIN32) || defined(__CYGWIN__) + static char *event_source = NULL; static DWORD pgctl_start_type = SERVICE_AUTO_START; static SERVICE_STATUS status; static SERVICE_STATUS_HANDLE hStatus = (SERVICE_STATUS_HANDLE) 0; *************** static void do_status(void); *** 133,138 **** --- 134,140 ---- static void do_promote(void); static void do_kill(pgpid_t pid); static void print_msg(const char *msg); + static void get_config_value(const char *name, char *buf, int buf_size); static void adjust_data_dir(void); #if defined(WIN32) || defined(__CYGWIN__) *************** write_eventlog(int level, const char *li *** 178,184 **** if (evtHandle == INVALID_HANDLE_VALUE) { ! evtHandle = RegisterEventSource(NULL, "PostgreSQL"); if (evtHandle == NULL) { evtHandle = INVALID_HANDLE_VALUE; --- 180,187 ---- if (evtHandle == INVALID_HANDLE_VALUE) { ! evtHandle = RegisterEventSource(NULL, ! event_source ? event_source : DEFAULT_EVENT_SOURCE); if (evtHandle == NULL) { evtHandle = INVALID_HANDLE_VALUE; *************** pgwin32_CommandLine(bool registration) *** 1389,1394 **** --- 1392,1400 ---- if (pg_config) appendPQExpBuffer(cmdLine, " -D \"%s\"", pg_config); + if (registration && event_source != NULL) + appendPQExpBuffer(cmdLine, " -e \"%s\"", event_source); + if (registration && do_wait) appendPQExpBuffer(cmdLine, " -w"); *************** do_help(void) *** 1854,1860 **** printf(_(" %s kill SIGNALNAME PID\n"), progname); #if defined(WIN32) || defined(__CYGWIN__) printf(_(" %s register [-N SERVICENAME] [-U USERNAME] [-P PASSWORD] [-D DATADIR]\n" ! " [-S START-TYPE] [-w] [-t SECS] [-o \"OPTIONS\"]\n"), progname); printf(_(" %s unregister [-N SERVICENAME]\n"), progname); #endif --- 1860,1866 ---- printf(_(" %s kill SIGNALNAME PID\n"), progname); #if defined(WIN32) || defined(__CYGWIN__) printf(_(" %s register [-N SERVICENAME] [-U USERNAME] [-P PASSWORD] [-D DATADIR]\n" ! " [-S START-TYPE] [-e event-source] [-w] [-t SECS] [-o \"OPTIONS\"]\n"), progname); printf(_(" %s unregister [-N SERVICENAME]\n"), progname); #endif *************** do_help(void) *** 1893,1898 **** --- 1899,1905 ---- #if defined(WIN32) || defined(__CYGWIN__) printf(_("\nOptions for register and unregister:\n")); printf(_(" -N SERVICENAME service name with which to register PostgreSQL server\n")); + printf(_(" -e event-source event source for pg_ctl to use for event log\n")); printf(_(" -P PASSWORD password of account to register PostgreSQL server\n")); printf(_(" -U USERNAME user name of account to register PostgreSQL server\n")); printf(_(" -S START-TYPE service start type to register PostgreSQL server\n")); *************** main(int argc, char **argv) *** 2121,2127 **** /* process command-line options */ while (optind < argc) { ! while ((c = getopt_long(argc, argv, "cD:l:m:N:o:p:P:sS:t:U:wW", long_options, &option_index)) != -1) { switch (c) { --- 2128,2134 ---- /* process command-line options */ while (optind < argc) { ! while ((c = getopt_long(argc, argv, "cD:e:l:m:N:o:p:P:sS:t:U:wW", long_options, &option_index)) != -1) { switch (c) { *************** main(int argc, char **argv) *** 2149,2154 **** --- 2156,2164 ---- case 'm': set_mode(optarg); break; + case 'e': + event_source = pg_strdup(optarg); + break; case 'N': register_servicename = pg_strdup(optarg); break; diff -rpcd a/src/bin/pgevent/pgevent.c b/src/bin/pgevent/pgevent.c *** a/src/bin/pgevent/pgevent.c 2014-03-21 05:17:03.000000000 +0900 --- b/src/bin/pgevent/pgevent.c 2014-04-12 02:06:05.741000000 +0900 *************** *** 12,17 **** --- 12,19 ---- */ + #include "postgres_fe.h" + #include #include #include *************** HANDLE g_module = NULL; /* hModule of D *** 26,32 **** * The maximum length of a registry key is 255 characters. * http://msdn.microsoft.com/en-us/library/ms724872(v=vs.85).aspx */ ! char event_source[256] = "PostgreSQL"; /* Prototypes */ HRESULT DllInstall(BOOL bInstall, LPCWSTR pszCmdLine); --- 28,34 ---- * The maximum length of a registry key is 255 characters. * http://msdn.microsoft.com/en-us/library/ms724872(v=vs.85).aspx */ ! char event_source[256] = DEFAULT_EVENT_SOURCE; /* Prototypes */ HRESULT DllInstall(BOOL bInstall, LPCWSTR pszCmdLine); *************** DllInstall(BOOL bInstall, *** 54,64 **** * * This strange behavior forces us to specify -n (i.e. "regsvr32 /n /i"). * Without -n, DllRegisterServer called before DllInstall would mistakenly ! * overwrite the default "PostgreSQL" event source registration. */ if (bInstall) ! DllRegisterServer(); ! return S_OK; } /* --- 56,67 ---- * * This strange behavior forces us to specify -n (i.e. "regsvr32 /n /i"). * Without -n, DllRegisterServer called before DllInstall would mistakenly ! * overwrite the default event source registration. */ if (bInstall) ! return DllRegisterServer(); ! else ! return S_OK; } /* *************** DllRegisterServer(void) *** 72,77 **** --- 75,81 ---- DWORD data; char buffer[_MAX_PATH]; char key_name[400]; + char message[1024]; /* Set the name of DLL full path name. */ if (!GetModuleFileName((HMODULE) g_module, buffer, sizeof(buffer))) *************** DllRegisterServer(void) *** 87,97 **** _snprintf(key_name, sizeof(key_name), "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s", event_source); ! if (RegCreateKey(HKEY_LOCAL_MACHINE, key_name, &key)) { MessageBox(NULL, "Could not create the registry key.", "PostgreSQL error", MB_OK | MB_ICONSTOP); return SELFREG_E_TYPELIB; } /* Add the name to the EventMessageFile subkey. */ if (RegSetValueEx(key, --- 91,110 ---- _snprintf(key_name, sizeof(key_name), "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s", event_source); ! if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, key_name, 0, NULL, 0, KEY_WRITE, ! NULL, &key, &data)) { MessageBox(NULL, "Could not create the registry key.", "PostgreSQL error", MB_OK | MB_ICONSTOP); return SELFREG_E_TYPELIB; } + else if (data == REG_OPENED_EXISTING_KEY) + { + RegCloseKey(key); + _snprintf(message, sizeof(message), + "Event source \"%s\" is already registered.", event_source); + MessageBox(NULL, message, "PostgreSQL error", MB_OK | MB_ICONSTOP); + return SELFREG_E_TYPELIB; + } /* Add the name to the EventMessageFile subkey. */ if (RegSetValueEx(key, diff -rpcd a/src/include/pg_config_manual.h b/src/include/pg_config_manual.h *** a/src/include/pg_config_manual.h 2014-03-21 05:17:03.000000000 +0900 --- b/src/include/pg_config_manual.h 2014-04-12 02:06:05.764000000 +0900 *************** *** 155,160 **** --- 155,165 ---- #define DEFAULT_PGSOCKET_DIR "/tmp" /* + * This is the default event source for Windows event log. + */ + #define DEFAULT_EVENT_SOURCE "PostgreSQL" + + /* * The random() function is expected to yield values between 0 and * MAX_RANDOM_VALUE. Currently, all known implementations yield * 0..2^31-1, so we just hardwire this constant. We could do a