Skip to contentSkip to conversation

package/glibc: install locale cmd independent of NLS

PATCH New Peter Seiderer 3 participants 9 messages Sep 20, 2020 – Sep 22, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 package/glibc: install locale cmd independent of NLS

---
 package/glibc/glibc.mk | 2 --
 1 file changed, 2 deletions(-)
package/glibc/glibc.mk +0 -2
index f2b5b4caf6..99c71b6eac 100644
@@ -158,10 +158,8 @@ endif
 ifeq ($(BR2_PACKAGE_GLIBC_UTILS),y)
 GLIBC_TARGET_UTILS_USR_BIN = posix/getconf elf/ldd
 GLIBC_TARGET_UTILS_SBIN = elf/ldconfig
-ifeq ($(BR2_SYSTEM_ENABLE_NLS),y)
 GLIBC_TARGET_UTILS_USR_BIN += locale/locale
 endif
-endif
 
 define GLIBC_INSTALL_TARGET_CMDS
 	for libpattern in $(GLIBC_LIBS_LIB); do \
Signature · 1 line
2.28.0
#1 lore raw

PATCH 2/3 package/postgresql: needs locale command

Running (as e.g. /etc/init.d/S50postgresql does):

su - postgres -c '/usr/bin/pg_ctl initdb -D /var/lib/pgsql'

gives the following warning:

performing post-bootstrap initialization ... sh: locale: not found

  1970-01-01 01:13:43.498 UTC [246] WARNING:  no usable system locales were found
  ok

