On 11/12/16 23:14, Ludovic Courtès wrote:
Hi!
Christopher Baines <m...@cbaines.net> skribis:
* gnu/services/postgresql.scm (<postgresql-configuration>): Add locale
field.
(postgresql-shepherd-service): Pass locale to initdb.
(postgresql-service): Add locale default.
[...]
+ (locale postgresql-configuration-locale
+ (default "en_US.UTF-8"))
Note: this should use the “normalized codeset”, so “en_US.utf8”.
(let ((user (getpwnam "postgres"))
- (initdb (string-append #$postgresql "/bin/initdb")))
+ (initdb (string-append #$postgresql "/bin/initdb"))
+ (initdb-args
+ (append
+ (if #$locale
+ (list (string-append "--locale=" #$locale))
+ '()))))
;; Create db state directory.
(mkdir-p #$data-directory)
(chown #$data-directory (passwd:uid user) (passwd:gid user))
@@ -103,14 +110,19 @@ host all all ::1/128 trust"))
(lambda ()
(setgid (passwd:gid user))
(setuid (passwd:uid user))
- (primitive-exit (system* initdb "-D" #$data-directory)))
+ (primitive-exit
+ (apply system*
+ initdb
+ "-D"
+ #$data-directory
+ initdb-args)))
(lambda ()
(primitive-exit 1))))
(pid (waitpid pid))))))))
The effect of that is that ‘initdb’, but not ‘postgresql’ itself, would
run in a locale different from the system locale by default.
These two inconsistencies may be quite confusing. WDYT?
I believe the locale passed to initdb sets "the default locale for the
database cluster", so I'd imagine that there is no problems with running
PostgreSQL (it seems to work for me). I think its good to support
setting it explicitly, but it would also be good to use the system
locale as a default.
I thought about trying to get the LANG from /etc/environment, or the
<operating-system>, but I could not see an easy and elegant way to do
either. By default, initdb will use the environment, its just that the
environment during service activation contains no locale information.