【问题标题】:data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.0数据目录由 PostgreSQL 版本 13 初始化,与此版本 14.0 不兼容
【发布时间】:2021-11-24 04:54:39
【问题描述】:

我已经将 Portainer 下载到我的服务器上,并在那里的容器中创建了一个 PostgreSQL 数据库。 今天我无法再访问数据库。日志显示存在版本问题的消息。

我已经阅读过一些类似的问题,例如 Postgres container crashes with `database files are incompatible with server` after container's image has been updated to the latest onePostgres container crashes with `database files are incompatible with server` after container's image has been updated to the latest one

解决方案brew postgresql-upgrade-database 不起作用。

我能做什么?

日志

2021-10-03  [1] FATAL:  database files are incompatible with server
2021-10-03  [1] DETAIL:  The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.0 (Debian 14.0-1.pgdg110+1).

PostgreSQL Database directory appears to contain a database; Skipping initialization

我也发现了这个https://www.postgresql.org/docs/14/upgrading.html,但命令不起作用。我是否需要以某种方式在容器中执行此操作,或者哪些命令可以使其在容器中运行?

【问题讨论】:

  • 您是否也有类似瞭望塔之类的东西可以将容器更新到最新版本?我会使用postgres:13 图像(如果您从 docker.io 获取 postgres)保持在版本 13。
  • 我不认为我有其中之一。你能告诉我我该怎么做吗?
  • 您需要将数据库升级到 v14。请阅读文档。

标签: postgresql docker debian portainer


【解决方案1】:

我解决了

  1. 删除 postgres 图像
  2. 删除卷
  3. 再次拉取图片

假设您知道上述步骤的 docker 命令。

【讨论】:

  • 命令是什么?
  • @DevilCode 我使用docker-compose stop 然后docker-compose down 删除旧的数据库和卷。
【解决方案2】:

您需要使用以下命令将数据文件更新为新格式:

$ brew postgresql-upgrade-database 

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
【解决方案3】:

运行后出现问题

brew update
brew upgrade

Brew 将 postgresql 升级到 14,这给了我

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

我通过检查也看到了与您相同的错误

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

我已降级到正在运行的版本 13

brew uninstall postgresql
brew install postgresql@13
echo 'export PATH="/usr/local/opt/postgresql@13/bin:$PATH"' >> ~/.zshrc

我用来再次启动数据库的命令是

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

【讨论】:

    【解决方案4】:

    我认为是因为 postgresql13 与 14 在初始化时的差异。 您可以在新版本之前备份您的数据库,删除它并将数据库迁移到新版本

    例如在 django 中:

    dump: ./manage.py dumpdata -o mydata.json
    load: ./manage.py loaddata mydata.json
    

    django:当然,如果你有重要的信息,对每个模型单独做,加载时注意依赖关系。

    【讨论】:

      【解决方案5】:

      除了建议删除所有卷/图像/容器的答案之外 - 如果您在 docker-compose.yml 中有数据库的共享卷,例如:

      db:
        image: postgres:14.1-alpine
        volumes:
          - ./tmp/db:/var/lib/postgresql/data
      

      您还需要删除 ./tmp/db 中的 postgres 映射卷数据。否则那些冲突的文件仍然存在。

      如果您不关心数据 - 您将数据库用于开发目的,并且您可以轻松地重新创建数据库,只需运行 rm -r ./tmp/db。你可以docker-compose up 并重新创建你的数据库。

      如果您关心数据,请在删除文件之前使用pg_dumpall 转储您的数据,并在您运行docker-compose up 并且您的 postgres 服务再次准备就绪后恢复。

      【讨论】:

        【解决方案6】:

        我在 keycloak 中的 postgres 也面临同样的问题。 将版本降级到 13 解决了我的问题。

        【讨论】:

          【解决方案7】:

          对我来说,数据库目录位于 /tmp/db 中,由于没有重要数据,我删除了所有数据,一切正常......

          但如果您的数据很重要,请阅读以下内容:

          【讨论】:

            猜你喜欢
            • 2022-01-10
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-06-28
            • 2023-03-04
            • 1970-01-01
            • 2020-07-19
            • 2022-11-21
            相关资源
            最近更新 更多