postgresql-server fails to start in sle-bci container
This document (000021398) is provided subject to the disclaimer at the end of this document.
Environment
Situation
FATAL: could not create lock file "/run/postgresql/.s.PGSQL.5432.lock": No such file or directory
Resolution
- Use the registry.suse.com/suse/postgres:latest image created by SUSE. See https://registry.suse.com/categories/apps/repositories/suse-postgres16 for more information. This image was designed to ease containerised deployment of postgresql-server.
- Install systemd along with postgresql-server
- Execute the following command to create /run/postgresql with the metadata specified in /usr/lib/tmpfiles.d/postgresql.conf after installing the postgresql-server package :
install -d /run/postgresql -m 1775 -g postgres -o postgres
Cause
As part of a general attempt to slim down the SUSE Base Container Image (see https://registry.suse.com/categories/bci) sizes, the dependency on systemd was removed in the postgresql-server-16-150500.10.3.2 maintenance update.
This causes the /run/postgresql/ directory to not get created by systemd-tmpfiles-setup.service as part of the installation.
Based on information in /usr/lib/tmpfiles.d/postgresql.conf systemd-tmpfiles-setup.service will create /run/postgresql/ when systemd is installed in the container.
Additional Information
Note that this is a very simplified example just demonstrating the core basics of the concept. Normally a persistent volume would be used for the data store. Also, once the container is terminated, the volatile /run/ directory is lost.
docker run -it registry.suse.com/bci/bci-base:15.5 /bin/bash -c \ 'zypper -n in sudo postgresql-server; \ install -d /run/postgresql -m 1775 -g postgres -o postgres;\ sudo -u postgres pg_ctl init -D /var/lib/pgsql; \ sudo -u postgres pg_ctl -D /var/lib/pgsql start'Another simplified example is building an image with the PostgreSQL server installed and database initialised. In this case /run/postgresql is preserved for the subsequent instantiations of the image.
Content of Dockerfile :
FROM registry.suse.com/bci/bci-base:15.5
RUN zypper -n in postgresql-server sudo
RUN install -d /run/postgresql -m 1775 -g postgres -o postgres
RUN sudo -u postgres pg_ctl init -D /var/lib/pgsql
ENTRYPOINT sudo -u postgres pg_ctl -D /var/lib/pgsql start && sleep infinity
Build a named image from the Dockerfile :
# docker build -t pg_image . ... Successfully built 92c45077517a Successfully tagged pg_image:latestRun a container from the image :
# docker run -it pg_image waiting for server to start....2024-03-15 11:10:31.413 UTC [11]LOG: redirecting log output to logging collector process 2024-03-15 11:10:31.413 UTC [11]HINT: Future log output will appear in directory "log". done server started
Disclaimer
This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.
- Document ID:000021398
- Creation Date: 12-Mar-2024
- Modified Date:15-Mar-2024
-
- SUSE Linux Enterprise Server
For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com