Index: src/bin/initdb/initdb.c =================================================================== --- src/bin/initdb/initdb.c (HEAD) +++ src/bin/initdb/initdb.c (working copy) @@ -2413,6 +2413,7 @@ * environment */ char bin_dir[MAXPGPATH]; char *pg_data_native; + bool is_default_locale; #ifdef WIN32 char *restrict_env; @@ -2760,6 +2761,15 @@ check_input(features_file); check_input(system_views_file); + is_default_locale = + strlen(locale) == 0 && + strlen(lc_collate) == 0 && + strlen(lc_ctype) == 0 && + strlen(lc_messages) == 0 && + strlen(lc_monetary) == 0 && + strlen(lc_numeric) == 0 && + strlen(lc_time) == 0; + setlocales(); printf(_("The files belonging to this database system will be owned " @@ -2767,29 +2777,6 @@ "This user must also own the server process.\n\n"), effective_user); - if (strcmp(lc_ctype, lc_collate) == 0 && - strcmp(lc_ctype, lc_time) == 0 && - strcmp(lc_ctype, lc_numeric) == 0 && - strcmp(lc_ctype, lc_monetary) == 0 && - strcmp(lc_ctype, lc_messages) == 0) - printf(_("The database cluster will be initialized with locale %s.\n"), lc_ctype); - else - { - printf(_("The database cluster will be initialized with locales\n" - " COLLATE: %s\n" - " CTYPE: %s\n" - " MESSAGES: %s\n" - " MONETARY: %s\n" - " NUMERIC: %s\n" - " TIME: %s\n"), - lc_collate, - lc_ctype, - lc_messages, - lc_monetary, - lc_numeric, - lc_time); - } - if (strlen(encoding) == 0) { int ctype_enc; @@ -2810,6 +2797,19 @@ } else if (!PG_VALID_BE_ENCODING(ctype_enc)) { + if (is_default_locale) + { + /* + * We don't support the default locale encoding. + * Use UTF-8 and C locale instead. + */ + ctype_enc = PG_UTF8; + locale = lc_collate = lc_ctype = lc_monetary = + lc_numeric = lc_time = lc_messages = "C"; + setlocales(); + } + else + { /* We recognized it, but it's not a legal server encoding */ fprintf(stderr, _("%s: locale %s requires unsupported encoding %s\n"), @@ -2819,13 +2819,11 @@ "Rerun %s with a different locale selection.\n"), pg_encoding_to_char(ctype_enc), progname); exit(1); + } } - else - { encodingid = encodingid_to_string(ctype_enc); printf(_("The default database encoding has accordingly been set to %s.\n"), pg_encoding_to_char(ctype_enc)); - } } else { @@ -2856,6 +2854,29 @@ } } + if (strcmp(lc_ctype, lc_collate) == 0 && + strcmp(lc_ctype, lc_time) == 0 && + strcmp(lc_ctype, lc_numeric) == 0 && + strcmp(lc_ctype, lc_monetary) == 0 && + strcmp(lc_ctype, lc_messages) == 0) + printf(_("The database cluster will be initialized with locale %s.\n"), lc_ctype); + else + { + printf(_("The database cluster will be initialized with locales\n" + " COLLATE: %s\n" + " CTYPE: %s\n" + " MESSAGES: %s\n" + " MONETARY: %s\n" + " NUMERIC: %s\n" + " TIME: %s\n"), + lc_collate, + lc_ctype, + lc_messages, + lc_monetary, + lc_numeric, + lc_time); + } + if (strlen(default_text_search_config) == 0) { default_text_search_config = find_matching_ts_config(lc_ctype);