Postgres - FATAL: database files are incompatible with server
重新启动MacBook Pro后,我无法启动数据库服务器:
1 2 3 | 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"? |
我检查了日志,然后一遍又一遍地出现以下行:
1 2 | 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安装的版本。
如前所述,这曾经在重启之前工作,所以它实际上不是一个编译问题。 我也重新运行
不幸的是,我对Postgres很新,所以任何帮助都会非常感激。
如果您正在寻找核选项(删除所有数据并获得新数据库),您可以:
然后你需要从你的Rails应用程序
如果您使用的是Mac并且最近从10.x升级到11,则可以运行以下命令来升级保留所有数据的postgres数据目录:
1 | brew postgresql-upgrade-DATABASE |
以上命令取自
试试这个 :
https://gist.github.com/joho/3735740
它对我来说很完美。
最后,它还会生成2个bash脚本来检查您的数据库并删除旧的群集。
非常棒。
请参阅:http://www.postgresql.org/docs/9.2/static/pgupgrade.html了解更多信息。
在互联网上找到,这个解决方案对我来说很好。
当我在升级到OS X 10.10 Yosemite后尝试启动postgresql服务器时,我遇到了下一个问题:
1 2 3 | 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"? |
好的,让我们来看看服务器日志:
1 2 | 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后遵循几个步骤:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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,请使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | $ 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命令迁移现有数据: