【问题标题】:Failure to run postgresql on Mac (after reboot)在 Mac 上运行 postgresql 失败(重启后)
【发布时间】:2014-08-03 19:51:56
【问题描述】:

无论我做什么,重启后我都无法在 Mac 10.9.3 上再次启动 postgresql 9.2。

$ initdb -D /usr/local/var/postgres
The files belonging to this database system will be owned by user "alex".
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: directory "/usr/local/var/postgres" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/usr/local/var/postgres" or run initdb
with an argument other than "/usr/local/var/postgres"

我决定我应该在其中创建另一个目录。所以我在那里创建了数据目录并再次运行 initdb:

$ initdb -D /usr/local/var/postgres/data
The files belonging to this database system will be owned by user "alex".
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.

fixing permissions on existing directory /usr/local/var/postgres/data ... initdb: 
  could not change permissions of directory "/usr/local/var/postgres/data": 
   Operation not permitted

我尝试更改权限,但不知道什么是正确的。这是我所拥有的:

$ ls -ald /usr/local/var/postgres
drwxr-xr-x  22 _postgres  staff  748 Jun 13 17:26 /usr/local/var/postgres

ls -ald /usr/local/var/postgres/data
drwxr-xr-x  2 _postgres  staff  68 Jun 13 17:26 /usr/local/var/postgres/data


$ ls -al /usr/local/var/postgres
total 96
drwxr-xr-x  22 _postgres  staff        748 Jun 13 17:26 .
drwx------   3 alex       admin        102 Jun  1 15:08 ..
-rw-------   1 _postgres  _postgres      4 Jun  1 15:08 PG_VERSION
drwx------   6 _postgres  _postgres    204 Jun  2 11:40 base
drwxr-xr-x   2 _postgres  staff         68 Jun 13 17:26 data
drwx------  42 _postgres  _postgres   1428 Jun  2 14:18 global
drwx------   3 _postgres  _postgres    102 Jun  1 15:08 pg_clog
-rw-------   1 _postgres  _postgres   4465 Jun  2 10:58 pg_hba.conf
-rw-------   1 _postgres  _postgres   1636 Jun  1 15:08 pg_ident.conf
drwx------   4 _postgres  _postgres    136 Jun  1 15:08 pg_multixact
drwx------   3 _postgres  _postgres    102 Jun  1 18:24 pg_notify
drwx------   2 _postgres  _postgres     68 Jun  1 15:08 pg_serial
drwx------   2 _postgres  _postgres     68 Jun  1 15:08 pg_snapshots
drwx------   7 _postgres  _postgres    238 Jun  2 21:23 pg_stat
drwx------   2 _postgres  _postgres     68 Jun  2 21:23 pg_stat_tmp
drwx------   3 _postgres  _postgres    102 Jun  1 15:08 pg_subtrans
drwx------   2 _postgres  _postgres     68 Jun  1 15:08 pg_tblspc
drwx------   2 _postgres  _postgres     68 Jun  1 15:08 pg_twophase
drwx------   4 _postgres  _postgres    136 Jun  1 15:08 pg_xlog
-rw-------   1 _postgres  _postgres  20571 Jun  1 15:08 postgresql.conf
-rw-------   1 _postgres  _postgres     79 Jun  1 18:24 postmaster.opts
-rw-------   1 _postgres  _postgres   1482 Jun  2 21:23 server.log

接下来我该怎么做?我没主意了。唯一的猜测是它与文件或文件夹权限有关。

【问题讨论】:

  • initdb 不会启动 postgres,它会从头开始创建数据目录。当它已经存在时,作为防止清除以前数据的保护措施,这将失败。
  • 当 postgres 无法启动时,它会发出错误消息来说明原因。您想阅读这些消息。

标签: linux macos postgresql permissions postgresql-9.2


【解决方案1】:

两步流程:

  1. 转到您的网络浏览器并搜索“postgresql 权限数据目录” - 从官方手册中查看该页面的列表(对我来说这是最上面的)。
  2. 阅读page from the official manuals 并按照说明进行操作。

大概是在抱怨它“无法更改权限”,因为您没有以用户“_postgres”的身份运行它。注意 - 它通常是用户“postgres”。我不知道改名是你做过的事情还是 Mac 安装中常见的事情。

哦 - 我不明白为什么这被标记为“linux”

【讨论】:

  • 让我检查一下。它是 linux,因为它不是 mac ox 特定的问题。
  • 在 linux 上你可能会使用基于包的东西。例如,Debian 有它的多安装版本包装器pg-createcluster
  • 文档中的这个页面解决了它postgresql.org/docs/current/static/creating-cluster.html
猜你喜欢
  • 1970-01-01
  • 2012-01-14
  • 2013-01-08
  • 2018-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多