Strace (greped for locale) of the command shows:

  247   execve("/bin/sh", ["sh", "-c", "locale -a"], 0x1ece86e0 /* 18 vars */ <unfinished ...>
  247   newfstatat(AT_FDCWD, "/bin/locale", 0x7fcbe31a30, 0) = -1 ENOENT (No such file or directory)
  247   newfstatat(AT_FDCWD, "/sbin/locale", 0x7fcbe31a30, 0) = -1 ENOENT (No such file or directory)
  247   newfstatat(AT_FDCWD, "/usr/bin/locale", 0x7fcbe31a30, 0) = -1 ENOENT (No such file or directory)
  247   newfstatat(AT_FDCWD, "/usr/sbin/locale", 0x7fcbe31a30, 0) = -1 ENOENT (No such file or directory)
  247   write(2, "locale: not found", 17) = 17

Fix it by selecting BR2_PACKAGE_GLIBC_UTILS providing the locale command for glibc.

---
Notes:

- tested with the following defconfig

    BR2_aarch64=y
    BR2_cortex_a72=y
    BR2_ARM_FPU_VFPV4=y
    BR2_TOOLCHAIN_BUILDROOT_GLIBC=y
    BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_4=y
    BR2_TOOLCHAIN_BUILDROOT_CXX=y
    BR2_SYSTEM_DHCP="eth0"
    BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi4-64/post-build.sh"
    BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi4-64/post-image.sh"
    BR2_ROOTFS_POST_SCRIPT_ARGS="--add-miniuart-bt-overlay --aarch64"
    BR2_LINUX_KERNEL=y
    BR2_LINUX_KERNEL_CUSTOM_TARBALL=y
    BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION="$(call github,raspberrypi,linux,1c64f4bc22811d2d371b271daa3fb27895a8abdd)/linux-1c64f4bc22811d2d371b271daa3fb27895a8abdd.tar.gz"
    BR2_LINUX_KERNEL_DEFCONFIG="bcm2711"
    BR2_LINUX_KERNEL_DTS_SUPPORT=y
    BR2_LINUX_KERNEL_INTREE_DTS_NAME="broadcom/bcm2711-rpi-4-b"
    BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
    BR2_PACKAGE_STRACE=y
    BR2_PACKAGE_RPI_FIRMWARE=y
    BR2_PACKAGE_RPI_FIRMWARE_VARIANT_PI4=y
    BR2_PACKAGE_POSTGRESQL=y
    BR2_TARGET_ROOTFS_EXT2=y
    BR2_TARGET_ROOTFS_EXT2_4=y
    BR2_TARGET_ROOTFS_EXT2_SIZE="192M"
    # BR2_TARGET_ROOTFS_TAR is not set
    BR2_PACKAGE_HOST_DOSFSTOOLS=y
    BR2_PACKAGE_HOST_GENIMAGE=y
    BR2_PACKAGE_HOST_MTOOLS=y
---
 package/postgresql/Config.in | 1 +
 1 file changed, 1 insertion(+)
package/postgresql/Config.in +1 -0
index 2f677daf5b..b15d34d3f0 100644
@@ -6,6 +6,7 @@ config BR2_PACKAGE_POSTGRESQL
 	# postgresql is unlikely to be used in a pure statically
 	# linked environment.
 	depends on !BR2_STATIC_LIBS
+	select BR2_PACKAGE_GLIBC_UTILS if BR2_PACKAGE_GLIBC # locale cmd
 	help
 	  PostgreSQL is a powerful, open source object-relational
 	  database system.
Signature · 1 line
2.28.0
#2 lore raw

PATCH 2/3 package/postgresql: needs locale command

Hello,

Quoted 9 lines · On Sun, 20 Sep 2020 17:06:58 +0200 Peter Seiderer <[email protected]> wrote:

Running (as e.g. /etc/init.d/S50postgresql does):

su - postgres -c '/usr/bin/pg_ctl initdb -D /var/lib/pgsql'

gives the following warning:

performing post-bootstrap initialization ... sh: locale: not found

  1970-01-01 01:13:43.498 UTC [246] WARNING:  no usable system locales were found
  ok

What is the situation with uClibc and musl toolchains ? Do they provide the "locale" command as well ?

What about external glibc toolchains ? Do we install/copy the locale tool to the target ?

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#3 lore raw

PATCH 2/3 package/postgresql: needs locale command

Hello Thomas,

Quoted 9 lines · Thomas Petazzoni

Hello,

Quoted 4 lines · On Sun, 20 Sep 2020 17:06:58 +0200 Peter Seiderer <[email protected]> wrote:

Running (as e.g. /etc/init.d/S50postgresql does):

su - postgres -c '/usr/bin/pg_ctl initdb -D /var/lib/pgsql'

Quoted 8 lines
Quoted 5 lines

gives the following warning:

performing post-bootstrap initialization ... sh: locale: not found

  1970-01-01 01:13:43.498 UTC [246] WARNING:  no usable system locales were found
  ok

What is the situation with uClibc and musl toolchains ? Do they provide the "locale" command as well ?

- uclibc without BR2_TOOLCHAIN_BUILDROOT_LOCALE: no warning, no locale command ([1])
- uclicc with BR2_TOOLCHAIN_BUILDROOT_LOCALE: no warning, locale command installed on target
- musl: 'locale: not found' warning, no locale commmand

But it is 'only' a warning... and easy to fix for gcc/buildroot toolchain...

Quoted 3 lines

What about external glibc toolchains ? Do we install/copy the locale tool to the target ?

Do not know...., but it is only a warning...

Regards,
Peter

[1] The usage of the locale command depends on 'HAVE_LOCALE_T' which depends on the availability of the locale_t type (see postgresql-12.4/config/c-library.m4 and postgresql-12.4/src/backend/commands/collationcmds.c)

Quoted 2 lines

Thomas

#4 lore raw

PATCH 2/3 package/postgresql: needs locale command

Hi Peter,

Quoted 19 lines · Peter Seiderer

Hello Thomas,

Quoted 15 lines · Thomas Petazzoni

Hello,

Quoted 9 lines · On Sun, 20 Sep 2020 17:06:58 +0200 Peter Seiderer <[email protected]> wrote:

Running (as e.g. /etc/init.d/S50postgresql does):

su - postgres -c '/usr/bin/pg_ctl initdb -D /var/lib/pgsql'

gives the following warning:

performing post-bootstrap initialization ... sh: locale: not found

  1970-01-01 01:13:43.498 UTC [246] WARNING:  no usable system locales were found
  ok
Quoted 12 lines
Quoted 2 lines

What is the situation with uClibc and musl toolchains ? Do they provide the "locale" command as well ?

- uclibc without BR2_TOOLCHAIN_BUILDROOT_LOCALE: no warning, no locale command ([1])
- uclicc with BR2_TOOLCHAIN_BUILDROOT_LOCALE: no warning, locale command installed on target
- musl: 'locale: not found' warning, no locale commmand

But it is 'only' a warning... and easy to fix for gcc/buildroot toolchain...

Quoted 3 lines

What about external glibc toolchains ? Do we install/copy the locale tool to the target ?

I checked - no, we don't install it, even if it is part of the toolchain sysroot.

Quoted 1 line

Do not know...., but it is only a warning...

It is only a warning, but this patch is meant to get rid of that warning, no?
If this series only fixes that warning for the internal toolchain, I don't think it's very useful.

But probably toolchain-external-pkg.mk should be fixed to install locale if
available, just like we do for ldd. And maybe also ldconfig and getconf (the other two glibc utils we install) should be handled in the same way?

Quoted 6 lines

Regards,
Peter

[1] The usage of the locale command depends on 'HAVE_LOCALE_T' which depends on the availability of the locale_t type (see postgresql-12.4/config/c-library.m4 and postgresql-12.4/src/backend/commands/collationcmds.c)

We could instead prepopulate the cache variable pgac_cv_type_locale_t with the
presence of the locale binary in the target directory. Something like:

POSTGRESQL_CONF_ENV += pgac_cv_type_locale_t=$(if $(wildcard $(TARGET_DIR)/usr/bin/locale),yes,no)

This is assuming that the presence of the locale executable corresponds with
the availability of locales (which is apparently not the case for musl, but I think that that should be considered a bug in our musl integration). But at least for glibc and uClibc it seems to be correct.

This solution also removes the need for patch 1/3, which I thought was a bit
iffy anyway.

Regards,
Arnout

#5 lore raw

PATCH 2/3 package/postgresql: needs locale command

Hello Arnout,

Quoted 35 lines · Arnout Vandecappelle

Hi Peter,

Quoted 19 lines · Peter Seiderer

Hello Thomas,

Quoted 15 lines · Thomas Petazzoni

Hello,

Quoted 9 lines · On Sun, 20 Sep 2020 17:06:58 +0200 Peter Seiderer <[email protected]> wrote:

Running (as e.g. /etc/init.d/S50postgresql does):

su - postgres -c '/usr/bin/pg_ctl initdb -D /var/lib/pgsql'

gives the following warning:

performing post-bootstrap initialization ... sh: locale: not found

  1970-01-01 01:13:43.498 UTC [246] WARNING:  no usable system locales were found
  ok
Quoted 12 lines
Quoted 2 lines

What is the situation with uClibc and musl toolchains ? Do they provide the "locale" command as well ?

- uclibc without BR2_TOOLCHAIN_BUILDROOT_LOCALE: no warning, no locale command ([1])
- uclicc with BR2_TOOLCHAIN_BUILDROOT_LOCALE: no warning, locale command installed on target
- musl: 'locale: not found' warning, no locale commmand

But it is 'only' a warning... and easy to fix for gcc/buildroot toolchain...

Quoted 3 lines

What about external glibc toolchains ? Do we install/copy the locale tool to the target ?

Quoted 7 lines

I checked - no, we don't install it, even if it is part of the toolchain sysroot.

Quoted 1 line

Do not know...., but it is only a warning...

It is only a warning, but this patch is meant to get rid of that warning, no?
If this series only fixes that warning for the internal toolchain, I don't think it's very useful.

Get rid of the warning for one use case (where it is easy to fix) ;-)

