initdb: Remove obsolete locale handling
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 14 Aug 2019 04:50:47 +0000 (06:50 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 14 Aug 2019 04:51:13 +0000 (06:51 +0200)
The method of passing LC_COLLATE and LC_CTYPE to the backend during
initdb is obsolete as of 61d967498802ab86d8897cb3c61740d7e9d712f6.
This can all be removed.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/eeaf2f99-a1a6-8aca-3f43-9ab0b2fb112a%402ndquadrant.com

src/backend/main/main.c
src/bin/initdb/initdb.c

index 7b18f8c75824ff83d1246e5115dc3f19cb09721c..a9edbfd4a44d19c7794d01a26ea17885fd28aa98 100644 (file)
@@ -99,42 +99,24 @@ main(int argc, char *argv[])
    MemoryContextInit();
 
    /*
-    * Set up locale information from environment.  Note that LC_CTYPE and
-    * LC_COLLATE will be overridden later from pg_control if we are in an
-    * already-initialized database.  We set them here so that they will be
-    * available to fill pg_control during initdb.  LC_MESSAGES will get set
-    * later during GUC option processing, but we set it here to allow startup
-    * error messages to be localized.
+    * Set up locale information
     */
-
    set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("postgres"));
 
-#ifdef WIN32
-
    /*
-    * Windows uses codepages rather than the environment, so we work around
-    * that by querying the environment explicitly first for LC_COLLATE and
-    * LC_CTYPE. We have to do this because initdb passes those values in the
-    * environment. If there is nothing there we fall back on the codepage.
+    * In the postmaster, absorb the environment values for LC_COLLATE and
+    * LC_CTYPE.  Individual backends will change these later to settings
+    * taken from pg_database, but the postmaster cannot do that.  If we leave
+    * these set to "C" then message localization might not work well in the
+    * postmaster.
     */
-   {
-       char       *env_locale;
-
-       if ((env_locale = getenv("LC_COLLATE")) != NULL)
-           init_locale("LC_COLLATE", LC_COLLATE, env_locale);
-       else
-           init_locale("LC_COLLATE", LC_COLLATE, "");
-
-       if ((env_locale = getenv("LC_CTYPE")) != NULL)
-           init_locale("LC_CTYPE", LC_CTYPE, env_locale);
-       else
-           init_locale("LC_CTYPE", LC_CTYPE, "");
-   }
-#else
    init_locale("LC_COLLATE", LC_COLLATE, "");
    init_locale("LC_CTYPE", LC_CTYPE, "");
-#endif
 
+   /*
+    * LC_MESSAGES will get set later during GUC option processing, but we set
+    * it here to allow startup error messages to be localized.
+    */
 #ifdef LC_MESSAGES
    init_locale("LC_MESSAGES", LC_MESSAGES, "");
 #endif
index 551d379d8591819c512b67692a263129998d6265..88a261d9bda104e682552c8c38978510c8717867 100644 (file)
@@ -1417,20 +1417,6 @@ bootstrap_template1(void)
    bki_lines = replace_token(bki_lines, "LC_CTYPE",
                              escape_quotes_bki(lc_ctype));
 
-   /*
-    * Pass correct LC_xxx environment to bootstrap.
-    *
-    * The shell script arranged to restore the LC settings afterwards, but
-    * there doesn't seem to be any compelling reason to do that.
-    */
-   snprintf(cmd, sizeof(cmd), "LC_COLLATE=%s", lc_collate);
-   putenv(pg_strdup(cmd));
-
-   snprintf(cmd, sizeof(cmd), "LC_CTYPE=%s", lc_ctype);
-   putenv(pg_strdup(cmd));
-
-   unsetenv("LC_ALL");
-
    /* Also ensure backend isn't confused by this environment var: */
    unsetenv("PGCLIENTENCODING");