gpt4 book ai didi

ruby-on-rails - 优胜美地意外关闭后 Postgres 服务器未启动

转载 作者:行者123 更新时间:2023-11-29 12:37:03 29 4
gpt4 key购买 nike

我正在尝试启动 Rails 服务器,但出现此错误...

/Users/kweihe/.rvm/gems/ruby-2.1.6/gems/activerecord-3.2.22/lib/active_record/connection_adapters/postgresql_adapter.rb:1222:in `initialize': could not connect to server: Connection refused (PG::ConnectionBad)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?

如果我检查我的 postgres 服务器进程,我会得到这个 ...

kweihe-mac:pmpaware-webapp kweihe$ ps auxw | grep postgres
kweihe 11687 0.0 0.0 2432772 636 s000 S+ 10:56AM 0:00.00 grep postgres

所以我尝试了以下...

kweihe-mac:pmpaware-webapp kweihe$  rm -rf /usr/local/var/postgres
kweihe-mac:pmpaware-webapp kweihe$ initdb /usr/local/var/postgres
The files belonging to this database system will be owned by user "kweihe".
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 ... initdb: could not change permissions of directory "/usr/local/var/postgres": Operation not permitted
kweihe-mac:pmpaware-webapp kweihe$ chmod 0700 /usr/local/var/postgres
chmod: Unable to change file mode on /usr/local/var/postgres: Operation not permitted

然后我检查了权限...

kweihe-mac:pmpaware-webapp kweihe$ cd /usr/local/var/
kweihe-mac:var kweihe$ ls -l
total 0
drwxr--r-- 2 root admin 68 Jul 22 10:59 postgres
kweihe-mac:var kweihe$

并尝试启用所有权限...

kweihe-mac:var kweihe$ chmod 777 postgres
chmod: Unable to change file mode on postgres: Operation not permitted

然后我就差点用这个...

kweihe-mac:pmpaware-webapp kweihe$ rm -rf /usr/local/var/postgres
kweihe-mac:pmpaware-webapp kweihe$ initdb /usr/local/var/postgres -E utf8
The files belonging to this database system will be owned by user "kweihe".
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".

Data page checksums are disabled.

creating directory /usr/local/var/postgres ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in /usr/local/var/postgres/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 11413) running in data directory "/usr/local/var/postgres"?
child process exited with exit code 1
initdb: removing data directory "/usr/local/var/postgres"
could not remove file or directory "/usr/local/var/postgres": Directory not empty
initdb: failed to remove data directory

最佳答案

看起来问题是正在运行的 launchctl 进程取决于 /usr/local/var/postgres。就我而言,解决方案是用

停止它

launchctl 卸载 ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

完成(删除目录,以防之前部分创建)

rm -rf /usr/local/var/postgres
initdb /usr/local/var/postgres

关于ruby-on-rails - 优胜美地意外关闭后 Postgres 服务器未启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31566974/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com