2013-11-01 36 views
1

我安裝小牛後,我的postgres配置似乎完全搞砸了。我安裝了開發工具,用於從小牛Xcode和我試圖把主機:本地主機的分貝YML但仍,如果我嘗試運行軌道S:Postgres配置搞糟OSX小牛隊後

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的查詢工具,它似乎並不具有連接,所以我知道的數據是什麼麻煩還在那兒。

我真的很感激,如果有人能幫我弄明白這一點,謝謝。

+1

當嘗試連接到本地主機時(通過'database.yml'中的主機項),提示Unix域套接字的錯誤不會發生,這意味着您對此文件的更改將被忽略。你應該試着在別的之前解決這個問題。特別是如果您的查詢工具仍然可以連接,因爲這意味着postgres實際上正在運行。 –

回答

3

upgrade PostgreSQL最保守的方式需要對需要:

  1. 使用9.2.X源代碼編譯一個版本的PostgreSQL(如./configure --prefix=/tmp/myPg-9.2 && make && make install
  2. 開始使用9.2二進制文件(如/tmp/myPg-9.2/bin/postgres -D /usr/local/var/postgres,這將在數據庫保持PostgreSQL在這個終端的前臺)
  3. 轉儲數據庫使用pg_dumpall
  4. 關閉9.2數據庫。
  5. 移動/usr/local/var/postgres到安全的地方(例如/usr/local/var/postgres-9.2
  6. initdb使用新的9.3二進制一個新數據庫。
  7. pg_dumpall加載轉儲。

確保您保留舊9.2數據目錄的副本,直到您成功恢復。一旦你確定你完全從這種情況中恢復過來,你可以吹掉你的臨時9.2安裝在/tmp/myPg-9.2和舊的9.2數據目錄/usr/local/var/postgres-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. 下載最新.bz2壓縮包PostgreSQL的9.2源從http://www.postgresql.org/ftp/source/(目前爲9.2 。5截至2013-10-31)。
    3. tar xjpf postgresql-9.2.5.tar.bz2
    4. cd postgresql-9.2.5
    5. ./configure --prefix=/tmp/myPg-9.2 - 不要運行此爲root
    6. make - 也不要運行此爲root
    7. make install - 通常你會做這個作爲根,但你不因爲您需要安裝到您有權安裝的/tmp。如果您的前綴是/usr/local,則必須運行此命令作爲root
+0

對不起,我是這方面的新手。我應該在我的應用程序根目錄中鍵入'./configure --prefix =/tmp/myPg-9.2 && make && make install'?該目錄不存在。 – Jaqx

+0

展開編譯PostgreSQL版本的步驟。從記憶中寫下來,所以可能會有錯別字。 – Sean

+0

當我試圖啓動數據庫我得到了'日誌:無法綁定IPv6套接字:地址已在使用中 提示:另一個郵局管理員已經在端口5432上運行?' – Jaqx

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分貝舊的數據,這是很容易解決這個問題:

rm -rf /usr/local/var/postgres 

其中/usr/local/var/postgres是默認的數據目錄路徑。您可能需要根據您的設置更改路徑。

刪除舊數據目錄後,初始化一個新的與9.3

​​

那麼你是好去!

====

如果你需要將舊數據遷移從9.29.3

一)重命名你的舊數據目錄:

mv /usr/local/var/postgres /usr/local/var/postgres9.2 

B)初始化一個新的9.3 db(創建一個新的數據目錄):

​​

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!

+0

刪除和執行initdb的第一個解決方案並不適用於我。數據庫初始化後,我嘗試psql並得到以下errorpsql: 致命:數據庫「數據庫名稱」不存在 –

+0

需要在終端執行'createdb'。加工。 –

+0

當然你需要'createdb'。 'initdb'不同於'createdb' :) – Brian