Quoted 4 lines

But probably toolchain-external-pkg.mk should be fixed to install locale if
available, just like we do for ldd. And maybe also ldconfig and getconf (the other two glibc utils we install) should be handled in the same way?

Will take a look...

Quoted 12 lines
Quoted 8 lines

Regards,
Peter

[1] The usage of the locale command depends on 'HAVE_LOCALE_T' which depends on the availability of the locale_t type (see postgresql-12.4/config/c-library.m4 and postgresql-12.4/src/backend/commands/collationcmds.c)

We could instead prepopulate the cache variable pgac_cv_type_locale_t with the
presence of the locale binary in the target directory. Something like:

Quoted 7 lines

POSTGRESQL_CONF_ENV += pgac_cv_type_locale_t=$(if $(wildcard $(TARGET_DIR)/usr/bin/locale),yes,no)

This is assuming that the presence of the locale executable corresponds with
the availability of locales (which is apparently not the case for musl, but I think that that should be considered a bug in our musl integration). But at least for glibc and uClibc it seems to be correct.

I believe false assumption, locale_t type availability (and the availability of different locale definitions) does not automatically mean the locale command will be available (see glibc case without BR2_PACKAGE_GLIBC_UTILS, and without BR2_SYSTEM_ENABLE_NLS before patch 1)...

