在我安装 Mavericks 之后,我的 postgres 配置似乎完全困惑了。我从 xcode 安装了 Maverick 的开发工具,我尝试将 host:localhost 放在 db yml 中,但如果我尝试运行 rails s:
could not connect to server: No such file or directory (PGError)
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
如果我尝试手动启动 postgres:
pg_ctl -D/usr/local/var/postgres -l/usr/local/var/postgres/server.log 开始
我得到:服务器启动
但是 pg_ctl -D/usr/local/var/postgres status
返回 pg_ctl: no server running
??
我尝试重新安装 pg gem 并重新加载 postgresql 但无济于事。 brew info postgres
返回:
postgresql: stable 9.3.1
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.3.1 (2919 files, 39M) *
因为我做了 brew reinstall postgress 我知道得到这个:
The data directory was initialized by PostgreSQL version 9.2,
which is not compatible with this version 9.3.1.
我有一个 postgres 查询工具,它似乎没有任何连接问题,所以我知道数据仍然存在。
如果有人能帮我解决这个问题,我将不胜感激,谢谢。
最佳答案
错误 数据目录由 PostgreSQL 9.2 版初始化,
与此版本 9.3.1 不兼容。
是由 9.2
和 9.3
之间的不兼容数据目录引起的。
如果您不需要9.2
db中的旧数据,那么解决这个问题就很容易:
rm -rf /usr/local/var/postgres
其中 /usr/local/var/postgres
是默认的数据目录路径。您可能需要根据您的设置更改路径。
删除旧数据目录后,使用 9.3
初始化一个新目录:
initdb /usr/local/var/postgres -E utf8
那么你就可以开始了!
====
如果您需要将旧数据从 9.2
迁移到 9.3
:
a) 重命名您的旧数据目录:
mv /usr/local/var/postgres /usr/local/var/postgres9.2
b) 初始化一个新的 9.3
db(创建一个新的数据目录):
initdb /usr/local/var/postgres -E utf8
c) 迁移:
pg_upgrade \
-b /usr/local/Cellar/postgresql/9.2.4/bin/ \
-B /usr/local/Cellar/postgresql/9.3.1/bin/ \
-d /usr/local/var/postgres9.2 \
-D /usr/local/var/postgres \
-v
-b
是您的旧二进制文件,而 -B
是您的新二进制文件。您可以通过 brew info postgres
获取它们。
-d
是重命名的旧数据目录,而 -D
是您刚刚在 step b
中创建的新数据目录。
然后你会收到如下信息:
Creating script to analyze new cluster ok
Creating script to delete old cluster ok
Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade so,
once you start the new server, consider running:
analyze_new_cluster.sh
Running this script will delete the old cluster's data files:
delete_old_cluster.sh
d) 用你的 postgres 9.3 摇滚吧!
关于ruby-on-rails-3 - OSX Mavericks 后 Postgres 配置搞砸了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19721092/