*** a/src/backend/utils/mb/mbutils.c
--- b/src/backend/utils/mb/mbutils.c
***************
*** 890,896 **** cliplen(const char *str, int len, int limit)
  	return l;
  }
  
! #if defined(ENABLE_NLS) && defined(WIN32)
  static const struct codeset_map {
  	int	encoding;
  	const char *codeset;
--- 890,896 ----
  	return l;
  }
  
! #if defined(ENABLE_NLS)
  static const struct codeset_map {
  	int	encoding;
  	const char *codeset;
***************
*** 929,935 **** static const struct codeset_map {
  	{PG_EUC_TW, "EUC-TW"},
  	{PG_EUC_JIS_2004, "EUC-JP"}
  };
! #endif /* WIN32 */
  
  void
  SetDatabaseEncoding(int encoding)
--- 929,935 ----
  	{PG_EUC_TW, "EUC-TW"},
  	{PG_EUC_JIS_2004, "EUC-JP"}
  };
! #endif /* ENABLE_NLS */
  
  void
  SetDatabaseEncoding(int encoding)
***************
*** 946,960 **** SetDatabaseEncoding(int encoding)
  }
  
  /*
!  * On Windows, we need to explicitly bind gettext to the correct
!  * encoding, because gettext() tends to get confused.
   */
  void
  pg_bind_textdomain_codeset(const char *domainname, int encoding)
  {
! #if defined(ENABLE_NLS) && defined(WIN32)
  	int     i;
  
  	for (i = 0; i < lengthof(codeset_map_array); i++)
  	{
  		if (codeset_map_array[i].encoding == encoding)
--- 946,975 ----
  }
  
  /*
!  * Bind gettext to the correct encoding.
   */
  void
  pg_bind_textdomain_codeset(const char *domainname, int encoding)
  {
! #if defined(ENABLE_NLS)
  	int     i;
  
+ 	/*
+ 	 * gettext() uses the encoding specified by LC_CTYPE by default,
+ 	 * so if that matches the database encoding, we don't need to do
+ 	 * anything. This is not for performance, but because if
+ 	 * bind_textdomain_codeset() doesn't recognize the codeset name we
+ 	 * pass it, it will fall back to English and we don't want that to 
+ 	 * happen unnecessarily.
+ 	 *
+ 	 * On Windows, though, gettext() tends to get confused so we always
+ 	 * bind it.
+ 	 */
+ #ifndef WIN32
+ 	if (pg_get_encoding_from_locale(NULL) == encoding)
+ 		return;
+ #endif
+ 
  	for (i = 0; i < lengthof(codeset_map_array); i++)
  	{
  		if (codeset_map_array[i].encoding == encoding)
