Back to blog

PostgreSQL Startup Failed: `could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock"`

3/8/2026 · 1 min · Database

Share

PostgreSQL Startup Failed: could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock"

This incident looks simple but often reveals orchestration gaps in production Linux environments.

Incident symptom

sudo systemctl start postgresql

Service fails, and instance log shows:

FATAL: could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": No such file or directory

Root cause

Field troubleshooting workflow

sudo -u postgres /usr/bin/postgres -D /var/lib/pgsql/data
ss -ltnp | grep 5432
ls -ld /var/run/postgresql /run/postgresql 2>/dev/null

Hotfix

sudo mkdir -p /var/run/postgresql
sudo chown postgres:postgres /var/run/postgresql
sudo chmod 775 /var/run/postgresql
sudo systemctl start postgresql

Definitive fix (systemd override)

[Service]
RuntimeDirectory=postgresql
RuntimeDirectoryMode=0775

Apply:

sudo systemctl daemon-reload
sudo systemctl restart postgresql

Optional tmpfiles.d fallback:

d /var/run/postgresql 0775 postgres postgres -

Security note

Use controlled permissions (775/770 as applicable). Avoid 777 on runtime socket paths.

Conclusion

This is not about creating a folder manually. It is about making service runtime idempotent and reboot-safe. Once runtime directory lifecycle is declared properly in systemd, startup becomes predictable and resilient.

CC BY-NC

This post is licensed under CC BY-NC.

Comments

Join the discussion below.