[英]how to fix postgres after updating/upgrading brew
我升級到了mavericks並且在安裝/編譯新寶石時遇到了一些麻煩,所以我重新安裝了xcode並進行了brew更新和升級。 寶石現在工作,甚至postgres繼續工作一段時間,直到最近重新啟動。 現在postgres似乎有問題。
postgres:
postgres does not know where to find the server configuration file.
You must specify the --config-file or -D invocation option or set the PGDATA environment variable.
brew info postgres:
postgresql: stable 9.3.2 (bottled)
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.2.4 (2842 files, 39M)
Built from source
/usr/local/Cellar/postgresql/9.3.2 (2924 files, 39M) *
Poured from bottle
postgres -D /usr/local/var/postgres:
FATAL: database files are incompatible with server
DETAIL: The data directory was initialized by PostgreSQL version 9.2, which is not compatible with this version 9.3.2.
我現在該怎么辦才能讓我的數據庫再次運行?
$ brew tap homebrew/versions
$ brew install postgresql92
$ brew switch postgresql 9.2.8 # might need to check this one, could be newer by the time you read this
$ pg_dumpall > ninedottwo-dump
$ brew uninstall postgresql92
$ brew switch postgresql 9.3.4 # again, check version
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
$ createdb # i got an error about my database not existing, so i had to run this
$ psql < ninedottwo-dump
$ bundle exec rails s
感謝Peter讓我開始朝着正確的方向前進。
編輯:這將教會我一次性升級所有內容......
您需要以某種方式獲得PostgreSQL 9.2的副本,以便能夠訪問現有的數據目錄。
通過Homebrew安裝9.2的選項包括:
postgresql
公式升級到9.3之前,先查看Homebrew。 homebrew/versions
tap安裝postgresql92
。 petere/postgresql
tap安裝postgresql-9.2
(披露:那是我的項目)。 然后你應該使用pg_dump
或pg_upgrade
將其升級到9.3。
pg_upgrade
就是出於這個目的,使用它很簡單。 只需確保為舊數據和二進制文件指定正確的路徑(-d和-b)以及指向新數據和二進制文件(-D和-B)的正確路徑:
pg_upgrade \
-d /usr/local/var/postgres/9.2/ -D /usr/local/var/postgres/9.3/ \
-b /usr/local/Cellar/postgresql/9.2.4/bin/ -B /usr/local/Cellar/postgresql/9.3.2/bin/
如果一切順利,你可以使用brew cleanup postgresql
清理舊版本,並且由於新版本的PostgreSQL意味着Ruby pg gem使用的本機庫的新版本,你可能想要重新編譯它:
gem uninstall pg
ARCHFLAGS="-arch x86_64" gem install pg
對於9.2到9.5,在El Capitan,我遇到了一些可能對其他人有幫助的問題。
現在看來,switch語句中使用的包的名稱已更改為包含版本號(postgresql92 vs postgresql)。 所以,我需要增加一步來取消當前版本的postgres:
brew unlink postgresql
brew link postgresql92
brew switch postgresql92 9.2.13 # match version
為了執行我需要啟動postgres服務器的轉儲,
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
但后來我遇到了可怕的:
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"?
我查看了日志,發現了這個:
could not open directory "pg_tblspc": No such file or directory
根據Donovan的 回答 ,Yosemite和El Capitan刪除了一些所需的目錄。 所以我還需要使用Nate的這個awesome命令重新添加這些目錄
mkdir /usr/local/var/postgres/{pg_tblspc,pg_twophase,pg_stat,pg_stat_tmp,pg_replslot,pg_snapshots}/
所以完整的更新版本是:
brew tap homebrew/versions
brew install postgresql92
brew unlink postgresql
brew switch postgresql92 9.2.13 # might need to check this one, could be newer by the time you read this
mkdir /usr/local/var/postgres/{pg_tblspc,pg_twophase,pg_stat,pg_stat_tmp,pg_replslot,pg_snapshots}/
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
pg_dumpall > ninedottwo-dump
pg_ctl -D /usr/local/var/postgres stop
brew unlink postgresql92
brew uninstall postgresql92
brew switch postgresql 9.5.2 # again, check version
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
createdb # i got an error about my database not existing, so i had to run this
psql < ninedottwo-dump
bundle install # need to make sure you have pg gem for 9.5
bundle exec rails s
所有功勞都歸功於哨兵 ,內特和多諾萬。 非常感謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.