Postgresql 13 AlmaLinux Permissions Issue



我正试图让postgresql 13.xAlmaLinux上运行。包管理显示v13.x可用,我安装了postgresql-server:

sudo yum install -y postgresql-server postgresql-contrib

然后尝试初始化第一个db:

sudo postgresql-setup --initdb

因为我必须重做一些东西,这个目录不是空的,然后我遇到权限问题。我试过设置我的帐户所有权,但它也不起作用:

ERROR: Data directory /var/lib/pgsql/data is not empty!
ERROR: Initializing database failed, possibly see /var/lib/pgsql/initdb_postgresql.log
[Wed Jun 29 18:31:40 rich@server1 /var/lib] cd pgsql
-bash: cd: pgsql: Permission denied
[Wed Jun 29 18:31:50 rich@server1 /var/lib] sudo ls -al pgsql/data
total 60
drwx------. 20 postgres postgres  4096 May 26 11:53 .
drwx------.  4 postgres postgres    54 Jun 29 18:27 ..
drwx------.  5 rich     rich        41 Jun 29 11:01 base
-rw-------.  1 rich     rich        30 Jun 29 15:58 current_logfiles
drwx------.  2 rich     rich      4096 Jun 29 11:01 global
drwx------.  2 rich     rich        32 Jun 29 11:02 log
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_commit_ts
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_dynshmem
-rw-------.  1 rich     rich      4760 Jun 29 11:01 pg_hba.conf
-rw-------.  1 rich     rich      1636 Jun 29 11:01 pg_ident.conf
drwx------.  4 rich     rich        68 Jun 29 11:01 pg_logical
drwx------.  4 rich     rich        36 Jun 29 11:01 pg_multixact
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_notify
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_replslot
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_serial
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_snapshots
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_stat
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_stat_tmp
drwx------.  2 rich     rich        18 Jun 29 11:01 pg_subtrans
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_tblspc
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_twophase
-rw-------.  1 rich     rich         3 Jun 29 11:01 PG_VERSION
drwx------.  3 rich     rich        60 Jun 29 11:01 pg_wal
drwx------.  2 rich     rich        18 Jun 29 11:01 pg_xact
-rw-------.  1 rich     rich        88 Jun 29 11:01 postgresql.auto.conf
-rw-------.  1 rich     rich     28098 Jun 29 11:01 postgresql.conf

所以现在我被困在初始化一个新数据库和通过permissions之间。有人知道怎么让它运行吗?

编辑:进一步信息

下面是关于权限问题的报告:

░░ A start job for unit postgresql.service has begun execution.
░░
░░ The job identifier is 2450.
Jun 29 21:28:58 server1.project33.ca postgresql-check-db-dir[2593]: cat: /var/lib/pgsql/data/PG_VERSION: Permission denied
Jun 29 21:28:58 server1.project33.ca postgresql-check-db-dir[2592]: An old version '' of the database format was found.
Jun 29 21:28:58 server1.project33.ca postgresql-check-db-dir[2592]: You need to dump and reload before using PostgreSQL 13.7.
Jun 29 21:28:58 server1.project33.ca postgresql-check-db-dir[2592]: See /usr/share/doc/postgresql/README.rpm-dist for more information.
Jun 29 21:28:58 server1.project33.ca systemd[1]: postgresql.service: Control process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://access.redhat.com/support
░░
░░ An ExecStartPre= process belonging to unit postgresql.service has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 1.
Jun 29 21:28:58 server1.project33.ca systemd[1]: postgresql.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://access.redhat.com/support
░░
░░ The unit postgresql.service has entered the 'failed' state with result 'exit-code'.
Jun 29 21:28:58 server1.project33.ca systemd[1]: Failed to start PostgreSQL database server.
░░ Subject: A start job for unit postgresql.service has failed
░░ Defined-By: systemd
░░ Support: https://access.redhat.com/support
░░
░░ A start job for unit postgresql.service has finished with a failure.
░░
░░ The job identifier is 2450 and the job result is failed.

已解决:sudo postgresql-setup --initdb

/var/lib/pgsql/datapostgresql:postgresql拥有的权限问题。

然后使用postgres用户登录,以:

开头
createdb `whoami`

…创建postgres数据库。在内部,您可以创建roles和数据库,或者退出到您的用户并再次使用createdb语法。

最新更新