Quoted 3 lines

This solution also removes the need for patch 1/3, which I thought was a bit
iffy anyway.

See above and any reasons why the locale command should be bound to NSL support?

Regards,
Peter

Quoted 3 lines

Regards,
Arnout

#6 lore raw

PATCH 3/3 package/postgresql: set locale for initdb to C

In reply to Peter Seiderer

Postgresql systemd startup fails with:

Starting PostgreSQL database server... [FAILED] Failed to start PostgreSQL database server. See 'systemctl status postgresql.service' for details.

  $ systemctl status postgresql.service | cat
  ? postgresql.service - PostgreSQL database server
       Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
       Active: failed (Result: exit-code) since Sat 2020-09-12 12:16:35 UTC; 35s ago
      Process: 164 ExecStartPre=/bin/sh -c if [ ! -f /var/lib/pgsql/PG_VERSION ]; then /usr/bin/pg_ctl initdb -D /var/lib/pgsql; fi (code=exited, status=1/FAILURE)
  Sep 12 12:16:35 buildroot systemd[1]: Starting PostgreSQL database server...
  Sep 12 12:16:35 buildroot postgres[166]: The files belonging to this database system will be owned by user "postgres".
  Sep 12 12:16:35 buildroot postgres[166]: This user must also own the server process.
  Sep 12 12:16:35 buildroot postgres[166]: initdb: error: invalid locale settings; check LANG and LC_* environment variables
  Sep 12 12:16:35 buildroot systemd[1]: postgresql.service: Control process exited, code=exited, status=1/FAILURE
  Sep 12 12:16:35 buildroot postgres[164]: pg_ctl: database system initialization failed
  Sep 12 12:16:35 buildroot systemd[1]: postgresql.service: Failed with result 'exit-code'.
  Sep 12 12:16:35 buildroot systemd[1]: Failed to start PostgreSQL database server.

Fix it by setting a sane/always available locale=C in the startup files.

A similare failure/fix was reported by Pascal de Bruijn ([1]), but with en_US.UTF-8 instead of C.

[1] http://lists.busybox.net/pipermail/buildroot/2019-November/266700.html

---
Notes:

