安装 PostgreSQL
1.安装 PostgreSQL
sudo yum install -y postgresql postgresql-server
root@localhost ~]# systemctl status postgresql.service
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2024-12-11 14:09:49 CST; 6s ago
Process: 64216 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=1/FAILURE)
12月 11 14:09:49 localhost.localdomain systemd[1]: Starting PostgreSQL database server...
12月 11 14:09:49 localhost.localdomain postgresql-check-db-dir[64216]: Directory "/var/lib/pgsql/data" is missing or empty.
12月 11 14:09:49 localhost.localdomain postgresql-check-db-dir[64216]: Use "/usr/bin/postgresql-setup --initdb"
12月 11 14:09:49 localhost.localdomain postgresql-check-db-dir[64216]: to initialize the database cluster.
12月 11 14:09:49 localhost.localdomain postgresql-check-db-dir[64216]: See /usr/share/doc/postgresql/README.rpm-dist for more information.
12月 11 14:09:49 localhost.localdomain systemd[1]: postgresql.service: Control process exited, code=exited status=1
12月 11 14:09:49 localhost.localdomain systemd[1]: postgresql.service: Failed with result 'exit-code'.
12月 11 14:09:49 localhost.localdomain systemd[1]: Failed to start PostgreSQL database server.
出现这个错误是因为 PostgreSQL 的数据目录 /var/lib/pgsql/data 不存在或为空。要解决这个问题,需要初始化数据库集群。
按照以下步骤修复问题:
步骤 1:初始化 PostgreSQL 数据目录
执行初始化命令:
[root@localhost ~]# sudo /usr/bin/postgresql-setup --initdb
* Initializing database in '/var/lib/pgsql/data'
* Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log
这将初始化 PostgreSQL 的数据目录。
步骤 2:启动 PostgreSQL 服务
启动服务:
sudo systemctl start postgresql.service
检查服务状态:
sudo systemctl status postgresql.service
设置服务开机自启动:
sudo systemctl enable postgresql.service
步骤 3 :创建数据库和用户
sudo -i -u postgres
psql
在 PostgreSQL shell 中运行以下命令:
CREATE DATABASE confluence;
CREATE USER confluence_user WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE confluence TO confluence_user;
ALTER ROLE confluence_user WITH LOGIN;
\q
exit
步骤 4:配置允许远程连接
编辑/var/lib/pgsql/data/pg_hba.conf,添加:
host all all 0.0.0.0/0 md5
编辑 /var/lib/pgsql/data/postgresql.conf,修改:
listen_addresses = '*'
重启服务:
sudo systemctl restart postgresql
原文地址:https://blog.csdn.net/qq_40914472/article/details/144400994
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!