Arch Linux

Please read this before reporting a bug:
https://wiki.archlinux.org/title/Bug_reporting_guidelines

Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!
Tasklist

FS#27222 - [postgresql] Default encoding doesn't honour $LOCALE (rc.conf) and fallback to SQL_ASCII

Attached to Project: Arch Linux
Opened by Shanto (Shanto) - Tuesday, 22 November 2011, 04:08 GMT
Last edited by Dan McGee (toofishes) - Monday, 05 December 2011, 21:08 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To Paul Mattal (paul)
Dan McGee (toofishes)
Architecture All
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No

Details

Problem description:
--------------------
Unicode is the recommended default encoding for PostgreSQL. However, to get that in Arch, you have to go through these steps every time you install/upgrade:
https://wiki.archlinux.org/index.php/PostgreSQL#Change_Default_Encoding_of_New_Databases_To_UTF-8_.28Optional.29

I think, this could be handled better with slight changes to the shipped conf.d file where it honours the $LOCALE set in rc.conf.

Reproducing the problem:
------------------------
# do this with an empty postgresql data dir (/var/lib/postgres)
$ sudo rc.d start postgresql
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale *C*.
The default database encoding has accordingly been set to *SQL_ASCII*.
The default text search configuration will be set to "english".

Possible fix (patch attached):
------------------------------
1. Uncomment INITOPTS in http://projects.archlinux.org/svntogit/packages.git/tree/trunk/postgresql.confd?h=packages/postgresql
2. Instead of using $LANG, which is not a reliable source, use $LOCALE variable (derived from rc.conf by the corresponding rc.d script).

After fixing:
-------------
$ grep ^LOCALE= /etc/rc.conf
LOCALE="en_US.UTF-8"
$ sudo rc.d start postgresql
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale *en_US.UTF-8*.
The default database encoding has accordingly been set to *UTF8*.
The default text search configuration will be set to "english".
This task depends upon

Closed by  Dan McGee (toofishes)
Monday, 05 December 2011, 21:08 GMT
Reason for closing:  Fixed
Additional comments about closing:  9.1.2-1
Comment by Dan McGee (toofishes) - Tuesday, 22 November 2011, 18:21 GMT
I don't even have LOCALE set in my environment; I doubt many others do either.

This is not meant to be a one-size-fits-all package, you need to carefully set up the package as appropriate, and I purposely commented everything in the config file because running under different users gave you different results before, which is just plain unacceptable.

I could put a commented `INITOPTS="--locale en_US.UTF-8"` bit in the file, but we're not RH nor Ubuntu; there is some work to do around here.
Comment by Shanto (Shanto) - Friday, 25 November 2011, 06:36 GMT
Let's think about one-size-fits-majority instead. Why else do you put LOCALE="en_US.UTF-8" in /etc/rc.conf (package: initscripts) by default? Why not let the user do some work around there too?

Just in case you missed it, I talked about using $LOCALE from /etc/rc.conf (already sourced by the postgresql init script), not from your user environment. So, if you are fine with supplying uncommented/default "LOCALE=en_US.UTF-8" in rc.conf, you should be fine too with using that same default (intended for majority).

Otherwise, don't check for data directory (http://projects.archlinux.org/svntogit/packages.git/tree/trunk/postgresql?h=packages/postgresql#n16) and don't call initdb from within the init script. Stop there and let the user handle it entirely. If you initialize the db from there, do it properly or don't do at all.
Comment by Shanto (Shanto) - Friday, 25 November 2011, 06:57 GMT
Which init script/example from the upstream are you following? I don't see any initdb call in http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=contrib/start-scripts/linux.
Comment by Shanto (Shanto) - Friday, 25 November 2011, 07:18 GMT
Running under different users gave you different results before because you had $LANG there, not $LOCALE. What I am suggesting is to use the $LOCALE coming from /etc/rc.conf.

Loading...