- tested with the following defconfig

    BR2_aarch64=y
    BR2_cortex_a72=y
    BR2_ARM_FPU_VFPV4=y
    BR2_TOOLCHAIN_BUILDROOT_GLIBC=y
    BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_4=y
    BR2_TOOLCHAIN_BUILDROOT_CXX=y
    BR2_INIT_SYSTEMD=y
    BR2_SYSTEM_DHCP="eth0"
    BR2_SYSTEM_DEFAULT_PATH="/bin:/sbin:/usr/bin:/usr/sbin"
    BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi4-64/post-build.sh"
    BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi4-64/post-image.sh"
    BR2_ROOTFS_POST_SCRIPT_ARGS="--add-miniuart-bt-overlay --aarch64"
    BR2_LINUX_KERNEL=y
    BR2_LINUX_KERNEL_CUSTOM_TARBALL=y
    BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION="$(call github,raspberrypi,linux,1c64f4bc22811d2d371b271daa3fb27895a8abdd)/linux-1c64f4bc22811d2d371b271daa3fb27895a8abdd.tar.gz"
    BR2_LINUX_KERNEL_DEFCONFIG="bcm2711"
    BR2_LINUX_KERNEL_DTS_SUPPORT=y
    BR2_LINUX_KERNEL_INTREE_DTS_NAME="broadcom/bcm2711-rpi-4-b"
    BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
    BR2_PACKAGE_STRACE=y
    BR2_PACKAGE_RPI_FIRMWARE=y
    BR2_PACKAGE_RPI_FIRMWARE_VARIANT_PI4=y
    BR2_PACKAGE_POSTGRESQL=y
    BR2_TARGET_ROOTFS_EXT2=y
    BR2_TARGET_ROOTFS_EXT2_4=y
    BR2_TARGET_ROOTFS_EXT2_SIZE="256M"
    # BR2_TARGET_ROOTFS_TAR is not set
    BR2_PACKAGE_HOST_DOSFSTOOLS=y
    BR2_PACKAGE_HOST_GENIMAGE=y
    BR2_PACKAGE_HOST_MTOOLS=y
---
 package/postgresql/S50postgresql      | 2 +-
 package/postgresql/postgresql.service | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
package/postgresql/S50postgresql +1 -1
index 1ece4fca9e..c47880dfd8 100644
@@ -7,7 +7,7 @@ umask 077
 
 if [ ! -f /var/lib/pgsql/PG_VERSION ]; then
 	echo "Initializing postgresql data base..."
-	su - postgres -c '/usr/bin/pg_ctl initdb -D /var/lib/pgsql'
+	su - postgres -c '/usr/bin/pg_ctl initdb -D /var/lib/pgsql -o --locale=C'
 	echo "done"
 fi
 
package/postgresql/postgresql.service +1 -1
index 53e6f84f00..42d973255c 100644
@@ -17,7 +17,7 @@ StandardError=syslog
 SyslogIdentifier=postgres
 PIDFile=/var/lib/pgsql/postmaster.pid
 
-ExecStartPre=/bin/sh -c "if [ ! -f /var/lib/pgsql/PG_VERSION ]; then /usr/bin/pg_ctl initdb -D /var/lib/pgsql; fi"
+ExecStartPre=/bin/sh -c "if [ ! -f /var/lib/pgsql/PG_VERSION ]; then /usr/bin/pg_ctl initdb -D /var/lib/pgsql -o --locale=C; fi"
 ExecStart=/usr/bin/postgres -D /var/lib/pgsql
 ExecReload=/usr/bin/kill -HUP $MAINPID
 KillMode=mixed
Signature · 1 line
2.28.0
#7 lore raw

PATCH 3/3 package/postgresql: set locale for initdb to C

Quoted 74 lines · Peter Seiderer

Postgresql systemd startup fails with:

