【问题标题】:Systemd cannot start Postgresql on Red Hat EL7Systemd 无法在 Red Hat EL7 上启动 Postgresql
【发布时间】:2023-08-26 00:26:01
【问题描述】:

在 Red Hat EL7 上,我从标准存储库安装了 Postgres,并以通常的方式初始化了数据库:

# postgresql-setup initdb

但是当我尝试启动服务时:

# systemctl start postgresql.service

我收到一个错误:

Job for postgresql.service failed. See 'systemctl status postgresql.service' and 'journalctl -xn' for details.

journalctl -xn 给我:

Oct 06 14:52:55 myserver systemd[1]: Starting PostgreSQL database server...
-- Subject: Unit postgresql.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit postgresql.service has begun starting up.
Oct 06 14:52:55 myserver systemd[29267]: Failed at step USER spawning /usr/bin/postgresql-check-db-dir: No such process
-- Subject: Process /usr/bin/postgresql-check-db-dir could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- The process /usr/bin/postgresql-check-db-dir could not be executed and failed.
-- 
-- The error number returned while executing this process is 3.

有人有什么想法吗?

【问题讨论】:

  • 检查 PostgreSQL 日志以查看 PostgreSQL 是否报告了更多详细信息。
  • 没有 Postgres 日志,因为在调用 pg_ctl 之前发生了故障。

标签: postgresql redhat systemd


【解决方案1】:

我不认为这是一个完整且适当的修复,但我称之为“强大的解决方法”。问题似乎始于这个 Linux 系统可以在本地以及通过目录服务器进行身份验证这一事实。 PostgreSQL 包尝试创建一个名为 postgres:postgres 的 user:group 组合。未创建用户“postgres”,因为它已存在于目录服务器中。 “postgres”组是在本地创建的。

当 systemd 启动 Postgres 时,它会在尝试调用 postgresql-check-db-dir 之前更改为 postgres 用户,这是一个检查数据库目录是否已使用 postgresql-setup initdb 初始化的脚本。 systemd 似乎无法更改为此目录提供的 postgres 用户。

我的解决方法是创建一个新的本地用户(“pgsql”)并将 /var/lib/pgsql 和 /var/run/postgresql 的所有权更改为这个新用户,然后创建一个名为的自定义 systemd 服务文件/etc/systemd/system/postgresql.service 覆盖默认值。这个文件的内容是:

.include /usr/lib/systemd/system/postgresql.service

[Service]
User=pgsql
Group=postgres

这允许通过 systemd 启动和停止 Postgres。

【讨论】:

    【解决方案2】:

    对我来说,日志告诉您数据库路径不存在。您确定 psql 配置正确,数据库路径存在并且您有权访问它吗?

    【讨论】:

      最近更新 更多