簡體   English   中英

Postgres - 致命:數據庫文件與服務器不兼容

[英]Postgres - FATAL: database files are incompatible with server

重新啟動 MacBook Pro 后,我無法啟動數據庫服務器:

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"?

我檢查了日志,並一遍又一遍地出現以下行:

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.0.4.

9.0.4 是預裝在 mac 上的版本,9.2[.4] 是我通過 Homebrew 安裝的版本。

如前所述,這曾經在重新啟動之前工作,因此它實際上不是編譯問題。 我還重新運行了initdb /usr/local/var/postgres -E utf8並且該文件仍然存在。

如果您最近將 postgres升級到最新版本,您可以運行以下命令來升級您的 postgres 數據目錄,保留所有數據:

brew postgresql-upgrade-database

上面的命令取自brew info postgres的輸出

如果您正在尋找核選項(刪除所有數據並獲取新數據庫),您可以執行以下操作:

rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8

然后你需要rake db:setuprake db:migrate從 Rails 應用程序重新設置。

試試這個: https ://gist.github.com/joho/3735740

它對我來說非常有效。 最后,它還會為您生成 2 個 bash 腳本來檢查您的數據庫並刪除舊集群。 非常棒。

請參閱: http ://www.postgresql.org/docs/9.2/static/pgupgrade.html 以了解更多信息。

在互聯網上找到,這個解決方案對我來說很好。

當我在升級到 OS X 10.10 Yosemite 后嘗試啟動 postgresql 服務器時,遇到了下一個問題:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

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

好的,讓我們看一下服務器日志:

cat /usr/local/var/postgres/server.log

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.5.

因此,我們需要在升級 postgresql 后遵循幾個步驟:

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

mv /usr/local/var/postgres /usr/local/var/postgres92

brew update

brew upgrade postgresql

initdb /usr/local/var/postgres -E utf8

pg_upgrade -b /usr/local/Cellar/postgresql/9.2.3/bin -B /usr/local/Cellar/postgresql/9.3.5_1/bin -d /usr/local/var/postgres92 -D /usr/local/var/postgres

cp /usr/local/Cellar/postgresql/9.3.5_1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

rm -rf /usr/local/var/postgres92

而已。

如果要保留以前版本的 postgres,請使用brew switch

$ brew info postgresql

postgresql: stable 10.5 (bottled), HEAD
Object-relational database system
https://www.postgresql.org/
Conflicts with:
  postgres-xc (because postgresql and postgres-xc install the same binaries.)
/usr/local/Cellar/postgresql/9.6.3 (3,259 files, 36.6MB)
  Poured from bottle on 2017-07-09 at 22:15:41
/usr/local/Cellar/postgresql/10.5 (1,705 files, 20.8MB) *
  Poured from bottle on 2018-11-04 at 15:13:13

$ brew switch postgresql 9.6.3
$ brew services stop postgresql
$ brew services start postgresql

否則,請考慮使用此 brew 命令遷移現有數據: brew postgresql-upgrade-database 查看源代碼

正如@Gowtham 提到的,您可以通過執行 brew 命令來解決此問題

brew postgresql-upgrade-database上面的命令取自brew info postgres的輸出

但是,不要忘記在執行 postgres 服務之前停止它,使用以下命令:`brew services stop postgresql

您可能需要重新啟動該服務。

所以命令的最終順序是:

brew services stop postgresql
brew postgresql-upgrade-database
brew services start postgresql  

與這些答案( 12 )類似,我的 Postgres 數據庫文件在升級到postgresql 13.3后與我的 Postgres 版本不兼容。

不幸的是,升級我的 Postgres 數據目錄失敗了。

$ brew postgresql-upgrade-database
...
Setting next OID for new cluster
*failure*

Consult the last few lines of "pg_upgrade_utility.log" for
the probable cause of the failure.
Failure, exiting
Error: Upgrading postgresql data from 12 to 13 failed!
==> Removing empty postgresql initdb database...
==> Moving postgresql data back from /usr/local/var/postgres.old to /usr/local/var/postgres...
Error: Failure while executing; `/usr/local/opt/postgresql/bin/pg_upgrade -r -b /usr/local/Cellar/postgresql@12/12.7/bin -B /usr/local/opt/postgresql/bin -d /usr/local/var/postgres.old -D /usr/local/var/postgres -j 8` exited with 1.

我的解決方法是重新安裝postgresql 12.7

$ brew reinstall postgresql@12
$ brew services start postgresql@12

當我嘗試使用 postgres11 安裝卷啟動 Postgres12 時,它發生在我身上。 只需刪除 postgres11 的已安裝卷並重新啟動對我有用。

以前我使用的是:

docker run -d --name my_database -v /Users/champ/postgres:/var/lib/postgresql/data -p 54320:5432 postgres:11

我刪除 /Users/champ/postgres 並重新啟動 postgres 12,使用

docker run -d --name my_database -v /Users/champ/postgres:/var/lib/postgresql/data -p 54320:5432 postgres:12

brew info postgres會給你一些提示,比如To migrate existing data from a previous major version of PostgreSQL run:

因此,在我的情況下,刪除舊的rm -rf /usr/local/var/postgres.old並升級數據庫brew postgresql-upgrade-database

在 Docker 中運行新的 Postgres 並且您的舊卷未更新時也會發生這種情況。

如果您不需要保持數據最簡單,請清除 docker 文件夾中的舊卷,在 Linux 中,此處為:

/var/lib/docker/volumes

一個陳舊的postmaster.pid文件對我造成了這種影響。

只需導航到您的 postgres 目錄/Users/st/Library/Application Support/Postgres/ ,對我來說,就是:

cd '/Users/<username>/Library/Application Support/Postgres/var-10'

然后刪除文件postmaster.pid 重新啟動postgres,它會工作。

對我來說,使用這個命令:

brew install --build-from-source postgresql@12

然后啟動 Postgres:

brew services start postgresql@12

您還可以檢查端口5432是否正在偵聽:

netstat -nl |grep 5432

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM