macos - 无法找出 Mac OS X 中 PostgreSQL 的数据目录

标签 macos postgresql

我在 Mac OS X 10.9.3 上通过自制程序安装了 PostgreSQL 9.3。当我第一次安装它时,它运行得很好。重启后它碰巧没有启动,我不知道如何通过 pg_ctl 启动它,因为我找不到它的数据目录是什么:

$ pg_ctl start
pg_ctl: no database directory specified and environment variable PGDATA unset
Try "pg_ctl --help" for more information.

$ pwd
/usr/local/var/postgres

$ ls -al
total 96
drwx------  21 alex  admin    714 Jun  2 21:23 .
drwx------   3 alex  admin    102 Jun  1 15:08 ..
-rw-------   1 alex  admin      4 Jun  1 15:08 PG_VERSION
drwx------   6 alex  admin    204 Jun  2 11:40 base
drwx------  42 alex  admin   1428 Jun  2 14:18 global
drwx------   3 alex  admin    102 Jun  1 15:08 pg_clog
-rw-------   1 alex  admin   4465 Jun  2 10:58 pg_hba.conf
-rw-------   1 alex  admin   1636 Jun  1 15:08 pg_ident.conf
drwx------   4 alex  admin    136 Jun  1 15:08 pg_multixact
drwx------   3 alex  admin    102 Jun  1 18:24 pg_notify
drwx------   2 alex  admin     68 Jun  1 15:08 pg_serial
drwx------   2 alex  admin     68 Jun  1 15:08 pg_snapshots
drwx------   7 alex  admin    238 Jun  2 21:23 pg_stat
drwx------   2 alex  admin     68 Jun  2 21:23 pg_stat_tmp
drwx------   3 alex  admin    102 Jun  1 15:08 pg_subtrans
drwx------   2 alex  admin     68 Jun  1 15:08 pg_tblspc
drwx------   2 alex  admin     68 Jun  1 15:08 pg_twophase
drwx------   4 alex  admin    136 Jun  1 15:08 pg_xlog
-rw-------   1 alex  admin  20571 Jun  1 15:08 postgresql.conf
-rw-------   1 alex  admin     79 Jun  1 18:24 postmaster.opts
-rw-------   1 alex  admin   1482 Jun  2 21:23 server.log

/Library中没有任何标题为PostgreSQL之类的内容。

如何找到它?

更新:

$ sudo chown -R _postgres /usr/local/var/postgres
$ ls -ld /usr/local/var/postgres
drwx------  21 _postgres  admin  714 Jun  2 21:23 /usr/local/var/postgres

#################

$ sudo -u _postgres pg_ctl -D /usr/local/var/postgres -w start
could not identify current directory: Permission denied
pg_ctl: could not open PID file "/usr/local/var/postgres/postmaster.pid": Permission denied

$ ls -al /usr/local/var/postgres/postmaster.pid
ls: /usr/local/var/postgres/postmaster.pid: Permission denied

$ sudo ls -al /usr/local/var/postgres/postmaster.pid
ls: /usr/local/var/postgres/postmaster.pid: No such file or directory

最佳答案

pg_ctl 不会在当前目录中查找 datadir。您必须使用 PGDATA 环境变量或 -D 命令行参数来指定它。

启动:

sudo -u postgres pg_ctl -D /usr/local/var/postgres -w start

但是,您确实应该对其进行设置以开始使用launchd。 AFAIK 它包含在 Homebrew 文档中。

关于macos - 无法找出 Mac OS X 中 PostgreSQL 的数据目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24132418/

相关文章:

r - 使用 R 在 SQL 中查询混合大小写列

postgresql - 在 postgresql 9.3 中更新多列的问题

sql - 更新 postgreSQL 首字母大写的列

mysql - 终端无法识别 mysqld 和 mysql 命令

macos - NSFileManager 'copyItemAtPath:' 创建隔离文件副本

java - JTextArea 不显示 native 字体表情符号

postgresql - 如何使用 PSQL 中相同 ID 的最后填充来填充空值?

python - 如何在 SQLAlchemy 中将两列 ARRAY_AGG 合并为一项?

r - Mac OS X R 错误 "ld: warning: directory not found for option"

python - 升级到 OS X Yosemite 后 pip 不起作用