【发布时间】:2015-10-12 13:19:35
【问题描述】:
我正在尝试启动 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
【问题讨论】:
标签: ruby-on-rails postgresql permissions server rails-postgresql