Postgres配置在OSX Mavericks之后搞砸了

时间:2013-11-01 05:02:32

标签: ruby-on-rails-3 postgresql osx-mavericks

在我安装了Mavericks后,我的postgres配置似乎完全搞砸了。我从xcode安装了Maverick的开发工具,我尝试在db yml中放置host:localhost,但是如果我尝试运行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 start

我得到:server starting

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) *

因为我确实要重新安装postgress,我知道得到这个:

The data directory was initialized by PostgreSQL version 9.2, 
which is not compatible with this version 9.3.1.

我有一个postgres查询工具,似乎连接没有任何问题所以我知道数据仍在那里。

如果有人可以帮我解决这个问题,我真的很感激,谢谢。

2 个答案:

答案 0 :(得分:8)

错误The data directory was initialized by PostgreSQL version 9.2, which is not compatible with this version 9.3.1.是由9.29.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摇滚吧!

答案 1 :(得分:3)

upgrade PostgreSQL最保守的方式需要:

  1. 使用9.2.X源(例如./configure --prefix=/tmp/myPg-9.2 && make && make install
  2. 编译PostgreSQL版本
  3. 使用9.2二进制文件启动数据库(例如/tmp/myPg-9.2/bin/postgres -D /usr/local/var/postgres,这将使PostgreSQL保持在此终端的前台)
  4. 使用pg_dumpall
  5. 转储数据库
  6. 关闭9.2数据库。
  7. /usr/local/var/postgres移至安全的地方(例如/usr/local/var/postgres-9.2
  8. initdb使用新的9.3二进制文件的新数据库。
  9. pg_dumpall加载转储。
  10. 确保在成功恢复之前保留旧9.2数据目录的副本。一旦确定已完全从这种情况中恢复,就可以在/tmp/myPg-9.2和旧的9.2数据目录/usr/local/var/postgres-9.2中清除临时9.2安装。我会对/usr/local/var/postgres-9.2进行备份,并会在其中保留几个月“以防万一”(例如tar cjpf /usr/local/var/postgres-9.2-2013-10-31.tar.bz2 /usr/local/var/postgres-9.2)。


    根据评论,添加一些额外的步骤:

    1. 编译PostgreSQL的一个版本:
      1. cd /tmp
      2. http://www.postgresql.org/ftp/source/下载PostgreSQL 9.2源码的最新.bz2 tarball(截至2013-10-31,目前为9.2.5)。
      3. tar xjpf postgresql-9.2.5.tar.bz2
      4. cd postgresql-9.2.5
      5. ./configure --prefix=/tmp/myPg-9.2 - 请勿将其作为root
      6. 运行
      7. make - 也不要将其作为root
      8. 运行
      9. make install - 您经常以root身份执行此操作,但此时您不需要,因为您正在安装到您有权安装的/tmp。如果您的前缀为/usr/local,则必须以root运行此命令。
相关问题