Starting PostgreSQL database server... [FAILED] Failed to start PostgreSQL database server. See 'systemctl status postgresql.service' for details.

  $ systemctl status postgresql.service | cat
  ? postgresql.service - PostgreSQL database server
       Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
       Active: failed (Result: exit-code) since Sat 2020-09-12 12:16:35 UTC; 35s ago
      Process: 164 ExecStartPre=/bin/sh -c if [ ! -f /var/lib/pgsql/PG_VERSION ]; then /usr/bin/pg_ctl initdb -D /var/lib/pgsql; fi (code=exited, status=1/FAILURE)
  Sep 12 12:16:35 buildroot systemd[1]: Starting PostgreSQL database server...
  Sep 12 12:16:35 buildroot postgres[166]: The files belonging to this database system will be owned by user "postgres".
  Sep 12 12:16:35 buildroot postgres[166]: This user must also own the server process.
  Sep 12 12:16:35 buildroot postgres[166]: initdb: error: invalid locale settings; check LANG and LC_* environment variables
  Sep 12 12:16:35 buildroot systemd[1]: postgresql.service: Control process exited, code=exited, status=1/FAILURE
  Sep 12 12:16:35 buildroot postgres[164]: pg_ctl: database system initialization failed
  Sep 12 12:16:35 buildroot systemd[1]: postgresql.service: Failed with result 'exit-code'.
  Sep 12 12:16:35 buildroot systemd[1]: Failed to start PostgreSQL database server.

Fix it by setting a sane/always available locale=C in the startup files.

A similare failure/fix was reported by Pascal de Bruijn ([1]), but with en_US.UTF-8 instead of C.

[1] http://lists.busybox.net/pipermail/buildroot/2019-November/266700.html

---
Notes:

- tested with the following defconfig

    BR2_aarch64=y
    BR2_cortex_a72=y
    BR2_ARM_FPU_VFPV4=y
    BR2_TOOLCHAIN_BUILDROOT_GLIBC=y
    BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_4=y
    BR2_TOOLCHAIN_BUILDROOT_CXX=y
    BR2_INIT_SYSTEMD=y
    BR2_SYSTEM_DHCP="eth0"
    BR2_SYSTEM_DEFAULT_PATH="/bin:/sbin:/usr/bin:/usr/sbin"
    BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi4-64/post-build.sh"
    BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi4-64/post-image.sh"
    BR2_ROOTFS_POST_SCRIPT_ARGS="--add-miniuart-bt-overlay --aarch64"
    BR2_LINUX_KERNEL=y
    BR2_LINUX_KERNEL_CUSTOM_TARBALL=y
    BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION="$(call github,raspberrypi,linux,1c64f4bc22811d2d371b271daa3fb27895a8abdd)/linux-1c64f4bc22811d2d371b271daa3fb27895a8abdd.tar.gz"
    BR2_LINUX_KERNEL_DEFCONFIG="bcm2711"
    BR2_LINUX_KERNEL_DTS_SUPPORT=y
    BR2_LINUX_KERNEL_INTREE_DTS_NAME="broadcom/bcm2711-rpi-4-b"
    BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
    BR2_PACKAGE_STRACE=y
    BR2_PACKAGE_RPI_FIRMWARE=y
    BR2_PACKAGE_RPI_FIRMWARE_VARIANT_PI4=y
    BR2_PACKAGE_POSTGRESQL=y
    BR2_TARGET_ROOTFS_EXT2=y
    BR2_TARGET_ROOTFS_EXT2_4=y
    BR2_TARGET_ROOTFS_EXT2_SIZE="256M"
    # BR2_TARGET_ROOTFS_TAR is not set
    BR2_PACKAGE_HOST_DOSFSTOOLS=y
    BR2_PACKAGE_HOST_GENIMAGE=y
    BR2_PACKAGE_HOST_MTOOLS=y
---
 package/postgresql/S50postgresql      | 2 +-
 package/postgresql/postgresql.service | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
package/postgresql/S50postgresql +0 -0
index 1ece4fca9e..c47880dfd8 100644

package/postgresql/S50postgresql umask 077 · line 10

