Ada*_*amT 87 macbook database postgresql homebrew macos
我刚刚通过以下方式重新安装了 postgres brew install postgres
我跑了initdb /usr/local/var/postgres -E utf8
但得到了这个:
The files belonging to this database system will be owned by user "atal421".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default text search configuration will be set to "english".
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".
Run Code Online (Sandbox Code Playgroud)
所以,我rm -rf
打开 postgres 文件夹并再次运行它:
initdb /usr/local/var/postgres -E utf8
Run Code Online (Sandbox Code Playgroud)
它说一切正常:
Success. You can now start the database server using:
postgres -D /usr/local/var/postgres
Run Code Online (Sandbox Code Playgroud)
所以,我运行该命令并得到:
postgres -D /usr/local/var/postgres
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 13731) running in data directory "/usr/local/var/postgres"?
Run Code Online (Sandbox Code Playgroud)
现在,当我查看活动监视器时,可以看到 6 个 postgress 实例。
我该如何解决?
Cra*_*ger 135
公益告示:永不删帖postmaster.pid
。真的。获得数据损坏的好方法。
您已经安装了 PostgreSQL,并且在没有停止正在运行的服务器的情况下删除了数据目录。因此,您现在有一些孤立的 PostgreSQL 服务器进程正在管理已删除的数据文件,因此它们在文件系统中不再可访问,并且在最后打开的文件句柄关闭时将被完全删除。您不能pg_ctl
像往常一样关闭服务器,因为您已经删除了集群数据目录,因此您必须简单地终止进程。杀死邮政局长(千万不能使用kill -9
,只是一个普通的杀都行),其余的将关停了。
然后,您将能够在 datadir 中针对新initdb
的数据启动一个新服务器。
除非您卸载其他旧版本的 PostgreSQL,否则很可能会遇到冲突。
简而言之:
cat /usr/local/var/postgres/postmaster.pid
记下第一行的数字,即邮局局长的pid。
验证ps
pid 是否为 postgres 邮局管理员的 pid。
使用以下命令终止 postmaster 进程,将“PID”替换为您记下的数字。同样,不要使用kill -9
or kill -KILL
,只使用普通的kill
,即 aSIGTERM
:
kill PID
如果 pid 不是 postgres postmaster 的 pid,手动kill
任何postgres
可能仍在运行的后端,验证它们不再运行,然后才删除postmaster.pid
. (您还必须验证postmaster.pid
不在共享存储上,服务器可以在其他 VM/主机上运行)。
Ale*_*fee 59
另一种可能性是您硬关机并且 postgres 进程在没有清理其 pid 文件的情况下死亡。当我的笔记本电脑的电池没电时,就会发生这种情况。
此解决方案不适用于生产系统,您确实应该确保 postgres 守护程序没有运行,但我使用笔记本电脑进行编码,而且我不担心需要重新生成我的数据库。
因此,如果另一个进程——或者根本没有——正在该端口上运行,只需删除 pid 文件,例如
rm /usr/local/var/postgres/postmaster.pid
Run Code Online (Sandbox Code Playgroud)
并且 postgres 很快就会正常启动。
要找出另一个进程是否正在该端口上运行,您可以执行以下操作
ps wax | grep `head -1 /usr/local/var/postgres/postmaster.pid`
Run Code Online (Sandbox Code Playgroud)
然后运行
tail -f /usr/local/var/postgres/server.log
Run Code Online (Sandbox Code Playgroud)
看看它是否有效。你应该看到
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 933) running in data directory "/usr/local/var/postgres"?
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 933) running in data directory "/usr/local/var/postgres"?
LOG: database system was interrupted; last known up at 2014-05-25 09:41:32 PDT
LOG: database system was not properly shut down; automatic recovery in progress
Run Code Online (Sandbox Code Playgroud)
(或者至少这是我在完成上述操作后才看到的:-))
(实际上,Postgres 不应该足够聪明以意识到没有 PID 为 933 的进程并自行删除伪造的 pid 文件吗?)
小智 8
升级到优胜美地后,我尝试了所有这些都无济于事,破坏了我的 postgres(通过自制软件安装)。
然后我偶然发现了这篇博文:http : //ruckus.tumblr.com/post/100355276496/yosemite-upgrade-breaks-homebrew-installed-postgres
首先,我需要创建在升级过程中显然被清除的丢失目录(感谢 Apple!)。
$ cd /usr/local/var/postgres
$ mkdir {pg_tblspc,pg_twophase,pg_stat_tmp}
Run Code Online (Sandbox Code Playgroud)
然后使用正常的自制启动顺序再次启动 postgres:
$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Run Code Online (Sandbox Code Playgroud)
感谢 Ruckus Notes 帮助解决我的问题。希望它也能帮助你。
小智 6
硬重启后我遇到了同样的问题。检查postmaster.pid
文件的 pid 后,我发现没有进程在运行。我不想硬删除 .pid 文件,而是使用了pg-stop
在 .pid 文件中创建的别名.bash_profile
。这个别名刚刚运行
pg_ctl -D /usr/local/var/postgres stop -s -m fast
# psql
alias pg-start='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start'
alias pg-stop='pg_ctl -D /usr/local/var/postgres stop -s -m fast'
Run Code Online (Sandbox Code Playgroud)
pg-stop
LOG: database system was interrupted; last known up at 2016-04-25 10:51:08 PDT
LOG: database system was not properly shut down; automatic recovery in progress
LOG: record with zero length at 0/274FA10
LOG: redo is not required
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
LOG: received smart shutdown request
LOG: autovacuum launcher shutting down
LOG: shutting down
LOG: database system is shut down
LOG: database system was shut down at 2016-04-25 13:11:04 PDT
Run Code Online (Sandbox Code Playgroud)
我想我还应该在这里提到,如果你已经用自制软件安装了 postgres,你应该看brew services
一下。这就是我现在更喜欢启动/停止数据库的方式。
XXXXX:~ chris$ brew services list
Name Status User Plist
mongodb stopped
postgresql started chris /Users/chris/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
redis started chris /Users/chris/Library/LaunchAgents/homebrew.mxcl.redis.plist
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
122155 次 |
最近记录: |