/var/lib/postgres/data存在但不为空

/var/lib/postgres/data exists but is not empty

我最近开始使用 arch。 (拱形版本 5.6.4)。

我通过 运行ning 安装了 postgresql:

sudo pacman -S postgresql

我正在按照 archwiki 指南初始化数据库集群。我通过 运行ning

切换到 postgres 用户
sudo -iu postgres

之后,我运行:

initdb -D /var/lib/postgres/data

我得到以下输出:

[postgres@archlinux ~]$ initdb -D /var/lib/postgres/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

initdb: error: directory "/var/lib/postgres/data" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/var/lib/postgres/data" or run initdb
with an argument other than "/var/lib/postgres/data".

我认为删除数据中的所有内容并不明智,所以我创建了一个目录 /home/user/postgres/data。创建此目录后,我将 postgres 作为其用户。

我在 运行 初始化 initdb 时仍然遇到权限错误。我什至更改了权限以允许读取、写入、执行,但我无法通过权限错误。

帮忙?

我自己修好了。只需删除 postgres/data 和 运行 initdb.

中的所有内容

我通过 运行 以下命令解决了这个问题:

sudo mkdir /var/lib/postgres/data

sudo chown postgres:postgres /var/lib/postgres/data

sudo -u postgres initdb -D /var/lib/postgres/data

我通过删除文件和以下回复 1 中提到的命令来做到这一点。我 运行,逐步执行这些命令:

sudo rm -rf /var/lib/postgres/data

sudo mkdir /var/lib/postgres/data

sudo chown postgres:postgres /var/lib/postgres/data

sudo -u postgres initdb -D /var/lib/postgres/data