Index: src/backend/commands/dbcommands.c =================================================================== --- src/backend/commands/dbcommands.c (HEAD) +++ src/backend/commands/dbcommands.c (working copy) @@ -258,7 +258,7 @@ /* * Check whether encoding matches server locale settings. We allow - * mismatch in two cases: + * mismatch in three cases: * * 1. ctype_encoding = SQL_ASCII, which means either that the locale * is C/POSIX which works with any encoding, or that we couldn't determine @@ -268,13 +268,21 @@ * This is risky but we have historically allowed it --- notably, the * regression tests require it. * + * 3. selected encoding is UTF-8, but only for Windows. + * We have special treatments of UTF-8 on Windows. We convert strings + * into wide characters and use wchar version of string functions. + * * Note: if you change this policy, fix initdb to match. */ ctype_encoding = pg_get_encoding_from_locale(NULL); if (!(ctype_encoding == encoding || ctype_encoding == PG_SQL_ASCII || - (encoding == PG_SQL_ASCII && superuser()))) + (encoding == PG_SQL_ASCII && superuser())) +#ifdef WIN32 + && encoding != PG_UTF8 +#endif + ) ereport(ERROR, (errmsg("encoding %s does not match server's locale %s", pg_encoding_to_char(encoding), Index: src/bin/initdb/initdb.c =================================================================== --- src/bin/initdb/initdb.c (HEAD) +++ src/bin/initdb/initdb.c (working copy) @@ -2810,6 +2810,9 @@ } else if (!PG_VALID_BE_ENCODING(ctype_enc)) { +#ifdef WIN32 + ctype_enc = PG_UTF8; +#else /* We recognized it, but it's not a legal server encoding */ fprintf(stderr, _("%s: locale %s requires unsupported encoding %s\n"), @@ -2819,13 +2822,12 @@ "Rerun %s with a different locale selection.\n"), pg_encoding_to_char(ctype_enc), progname); exit(1); +#endif } - 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)); - } + + 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 { @@ -2840,7 +2842,11 @@ /* We allow selection of SQL_ASCII --- see notes in createdb() */ if (!(ctype_enc == user_enc || ctype_enc == PG_SQL_ASCII || - user_enc == PG_SQL_ASCII)) + user_enc == PG_SQL_ASCII) +#ifdef WIN32 + && user_enc != PG_UTF8 +#endif + ) { fprintf(stderr, _("%s: encoding mismatch\n"), progname); fprintf(stderr,