如何在不丢失数据的情况下将 PostgreSQL 从 9.5 升级到 9.6.1?

ogi*_*inc 6 postgresql postgresql-9.5 postgresql-9.6

当我试图跑步时psql,我得到了

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"?
Run Code Online (Sandbox Code Playgroud)

当我检查时Server.log,我看到:

FATAL: database files are incompatible with server
DETAIL: The data directory was initialized by PostgreSQL version 9.5,
        which is not compatible with this version 9.6.1.
Run Code Online (Sandbox Code Playgroud)

我尝试按照本教程(从 9.4 到 9.5)升级 9.6.1,但不断收到此错误消息

cannot write to log file pg_upgrade_internal.log
Failure, exiting
Run Code Online (Sandbox Code Playgroud)

跑完后

$ pg_upgrade -v \
> -d /usr/local/var/postgres \
> -D /usr/local/var/postgres9.6.1 \
> -b /usr/local/Cellar/postgresql/9.5/bin/ \
> -B /usr/local/Cellar/postgresql/9.6.1/bin/
Run Code Online (Sandbox Code Playgroud)

有谁知道我错过了什么/做错了什么?谢谢!


系统:

  • macOS 10.12.2
  • 与 Homebrew 一起安装的 PostgreSQL

Loh*_*pta 2

如果您的数据库大小不大,您可以使用 pg_dump 和 pg_dumpall 从 posgtres 9.5 以 sql 查询的形式获取数据库结构和数据转储,并在 postgres 9.6.1 中恢复相同的数据。

如果数据库太大,则进行pg_upgrade。通过查看错误,似乎用户没有目录的权限,并且无法写入日志文件。另外为了节省时间,我建议您使用-kpg_upgrade 选项来更快地升级。请注意,这-k将在新安装的数据目录中创建旧数据的软链接。因此您将无法删除旧数据。