说明:记录一次在Linux上启动postgres数据错误;
问题:安装好postgres数据库后,我使用systemctl
启动数据库,报下面的错误
● postgresql-15.service - PostgreSQL 15 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-15.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2024-07-23 09:36:20 CST; 1min 51s ago
Docs: https://www.postgresql.org/docs/15/static/
Process: 22364 ExecStart=/usr/pgsql-15/bin/postmaster -D ${PGDATA} (code=exited, status=1/FAILURE)
Process: 22358 ExecStartPre=/usr/pgsql-15/bin/postgresql-15-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 22364 (code=exited, status=1/FAILURE)
Jul 23 09:36:20 MyECS systemd[1]: Starting PostgreSQL 15 database server...
Jul 23 09:36:20 MyECS postmaster[22364]: 2024-07-23 09:36:20.511 CST [22364] FATAL: data directory "/var/lib/pgsql/15/data" has invalid permissions
Jul 23 09:36:20 MyECS postmaster[22364]: 2024-07-23 09:36:20.511 CST [22364] DETAIL: Permissions should be u=rwx (0700) or u=rwx,g=rx (0750).
Jul 23 09:36:20 MyECS systemd[1]: postgresql-15.service: main process exited, code=exited, status=1/FAILURE
Jul 23 09:36:20 MyECS systemd[1]: Failed to start PostgreSQL 15 database server.
Jul 23 09:36:20 MyECS systemd[1]: Unit postgresql-15.service entered failed state.
Jul 23 09:36:20 MyECS systemd[1]: postgresql-15.service failed.
截图如下:
解决:看描述,像是存放数据的文件夹有无法的权限,敲下面的命令(问我怎么来的,通义告诉我的),修改文件夹权限
sudo chmod 0700 /var/lib/pgsql/15/data
修改前后的权限比较,如下,修改后再启动就没问题了