首页 > 解决方案 > postgresql 未安装,但自制报告它是

问题描述

我以前从未遇到过这样的问题-通常可以正常brew install postgres工作,一切都很好。

我在这台机器上遇到过“Mac OSX 由于出现问题而重新启动”的实例,通常有一个陈旧的postmaster.pid文件,我可以删除并重新启动 postgresql,一切都很好。

不再 - 有一些不正常的东西,我不知道自制软件如何工作得足够好来解决这个问题。

➜  ~ pg_ctl
zsh: command not found: pg_ctl
➜  ~ brew info postgresql
postgresql: stable 13.1 (bottled), HEAD
Object-relational database system
https://www.postgresql.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/postgresql.rb
License: PostgreSQL
==> Dependencies
Build: pkg-config ✔
Required: icu4c ✔, krb5 ✔, openssl@1.1 ✔, readline ✔
==> Options
--HEAD
    Install HEAD version
==> Caveats
To migrate existing data from a previous major version of PostgreSQL run:
  brew postgresql-upgrade-database

This formula has created a default database cluster with:
  initdb --locale=C -E UTF-8 /usr/local/var/postgres
For more details, read:
  https://www.postgresql.org/docs/13/app-initdb.html

To have launchd start postgresql now and restart at login:
  brew services start postgresql
Or, if you don't want/need a background service you can just run:
  pg_ctl -D /usr/local/var/postgres start
==> Analytics
install: 188,386 (30 days), 549,953 (90 days), 1,863,554 (365 days)
install-on-request: 180,714 (30 days), 528,971 (90 days), 1,789,016 (365 days)
build-error: 0 (30 days)
➜  ~ ls -ltra /usr/local/var
total 0
drwxrwxr-x   4 myhandle  admin  128 Aug 21  2019 homebrew
drwxr-xr-x   4 myhandle  admin  128 Apr 18  2020 log
drwxr-xr-x  15 root   wheel  480 Dec  1 17:32 ..
drwxrwxr-x   4 root   wheel  128 Dec  2 08:56 .

我在这里报告了这个问题 - https://discourse.brew.sh/t/postgress-install-fails-in-postinstall-step/6209

唯一的答案是“我在旧安装上运行了安装脚本”,这对我来说毫无意义——我试着brew postinstall postgres@12想象这就是“旧安装”的意思,但我得到了完全相同的结果:

➜  ~ brew postinstall postgresql
==> Postinstalling postgresql
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall postgresql`
➜  ~ brew postinstall postgresql@12
==> Postinstalling postgresql@12
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall postgresql@12`

有任何想法吗?

更新:我开始感觉 /usr/local/var 和 /usr/local/bin 被我、自制软件或 postgres 桶弄糊涂了,因为错误消息与现实不符:

➜  ~ pg_ctl -D /usr/local/var/postgres start
pg_ctl: directory "/usr/local/var/postgres" does not exist
➜  ~ pg_ctl -D /usr/local/bin/postgres start
pg_ctl: could not open PID file "/usr/local/bin/postgres/postmaster.pid": Not a directory
➜  ~ mkdir /usr/local/bin/postgres
mkdir: /usr/local/bin/postgres: File exists

为什么自制软件建议从 /usr/local/var 运行 pg_ctl 但全新安装后此处不存在 postgres 进程?为什么我会在 /usr/local/bin 中找到它?然后,当我尝试从 bin/ 启动时,它要求 bin/ 中的 postmaster.pid 文件,但 bin/ 中当然没有 postgres 目录,因为这些是进程本身...

标签: postgresqlmacoshomebrew

解决方案


我已经运行了这些步骤,postgresql 已经开始工作了——我承认这是一个“幸运胜于好事”的案例,因为我只是在这里暗中刺伤——

➜  ~ sudo mkdir /usr/local/var/postgres
➜  ~ sudo chown -R `whoami` /usr/local/var/postgres
➜  ~ initdb -D /usr/local/var/postgres
The files belonging to this database system will be owned by user "tyler".
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 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... America/Chicago
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /usr/local/var/postgres -l logfile start

➜  ~ brew services restart postgresql
Stopping `postgresql`... (might take a while)
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)

➜  ~ brew postinstall postgresql
==> Postinstalling postgresql
Success

然后我可以回到 Rails-world 并正确迁移数据库 - 我推测这意味着 homebrew 安装步骤(可能是一直失败的 postinstall 步骤)没有创建 /usr/local/var/postgres 目录,因为它应该有,或者它正在尝试没有足够的权限这样做并且默默地失败。

一旦我手动创建了目录并对其进行了更改,事情就开始按应有的方式工作。


推荐阅读