postgresql Postgres - 致命:数据库文件与服务器不兼容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17822974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postgres - FATAL: database files are incompatible with server
提问by klaffenboeck
After restarting my MacBook Pro I am unable to start the database 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"?
I checked the logs and the following line appears over and over again:
我检查了日志,一遍又一遍地出现以下行:
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 was the version that came preinstalled on the mac, 9.2[.4] is the version I installed via Homebrew.
As mentioned, this used to work before the restart, so it can't actually be an compiling issue. I also re-ran initdb /usr/local/var/postgres -E utf8
and the file still exists.
9.0.4 是预装在 mac 上的版本,9.2[.4] 是我通过 Homebrew 安装的版本。如前所述,这曾经在重新启动之前起作用,因此它实际上不是编译问题。我也重新运行initdb /usr/local/var/postgres -E utf8
,文件仍然存在。
Unfortunately, I am pretty new to Postgres, so any help would be very much appreciated.
不幸的是,我对 Postgres 还很陌生,因此非常感谢任何帮助。
回答by Gowtham Gopalakrishnan
If you recently upgraded to 11 or 12 from 10.xyou can run the below command to upgrade your postgres data directory retaining all data:
如果您最近从 10.x 升级到 11 或 12,您可以运行以下命令来升级保留所有数据的 postgres 数据目录:
brew postgresql-upgrade-database
The above command is taken from the output of brew info postgres
上面的命令取自的输出 brew info postgres
回答by Meekohi
If you are looking for the nuclear option (delete all data and get a fresh database), you can do:
如果您正在寻找核选项(删除所有数据并获取新数据库),您可以执行以下操作:
rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8
rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8
and then you'll need to rake db:setup
and rake db:migrate
from your Rails app to get setup again.
然后你需要rake db:setup
和rake db:migrate
您的Rails应用程序重新获得设置。
回答by gdurelle
Try this : https://gist.github.com/joho/3735740
试试这个:https: //gist.github.com/joho/3735740
It worked perfectly for me. In the end it also generates you 2 bash scripts to check your DB and remove the old cluster. Really Awesome.
它非常适合我。最后,它还为您生成 2 个 bash 脚本来检查您的数据库并删除旧集群。非常棒。
see: http://www.postgresql.org/docs/9.2/static/pgupgrade.htmlto understand more.
请参阅:http: //www.postgresql.org/docs/9.2/static/pgupgrade.html了解更多信息。
回答by Gianluca Musa
Found on internet, this solution work fine for me.
在互联网上找到,这个解决方案对我来说很好。
When I tried to start postgresql server after upgrade to OS X 10.10 Yosemite, I encountered with a next problem:
当我在升级到 OS X 10.10 Yosemite 后尝试启动 postgresql 服务器时,我遇到了下一个问题:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
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"?
Okay, lets take a look into server logs:
好的,让我们看看服务器日志:
cat /usr/local/var/postgres/server.log
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.
So, we need to follow a few steps after upgrade postgresql:
所以,升级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
That's it.
就是这样。
回答by peresleguine
If you want to keep the previous version of postgres, use brew switch
:
如果要保留以前版本的 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
Otherwise, consider this brew command to migrate existing data: brew postgresql-upgrade-database
. Check out the source code.
否则,请考虑使用此 brew 命令来迁移现有数据:brew postgresql-upgrade-database
。查看源代码。
回答by anuj kumar
It happened for me when I was trying to start Postgres12 with postgres11 mounted volume. Just deleting the mounted volume for postgres11 and restart worked for me.
当我尝试使用 postgres11 安装卷启动 Postgres12 时,它发生在我身上。只是删除 postgres11 的已安装卷并重新启动对我有用。
Previously I was using:
以前我使用的是:
docker run -d --name my_database -v /Users/champ/postgres:/var/lib/postgresql/data -p 54320:5432 postgres:11
I deleted /Users/champ/postgres and restarted postgres 12, using
我删除了 /Users/champ/postgres 并重新启动了 postgres 12,使用
docker run -d --name my_database -v /Users/champ/postgres:/var/lib/postgresql/data -p 54320:5432 postgres:12