diff -rpcd a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
*** a/doc/src/sgml/config.sgml	2014-01-05 05:17:14.000000000 +0900
--- b/doc/src/sgml/config.sgml	2014-01-22 15:09:38.000000000 +0900
*************** local0.*    /var/log/postgresql
*** 3659,3665 ****
          When logging to <application>event log</> is enabled, this parameter
          determines the program name used to identify
          <productname>PostgreSQL</productname> messages in
!         the log. The default is <literal>PostgreSQL</literal>.
          This parameter can only be set in the <filename>postgresql.conf</>
          file or on the server command line.
         </para>
--- 3659,3665 ----
          When logging to <application>event log</> is enabled, this parameter
          determines the program name used to identify
          <productname>PostgreSQL</productname> messages in
!         the log. The default is <literal>PostgreSQL &majorversion;</literal>.
          This parameter can only be set in the <filename>postgresql.conf</>
          file or on the server command line.
         </para>
diff -rpcd a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml
*** a/doc/src/sgml/runtime.sgml	2014-01-05 05:17:14.000000000 +0900
--- b/doc/src/sgml/runtime.sgml	2014-01-22 15:09:38.000000000 +0900
*************** ssh -L 63333:db.foo.com:5432 joe@shell.f
*** 2262,2268 ****
  <userinput>regsvr32 <replaceable>pgsql_library_directory</>/pgevent.dll</>
  </screen>
     This creates registry entries used by the event viewer, under the default
!    event source named <literal>PostgreSQL</literal>.
    </para>
  
    <para>
--- 2262,2268 ----
  <userinput>regsvr32 <replaceable>pgsql_library_directory</>/pgevent.dll</>
  </screen>
     This creates registry entries used by the event viewer, under the default
!    event source named <literal>PostgreSQL &majorversion;</literal>.
    </para>
  
    <para>
diff -rpcd a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
*** a/src/backend/utils/error/elog.c	2014-01-05 05:17:10.000000000 +0900
--- b/src/backend/utils/error/elog.c	2014-01-22 15:09:38.000000000 +0900
*************** write_eventlog(int level, const char *li
*** 1934,1940 ****
  
  	if (evtHandle == INVALID_HANDLE_VALUE)
  	{
! 		evtHandle = RegisterEventSource(NULL, event_source ? event_source : "PostgreSQL");
  		if (evtHandle == NULL)
  		{
  			evtHandle = INVALID_HANDLE_VALUE;
--- 1934,1941 ----
  
  	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-01-05 05:17:09.000000000 +0900
--- b/src/backend/utils/misc/guc.c	2014-01-22 15:09:38.000000000 +0900
*************** static struct config_string ConfigureNam
*** 2964,2970 ****
  			NULL
  		},
  		&event_source,
! 		"PostgreSQL",
  		NULL, NULL, NULL
  	},
  
--- 2964,2970 ----
  			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-01-05 05:17:12.000000000 +0900
--- b/src/bin/pg_ctl/pg_ctl.c	2014-01-22 15:09:38.000000000 +0900
*************** static char recovery_file[MAXPGPATH];
*** 103,108 ****
--- 103,109 ----
  static char promote_file[MAXPGPATH];
  
  #if defined(WIN32) || defined(__CYGWIN__)
+ static char event_source[256];
  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);
*** 132,137 ****
--- 133,139 ----
  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
*** 170,176 ****
  
  	if (evtHandle == INVALID_HANDLE_VALUE)
  	{
! 		evtHandle = RegisterEventSource(NULL, "PostgreSQL");
  		if (evtHandle == NULL)
  		{
  			evtHandle = INVALID_HANDLE_VALUE;
--- 172,179 ----
  
  	if (evtHandle == INVALID_HANDLE_VALUE)
  	{
! 		evtHandle = RegisterEventSource(NULL,
! 						*event_source ? event_source : DEFAULT_EVENT_SOURCE);
  		if (evtHandle == NULL)
  		{
  			evtHandle = INVALID_HANDLE_VALUE;
*************** set_starttype(char *starttypeopt)
*** 1902,1907 ****
--- 1905,1942 ----
  }
  #endif
  
+ static void
+ get_config_value(const char *name, char *buf, int buf_size)
+ {
+ 	char		cmd[MAXPGPATH],
+ 			   *my_exec_path;
+ 	FILE	   *fd;
+ 
+ 	/* we use a private my_exec_path to avoid interfering with later uses */
+ 	if (exec_path == NULL)
+ 		my_exec_path = find_other_exec_or_die(argv0, "postgres", PG_BACKEND_VERSIONSTR);
+ 	else
+ 		my_exec_path = pg_strdup(exec_path);
+ 
+ 	snprintf(cmd, MAXPGPATH, SYSTEMQUOTE "\"%s\" %s%s -C %s" SYSTEMQUOTE,
+ 			 my_exec_path, pgdata_opt ? pgdata_opt : "", post_opts ?
+ 			 post_opts : "", name);
+ 
+ 	fd = popen(cmd, "r");
+ 	if (fd == NULL || fgets(buf, buf_size, fd) == NULL)
+ 	{
+ 		write_stderr(_("%s: could not execute command \"%s\": %s\n"),
+ 					 progname, cmd, strerror(errno));
+ 		exit(1);
+ 	}
+ 	pclose(fd);
+ 	free(my_exec_path);
+ 
+ 	/* Remove trailing newline */
+ 	if (strchr(buf, '\n') != NULL)
+ 		*strchr(buf, '\n') = '\0';
+ }
+ 
  /*
   * adjust_data_dir
   *
*************** set_starttype(char *starttypeopt)
*** 1910,1918 ****
  static void
  adjust_data_dir(void)
  {
! 	char		cmd[MAXPGPATH],
! 				filename[MAXPGPATH],
! 			   *my_exec_path;
  	FILE	   *fd;
  
  	/* do nothing if we're working without knowledge of data dir */
--- 1945,1951 ----
  static void
  adjust_data_dir(void)
  {
! 	char		filename[MAXPGPATH];
  	FILE	   *fd;
  
  	/* do nothing if we're working without knowledge of data dir */
*************** adjust_data_dir(void)
*** 1934,1962 ****
  	}
  
  	/* Must be a configuration directory, so find the data directory */
! 
! 	/* we use a private my_exec_path to avoid interfering with later uses */
! 	if (exec_path == NULL)
! 		my_exec_path = find_other_exec_or_die(argv0, "postgres", PG_BACKEND_VERSIONSTR);
! 	else
! 		my_exec_path = pg_strdup(exec_path);
! 
! 	snprintf(cmd, MAXPGPATH, SYSTEMQUOTE "\"%s\" %s%s -C data_directory" SYSTEMQUOTE,
! 			 my_exec_path, pgdata_opt ? pgdata_opt : "", post_opts ?
! 			 post_opts : "");
! 
! 	fd = popen(cmd, "r");
! 	if (fd == NULL || fgets(filename, sizeof(filename), fd) == NULL)
! 	{
! 		write_stderr(_("%s: could not determine the data directory using command \"%s\"\n"), progname, cmd);
! 		exit(1);
! 	}
! 	pclose(fd);
! 	free(my_exec_path);
! 
! 	/* Remove trailing newline */
! 	if (strchr(filename, '\n') != NULL)
! 		*strchr(filename, '\n') = '\0';
  
  	free(pg_data);
  	pg_data = pg_strdup(filename);
--- 1967,1973 ----
  	}
  
  	/* Must be a configuration directory, so find the data directory */
! 	get_config_value("data_directory", filename, sizeof(filename));
  
  	free(pg_data);
  	pg_data = pg_strdup(filename);
*************** main(int argc, char **argv)
*** 2194,2199 ****
--- 2205,2215 ----
  	/* -D might point at config-only directory; if so find the real PGDATA */
  	adjust_data_dir();
  
+ #if defined(WIN32) || defined(__CYGWIN__)
+ 	/* Get event source from postgresql.conf for eventlog output */
+ 	get_config_value("event_source", event_source, sizeof(event_source));
+ #endif
+ 
  	/* Complain if -D needed and not provided */
  	if (pg_config == NULL &&
  		ctl_command != KILL_COMMAND && ctl_command != UNREGISTER_COMMAND)
diff -rpcd a/src/bin/pgevent/pgevent.c b/src/bin/pgevent/pgevent.c
*** a/src/bin/pgevent/pgevent.c	2014-01-05 05:17:12.000000000 +0900
--- b/src/bin/pgevent/pgevent.c	2014-01-22 15:10:21.000000000 +0900
***************
*** 12,17 ****
--- 12,19 ----
   */
  
  
+ #include "postgres_fe.h"
+ 
  #include <windows.h>
  #include <olectl.h>
  #include <string.h>
***************
*** 20,32 ****
  
  /* Global variables */
  HANDLE		g_module = NULL;	/* hModule of DLL */
  
  /*
   * The event source is stored as a registry key.
   * 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);
--- 22,35 ----
  
  /* Global variables */
  HANDLE		g_module = NULL;	/* hModule of DLL */
+ char		message[1024];
  
  /*
   * The event source is stored as a registry key.
   * 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,60 ****
  	 *
  	 * 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();
--- 57,63 ----
  	 *
  	 * 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)
  		DllRegisterServer();
*************** DllRegisterServer(void)
*** 87,92 ****
--- 90,103 ----
  	_snprintf(key_name, sizeof(key_name),
  			"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s",
  			  event_source);
+ 	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, key_name, 0, KEY_READ, &key) == ERROR_SUCCESS)
+ 	{
+ 		_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;
+ 	}
+ 	RegCloseKey(key);
  	if (RegCreateKey(HKEY_LOCAL_MACHINE, key_name, &key))
  	{
  		MessageBox(NULL, "Could not create the registry key.", "PostgreSQL error", MB_OK | MB_ICONSTOP);
diff -rpcd a/src/include/pg_config_manual.h b/src/include/pg_config_manual.h
*** a/src/include/pg_config_manual.h	2014-01-05 05:17:04.000000000 +0900
--- b/src/include/pg_config_manual.h	2014-01-22 15:09:38.000000000 +0900
***************
*** 147,152 ****
--- 147,157 ----
  #define DEFAULT_PGSOCKET_DIR  "/tmp"
  
  /*
+  * This is the default event source for Windows event log.
+  */
+ #define DEFAULT_EVENT_SOURCE  "PostgreSQL " PG_MAJORVERSION
+ 
+ /*
   * 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
