【问题标题】:/var/lib/postgres/data exists but is not empty/var/lib/postgres/data 存在但不为空
【发布时间】:2020-04-19 11:08:01
【问题描述】:

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

我通过运行安装了 postgresql:

sudo pacman -S postgresql

我正在按照 archwiki 指南来初始化数据库集群。我通过运行切换到 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 时仍然遇到权限错误。我什至更改了权限以允许读取、写入、执行,但我无法通过权限错误。

帮助?

【问题讨论】:

  • 如果您遇到错误,请告诉我们。

标签: postgresql archlinux


【解决方案1】:

自己修好了。只需删除 postgres/data 中的所有内容并运行 initdb。

【讨论】:

    【解决方案2】:

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

    sudo mkdir /var/lib/postgres/data
    
    sudo chown postgres:postgres /var/lib/postgres/data
    
    sudo -u postgres initdb -D /var/lib/postgres/data
    

    【讨论】:

      【解决方案3】:

      我通过删除文件和以下回复 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
      

      【讨论】:

      • 它解决了我的问题。谢谢!
      猜你喜欢
      • 2020-10-23
      • 2018-05-30
      • 2018-12-04
      • 1970-01-01
      • 2017-04-25
      • 2019-01-23
      • 2015-01-08
      • 1970-01-01
      • 2020-11-24
      相关资源
      最近更新 更多