pgsql: Replace empty locale name with implied value in CREATE DATABASE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Replace empty locale name with implied value in CREATE DATABASE
Date: 2012-03-26 01:47:30
Message-ID: E1SBz1u-0000mq-3K@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Replace empty locale name with implied value in CREATE DATABASE and initdb.

setlocale() accepts locale name "" as meaning "the locale specified by the
process's environment variables". Historically we've accepted that for
Postgres' locale settings, too. However, it's fairly unsafe to store an
empty string in a new database's pg_database.datcollate or datctype fields,
because then the interpretation could vary across postmaster restarts,
possibly resulting in index corruption and other unpleasantness.

Instead, we should expand "" to whatever it means at the moment of calling
CREATE DATABASE, which we can do by saving the value returned by
setlocale().

For consistency, make initdb set up the initial lc_xxx parameter values the
same way. initdb was already doing the right thing for empty locale names,
but it did not replace non-empty names with setlocale results. On a
platform where setlocale chooses to canonicalize the spellings of locale
names, this would result in annoying inconsistency. (It seems that popular
implementations of setlocale don't do such canonicalization, which is a
pity, but the POSIX spec certainly allows it to be done.) The same risk
of inconsistency leads me to not venture back-patching this, although it
could certainly be seen as a longstanding bug.

Per report from Jeff Davis, though this is not his proposed patch.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/c7cea267de3ca05b29a57b9d113b95ef3793c8d8

Modified Files
--------------
src/backend/commands/dbcommands.c | 9 +++-
src/backend/utils/adt/pg_locale.c | 34 ++++++++++----
src/bin/initdb/initdb.c | 86 +++++++++++++++++++++++++------------
src/include/utils/pg_locale.h | 2 +-
4 files changed, 90 insertions(+), 41 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2012-03-26 03:18:08 pgsql: Fix COPY FROM for null marker strings that correspond to invalid
Previous Message Tom Lane 2012-03-24 20:22:54 pgsql: Fix planner's handling of outer PlaceHolderVars within subquerie

Browse pgsql-hackers by date

  From Date Subject
Next Message Joachim Wieland 2012-03-26 02:50:51 Re: patch for parallel pg_dump
Previous Message Tom Lane 2012-03-25 21:14:48 Re: COPY / extend ExclusiveLock