aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/dbcommands.c
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2008-09-23 10:58:03 +0000
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2008-09-23 10:58:03 +0000
commitc2d4526495a149d215a9c2a6e0f7c165e78e6b66 (patch)
tree0eb89fd07cddac5814d3eae3e0d0168ca43e45cc /src/backend/commands/dbcommands.c
parent61d967498802ab86d8897cb3c61740d7e9d712f6 (diff)
downloadpostgresql-c2d4526495a149d215a9c2a6e0f7c165e78e6b66.tar.gz
postgresql-c2d4526495a149d215a9c2a6e0f7c165e78e6b66.zip
Tighten the check in initdb and CREATE DATABASE that the chosen encoding
matches the encoding of the locale. LC_COLLATE is now checked in addition to LC_CTYPE.
Diffstat (limited to 'src/backend/commands/dbcommands.c')
-rw-r--r--src/backend/commands/dbcommands.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index ce3754f5928..29dc0733a73 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.211 2008/09/23 09:20:35 heikki Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.212 2008/09/23 10:58:03 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -118,6 +118,7 @@ createdb(const CreatedbStmt *stmt)
int encoding = -1;
int dbconnlimit = -1;
int ctype_encoding;
+ int collate_encoding;
int notherbackends;
int npreparedxacts;
createdb_failure_params fparms;
@@ -334,6 +335,7 @@ createdb(const CreatedbStmt *stmt)
* Note: if you change this policy, fix initdb to match.
*/
ctype_encoding = pg_get_encoding_from_locale(dbctype);
+ collate_encoding = pg_get_encoding_from_locale(dbcollate);
if (!(ctype_encoding == encoding ||
ctype_encoding == PG_SQL_ASCII ||
@@ -345,9 +347,22 @@ createdb(const CreatedbStmt *stmt)
(errmsg("encoding %s does not match locale %s",
pg_encoding_to_char(encoding),
dbctype),
- errdetail("The chosen LC_CTYPE setting requires encoding %s.",
+ errdetail("The chosen CTYPE setting requires encoding %s.",
pg_encoding_to_char(ctype_encoding))));
+ if (!(collate_encoding == encoding ||
+ collate_encoding == PG_SQL_ASCII ||
+#ifdef WIN32
+ encoding == PG_UTF8 ||
+#endif
+ (encoding == PG_SQL_ASCII && superuser())))
+ ereport(ERROR,
+ (errmsg("encoding %s does not match locale %s",
+ pg_encoding_to_char(encoding),
+ dbcollate),
+ errdetail("The chosen COLLATE setting requires encoding %s.",
+ pg_encoding_to_char(collate_encoding))));
+
/*
* Check that the new locale is compatible with the source database.
*