PG :: ConnectionBad升级到Yosemite和postgresql 9.4.4

时间:2015-08-04 21:12:57

标签: macos postgresql rails-4-2-1

我刚刚将我的mac OS X更新为Yosemite,版本10.10.4,并将postgresql更新为:psql(PostgreSQL)9.4.4。

在我的Rails 4.2.1应用程序上运行rake db:migrate后,我的终端会话响应:

rake aborted!
PG::ConnectionBad: 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?
could not connect to server: Connection refused
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?

在终端会话中简单输入psql也会显得有些偏差:

$ psql
psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

从cat /usr/local/var/postgres/server.log中打印出日志后,我读到:

DETAIL:  The data directory was initialized by PostgreSQL version 9.3, which is not compatible with this version 9.4.4.
LOG:  skipping missing configuration file "/usr/local/var/postgres/postgresql.auto.conf"
FATAL:  database files are incompatible with server

我在SO上找到了this answer,但是我开始创建一堆目录时犹豫不决,除非这真的是我想要做的。我还找到了一个older answer,但我不太确定它是否应该跟随。

SO answer建议我删除一个/usr/local/var/postgres/postmaster.pid,但我没有,我有一个/ usr / local / var / postgres / postmaster。选择 - 我应该删除postmaster.opts吗?

似乎有很多建议,但我不太清楚要遵循什么。有人可以提供一些建议让我的postgresql数据库在我的rails应用程序上运行吗?

2 个答案:

答案 0 :(得分:12)

您可以按照官方指南升级数据库:

brew switch postgres 9.3    # presuming you already installed 9.4.4
pg_dumpall > outputfile
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
mv /usr/local/var/postgres /usr/local/var/postgres.old
brew switch postgres 9.4.4
initdb -D /usr/local/var/postgres
psql -d postgres -f outputfile

PostgreSQL upgrade

答案 1 :(得分:0)

基本上,我不得不删除并重新创建自己的数据库,并使用远程登台数据重新播种。我不明白的是,更新数据库的问题是数据本身也需要更新'在某种方式。数据与不同版本兼容