Quoted 5 lines
package/postgresql/S50postgresql +1 -1
@@ -7,7 +7,7 @@ umask 077
 
 if [ ! -f /var/lib/pgsql/PG_VERSION ]; then
 	echo "Initializing postgresql data base..."
-	su - postgres -c '/usr/bin/pg_ctl initdb -D /var/lib/pgsql'
+	su - postgres -c '/usr/bin/pg_ctl initdb -D /var/lib/pgsql -o --locale=C'

I think it would be nicer if the default locale could be used instead of
forcing C, but I can't be bother to find a solution for that, so

Regards,
Arnout

Quoted 17 lines
package/postgresql/S50postgresql +0 -0
 	echo "done"
 fi
 
package/postgresql/postgresql.service +1 -1
index 53e6f84f00..42d973255c 100644
@@ -17,7 +17,7 @@ StandardError=syslog
 SyslogIdentifier=postgres
 PIDFile=/var/lib/pgsql/postmaster.pid
 
-ExecStartPre=/bin/sh -c "if [ ! -f /var/lib/pgsql/PG_VERSION ]; then /usr/bin/pg_ctl initdb -D /var/lib/pgsql; fi"
+ExecStartPre=/bin/sh -c "if [ ! -f /var/lib/pgsql/PG_VERSION ]; then /usr/bin/pg_ctl initdb -D /var/lib/pgsql -o --locale=C; fi"
 ExecStart=/usr/bin/postgres -D /var/lib/pgsql
 ExecReload=/usr/bin/kill -HUP $MAINPID
 KillMode=mixed
#8 lore raw

PATCH 3/3 package/postgresql: set locale for initdb to C

Hello Arnout,

Quoted 76 lines · Arnout Vandecappelle
Quoted 75 lines · Peter Seiderer

Postgresql systemd startup fails with:

Starting PostgreSQL database server... [FAILED] Failed to start PostgreSQL database server. See 'systemctl status postgresql.service' for details.

  $ systemctl status postgresql.service | cat
  ? postgresql.service - PostgreSQL database server
       Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
       Active: failed (Result: exit-code) since Sat 2020-09-12 12:16:35 UTC; 35s ago
      Process: 164 ExecStartPre=/bin/sh -c if [ ! -f /var/lib/pgsql/PG_VERSION ]; then /usr/bin/pg_ctl initdb -D /var/lib/pgsql; fi (code=exited, status=1/FAILURE)
  Sep 12 12:16:35 buildroot systemd[1]: Starting PostgreSQL database server...
  Sep 12 12:16:35 buildroot postgres[166]: The files belonging to this database system will be owned by user "postgres".
  Sep 12 12:16:35 buildroot postgres[166]: This user must also own the server process.
  Sep 12 12:16:35 buildroot postgres[166]: initdb: error: invalid locale settings; check LANG and LC_* environment variables
  Sep 12 12:16:35 buildroot systemd[1]: postgresql.service: Control process exited, code=exited, status=1/FAILURE
  Sep 12 12:16:35 buildroot postgres[164]: pg_ctl: database system initialization failed
  Sep 12 12:16:35 buildroot systemd[1]: postgresql.service: Failed with result 'exit-code'.
  Sep 12 12:16:35 buildroot systemd[1]: Failed to start PostgreSQL database server.

Fix it by setting a sane/always available locale=C in the startup files.

A similare failure/fix was reported by Pascal de Bruijn ([1]), but with en_US.UTF-8 instead of C.

[1] http://lists.busybox.net/pipermail/buildroot/2019-November/266700.html

---
Notes:

