kla*_*eck 117 postgresql macos homebrew
重新启动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"?
Run Code Online (Sandbox Code Playgroud)
我检查了日志,然后一遍又一遍地出现以下行:
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.
Run Code Online (Sandbox Code Playgroud)
9.0.4是预装在mac上的版本,9.2 [.4]是我通过Homebrew安装的版本.如前所述,这曾经在重启之前工作,所以它实际上不是一个编译问题.我也重新运行initdb /usr/local/var/postgres -E utf8,文件仍然存在.
不幸的是,我对Postgres很新,所以任何帮助都会非常感激.
Gow*_*nan 180
如果您使用的是Mac并且最近从10.x升级到11,则可以运行以下命令来升级保留所有数据的postgres数据目录:
brew postgresql-upgrade-database
Run Code Online (Sandbox Code Playgroud)
上面的命令取自输出 brew info postgres
Mee*_*ohi 150
如果您正在寻找核选项(删除所有数据并获得新数据库),您可以:
rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8
然后你需要rake db:setup和rake db:migrate您的Rails应用程序重新获得设置.
gdu*_*lle 38
试试这个:https: //gist.github.com/joho/3735740
它对我来说很完美.最后,它还会生成2个bash脚本来检查您的数据库并删除旧的群集.非常棒.
请参阅:http://www.postgresql.org/docs/9.2/static/pgupgrade.html了解更多信息.
小智 10
正如@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
Run Code Online (Sandbox Code Playgroud)
小智 9
在互联网上找到,这个解决方案对我来说很好.
当我在升级到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"?
Run Code Online (Sandbox Code Playgroud)
好的,让我们来看看服务器日志:
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.
Run Code Online (Sandbox Code Playgroud)
所以,我们需要在升级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
Run Code Online (Sandbox Code Playgroud)
而已.
如果要保留以前版本的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
Run Code Online (Sandbox Code Playgroud)
否则,请考虑以下brew命令以迁移现有数据:brew postgresql-upgrade-database。查看源代码。
当在 Docker 中运行新的 Postgres 并且旧卷未更新时,也可能会发生这种情况。
如果您不需要保留数据,最简单的方法是清除 docker 文件夹中的旧卷,在 Linux 中,如下所示:
/var/lib/docker/volumes
Run Code Online (Sandbox Code Playgroud)
与这些答案类似(1、2 ),我的 Postgres 数据库文件在升级到.postgresql 13.3
不幸的是,升级我的 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.
Run Code Online (Sandbox Code Playgroud)
我的解决方法是重新安装postgresql 12.7.
$ brew reinstall postgresql@12
$ brew services start postgresql@12
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
45246 次 |
| 最近记录: |