重新启动postgresql服务失败,因为”/var/lib/pgsql/data”文件夹不存在或为空

首先

CentOS7上安装了PostgreSQL,并且在重新启动PostgreSQL服务后发生了失败,所以我写了一篇文章记录了这个问题。

PostgreSQL重新启动失败。

[root@localhost ~]# systemctl restart postgresql
Job for postgresql.service failed because the control process exited with error code. See "systemctl status postgresql.service" and "journalctl -xe" for details.

请确认详细的错误信息

[root@localhost ~]# journalctl -xe
11月 26 20:23:44 localhost.localdomain systemd[1]: Starting PostgreSQL database server...
-- Subject: Unit postgresql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit postgresql.service has begun starting up.
11月 26 20:23:44 localhost.localdomain postgresql-check-db-dir[9979]: "/var/lib/pgsql/data" is missing or empty.
11月 26 20:23:44 localhost.localdomain postgresql-check-db-dir[9979]: Use "postgresql-setup initdb" to initialize the database cluster.
11月 26 20:23:44 localhost.localdomain postgresql-check-db-dir[9979]: See /usr/share/doc/postgresql-9.2.24/README.rpm-dist for more informat
11月 26 20:23:44 localhost.localdomain polkitd[652]: Unregistered Authentication Agent for unix-process:9972:400235 (system bus name :1.30,
11月 26 20:23:44 localhost.localdomain systemd[1]: postgresql.service: control process exited, code=exited status=1
11月 26 20:23:44 localhost.localdomain systemd[1]: Failed to start PostgreSQL database server.
-- Subject: Unit postgresql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit postgresql.service has failed.
--
-- The result is failed.

我在寻找PostgreSQL的初始设置脚本。

我参考了以下网站:
https://www.postgresql.jp/document/9.4/html/app-initdb.html
https://qiita.com/LowSE01/items/84af05449f96dedd0edc

据说在安装完PostgreSQL之后需要进行数据库的初始设置。
由于根据环境的不同,可能会有不同名称的PostgreSQL初始设置脚本,因此我使用了find命令进行了搜索。

[root@localhost ~]# find / -name postgresql*
/run/postgresql
/sys/fs/selinux/booleans/postgresql_selinux_unconfined_dbadm
/sys/fs/selinux/booleans/postgresql_selinux_transmit_client_label
/sys/fs/selinux/booleans/postgresql_selinux_users_ddl
/sys/fs/selinux/booleans/postgresql_can_rsync
/etc/selinux/targeted/active/modules/100/postgresql
/etc/pam.d/postgresql
/usr/bin/postgresql-check-db-dir
/usr/bin/postgresql-setup  ←みつかりました。
/usr/lib/systemd/system/postgresql.service
/usr/lib/tmpfiles.d/postgresql.conf
/usr/lib/firewalld/services/postgresql.xml
/usr/share/doc/postgresql-libs-9.2.24
/usr/share/doc/postgresql-9.2.24
/usr/share/man/man1/postgresql-setup.1.gz
/usr/share/pgsql/postgresql.conf.sample
/usr/libexec/initscripts/legacy-actions/postgresql

我执行了postgresql-setup。

[root@localhost ~]# postgresql-setup initdb
Initializing database ... OK

PostgreSQL的重新启动已成功。

# systemctl restart postgresql

我已经确认了PostgreSQL服务的状态。

[root@localhost ~]# systemctl status postgresql
● postgresql.service - PostgreSQL database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled)
   Active: active (running) since 日 2023-11-26 20:28:03 JST; 7s ago
  Process: 10280 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=0/SUCCESS)
  Process: 10274 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 10283 (postgres)
   CGroup: /system.slice/postgresql.service
           tq10283 /usr/bin/postgres -D /var/lib/pgsql/data -p 5432
           tq10284 postgres: logger process
           tq10286 postgres: checkpointer process
           tq10287 postgres: writer process
           tq10288 postgres: wal writer process
           tq10289 postgres: autovacuum launcher process
           mq10290 postgres: stats collector process

11月 26 20:28:02 localhost.localdomain systemd[1]: Starting PostgreSQL database server...
11月 26 20:28:03 localhost.localdomain systemd[1]: Started PostgreSQL database server.
广告
将在 10 秒后关闭
bannerAds