Cleanup PostgreSQL for state version 17.09 (#25753)
* postgresql service: make 9.6 the default version for 17.09 * postgresql service: change default superuser for 17.09 Change the default superuser from `root` to `postgres` for state version 17.09 * postgresql service: change default data directory for 17.09 The new directory includes the schema version of the database. This makes upgrades easier and is more consistent with other distros. * updated nixos release notes
This commit is contained in:
parent
3fa1be6f49
commit
de52d2450e
@ -78,6 +78,17 @@ rmdir /var/lib/ipfs/.ipfs
|
|||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
The <literal>postgres</literal> default version was changed from 9.5 to 9.6.
|
||||||
|
</para>
|
||||||
|
<para>
|
||||||
|
The <literal>postgres</literal> superuser name has changed from <literal>root</literal> to <literal>postgres</literal> to more closely follow what other Linux distributions are doing.
|
||||||
|
</para>
|
||||||
|
<para>
|
||||||
|
The <literal>postgres</literal> default <literal>dataDir</literal> has changed from <literal>/var/db/postgres</literal> to <literal>/var/lib/postgresql/$psqlSchema</literal> where $psqlSchema is 9.6 for example.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,6 +38,10 @@ let
|
|||||||
|
|
||||||
pre84 = versionOlder (builtins.parseDrvName postgresql.name).version "8.4";
|
pre84 = versionOlder (builtins.parseDrvName postgresql.name).version "8.4";
|
||||||
|
|
||||||
|
# NixOS traditionally used `root` as superuser, most other distros use `postgres`. From 17.09
|
||||||
|
# we also try to follow this standard
|
||||||
|
superuser = (if versionAtLeast config.system.stateVersion "17.09" then "postgres" else "root");
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -74,7 +78,7 @@ in
|
|||||||
|
|
||||||
dataDir = mkOption {
|
dataDir = mkOption {
|
||||||
type = types.path;
|
type = types.path;
|
||||||
default = "/var/db/postgresql";
|
example = "/var/lib/postgresql/9.6";
|
||||||
description = ''
|
description = ''
|
||||||
Data directory for PostgreSQL.
|
Data directory for PostgreSQL.
|
||||||
'';
|
'';
|
||||||
@ -160,7 +164,13 @@ in
|
|||||||
# Note: when changing the default, make it conditional on
|
# Note: when changing the default, make it conditional on
|
||||||
# ‘system.stateVersion’ to maintain compatibility with existing
|
# ‘system.stateVersion’ to maintain compatibility with existing
|
||||||
# systems!
|
# systems!
|
||||||
mkDefault (if versionAtLeast config.system.stateVersion "16.03" then pkgs.postgresql95 else pkgs.postgresql94);
|
mkDefault (if versionAtLeast config.system.stateVersion "17.09" then pkgs.postgresql96
|
||||||
|
else if versionAtLeast config.system.stateVersion "16.03" then pkgs.postgresql95
|
||||||
|
else pkgs.postgresql94);
|
||||||
|
|
||||||
|
services.postgresql.dataDir =
|
||||||
|
mkDefault (if versionAtLeast config.system.stateVersion "17.09" then "/var/lib/postgresql/${config.services.postgresql.package.psqlSchema}"
|
||||||
|
else "/var/db/postgresql");
|
||||||
|
|
||||||
services.postgresql.authentication = mkAfter
|
services.postgresql.authentication = mkAfter
|
||||||
''
|
''
|
||||||
@ -205,7 +215,7 @@ in
|
|||||||
''
|
''
|
||||||
# Initialise the database.
|
# Initialise the database.
|
||||||
if ! test -e ${cfg.dataDir}/PG_VERSION; then
|
if ! test -e ${cfg.dataDir}/PG_VERSION; then
|
||||||
initdb -U root
|
initdb -U ${superuser}
|
||||||
# See postStart!
|
# See postStart!
|
||||||
touch "${cfg.dataDir}/.first_startup"
|
touch "${cfg.dataDir}/.first_startup"
|
||||||
fi
|
fi
|
||||||
@ -237,14 +247,14 @@ in
|
|||||||
# Wait for PostgreSQL to be ready to accept connections.
|
# Wait for PostgreSQL to be ready to accept connections.
|
||||||
postStart =
|
postStart =
|
||||||
''
|
''
|
||||||
while ! psql --port=${toString cfg.port} postgres -c "" 2> /dev/null; do
|
while ! ${pkgs.sudo}/bin/sudo -u ${superuser} psql --port=${toString cfg.port} -d postgres -c "" 2> /dev/null; do
|
||||||
if ! kill -0 "$MAINPID"; then exit 1; fi
|
if ! kill -0 "$MAINPID"; then exit 1; fi
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
done
|
done
|
||||||
|
|
||||||
if test -e "${cfg.dataDir}/.first_startup"; then
|
if test -e "${cfg.dataDir}/.first_startup"; then
|
||||||
${optionalString (cfg.initialScript != null) ''
|
${optionalString (cfg.initialScript != null) ''
|
||||||
psql -f "${cfg.initialScript}" --port=${toString cfg.port} postgres
|
${pkgs.sudo}/bin/sudo -u ${superuser} psql -f "${cfg.initialScript}" --port=${toString cfg.port} -d postgres
|
||||||
''}
|
''}
|
||||||
rm -f "${cfg.dataDir}/.first_startup"
|
rm -f "${cfg.dataDir}/.first_startup"
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user