- tested with the following defconfig

    BR2_aarch64=y
    BR2_cortex_a72=y
    BR2_ARM_FPU_VFPV4=y
    BR2_TOOLCHAIN_BUILDROOT_GLIBC=y
    BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_4=y
    BR2_TOOLCHAIN_BUILDROOT_CXX=y
    BR2_INIT_SYSTEMD=y
    BR2_SYSTEM_DHCP="eth0"
    BR2_SYSTEM_DEFAULT_PATH="/bin:/sbin:/usr/bin:/usr/sbin"
    BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi4-64/post-build.sh"
    BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi4-64/post-image.sh"
    BR2_ROOTFS_POST_SCRIPT_ARGS="--add-miniuart-bt-overlay --aarch64"
    BR2_LINUX_KERNEL=y
    BR2_LINUX_KERNEL_CUSTOM_TARBALL=y
    BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION="$(call github,raspberrypi,linux,1c64f4bc22811d2d371b271daa3fb27895a8abdd)/linux-1c64f4bc22811d2d371b271daa3fb27895a8abdd.tar.gz"
    BR2_LINUX_KERNEL_DEFCONFIG="bcm2711"
    BR2_LINUX_KERNEL_DTS_SUPPORT=y
    BR2_LINUX_KERNEL_INTREE_DTS_NAME="broadcom/bcm2711-rpi-4-b"
    BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
    BR2_PACKAGE_STRACE=y
    BR2_PACKAGE_RPI_FIRMWARE=y
    BR2_PACKAGE_RPI_FIRMWARE_VARIANT_PI4=y
    BR2_PACKAGE_POSTGRESQL=y
    BR2_TARGET_ROOTFS_EXT2=y
    BR2_TARGET_ROOTFS_EXT2_4=y
    BR2_TARGET_ROOTFS_EXT2_SIZE="256M"
    # BR2_TARGET_ROOTFS_TAR is not set
    BR2_PACKAGE_HOST_DOSFSTOOLS=y
    BR2_PACKAGE_HOST_GENIMAGE=y
    BR2_PACKAGE_HOST_MTOOLS=y
---
 package/postgresql/S50postgresql      | 2 +-
 package/postgresql/postgresql.service | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
package/postgresql/S50postgresql +0 -0
index 1ece4fca9e..c47880dfd8 100644
@@ -7,7 +7,7 @@ umask 077
 
Quoted 7 lines

package/postgresql/S50postgresql umask 077 · line 10

Quoted 4 lines
package/postgresql/S50postgresql +1 -1
 if [ ! -f /var/lib/pgsql/PG_VERSION ]; then
 	echo "Initializing postgresql data base..."
-	su - postgres -c '/usr/bin/pg_ctl initdb -D /var/lib/pgsql'
+	su - postgres -c '/usr/bin/pg_ctl initdb -D /var/lib/pgsql -o --locale=C'  

I think it would be nicer if the default locale could be used instead of
forcing C, but I can't be bother to find a solution for that, so

Is there the concept of default locale in buildroot? Did not find anything setting/using /etc/locale.conf (maybe systemd is setting something)?

Thanks for review...

Regards,
Peter

Quoted 28 lines

Regards,
Arnout

Quoted 9 lines
package/postgresql/S50postgresql +0 -0
 	echo "done"
 fi
 
package/postgresql/postgresql.service +0 -0
index 53e6f84f00..42d973255c 100644

package/postgresql/postgresql.service StandardError=syslog · line 23

Quoted 8 lines
package/postgresql/postgresql.service +1 -1
@@ -17,7 +17,7 @@ StandardError=syslog
 SyslogIdentifier=postgres
 PIDFile=/var/lib/pgsql/postmaster.pid
 
-ExecStartPre=/bin/sh -c "if [ ! -f /var/lib/pgsql/PG_VERSION ]; then /usr/bin/pg_ctl initdb -D /var/lib/pgsql; fi"
+ExecStartPre=/bin/sh -c "if [ ! -f /var/lib/pgsql/PG_VERSION ]; then /usr/bin/pg_ctl initdb -D /var/lib/pgsql -o --locale=C; fi"
 ExecStart=/usr/bin/postgres -D /var/lib/pgsql
 ExecReload=/usr/bin/kill -HUP $MAINPID
 KillMode=mixed

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot