PostgreSQL Server版本太高

6ju8rftf  于 12个月前  发布在  PostgreSQL
关注(0)|答案(1)|浏览(220)

我现在收到这个错误消息:

db-1      |
db-1      | PostgreSQL Database directory appears to contain a database; Skipping initialization
db-1      |
db-1      | 2023-12-09 23:47:52.107 UTC [1] FATAL:  database files are incompatible with server
db-1      | 2023-12-09 23:47:52.107 UTC [1] DETAIL:  The data directory was initialized by PostgreSQL version 16, which is not compatible with this version 13.13 (Debian 13.13-1.pgdg120+1).
db-1 exited with code 1

字符串
我的docker文件如下:

version: '3'

services:
  server:
    image: registry.gitlab.com/commento/commento:v1.4.0
    ports:
      - 8080:8080
    environment:
      COMMENTO_ORIGIN: http://127.0.0.1:8080
      COMMENTO_PORT: 8080
      COMMENTO_POSTGRES: postgres://postgres:admin@db:5433/commento?sslmode=disable
    depends_on:
      - db
  db:
    image: postgres:13
    environment:
      POSTGRES_DB: postgres 
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: admin
    volumes:
      - postgres_data_volume:/Program Files/PostgreSQL/13/data

volumes:
  postgres_data_volume:


我已经做了我能想到的一切,这就是:

  • 更改版本号后重新初始化数据目录
  • 通过initdb --version确保我有正确的版本
  • 已卸载PostgreSQL 16版本
  • 检查端口号,以确保我与PostgreSQL 13版本处于同一端口

我是docker的新手,但我不知道从哪里开始。我使用的工具是Commento,不再支持,这就是为什么我使用旧版本的PostgreSQL。

r9f1avp5

r9f1avp51#

我复制了你的错误,事实上,你应该按照评论中的建议去做:在Docker Compose文件中将PostgreSQL版本从13更改为16。
这是我使用的Docker Compose测试文件:

version: '3'

services:
  db:
    image: postgres:16
    environment:
      POSTGRES_DB: postgres
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: admin
    volumes:
      - db_data:/var/lib/postgresql/data

volumes:
  db_data:

字符串
以下是第一次运行docker compose up时的日志:

...
test-db-1  | PostgreSQL init process complete; ready for start up.
test-db-1  | 
test-db-1  | 2023-12-10 02:23:02.240 UTC [1] LOG:  starting PostgreSQL 16.1 (Debian 16.1-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
test-db-1  | 2023-12-10 02:23:02.241 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
test-db-1  | 2023-12-10 02:23:02.243 UTC [1] LOG:  could not create IPv6 socket for address "::": Address family not supported by protocol
test-db-1  | 2023-12-10 02:23:02.255 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
test-db-1  | 2023-12-10 02:23:02.272 UTC [63] LOG:  database system was shut down at 2023-12-10 02:23:02 UTC
test-db-1  | 2023-12-10 02:23:02.284 UTC [1] LOG:  database system is ready to accept connections


正如你所看到的,数据库的初始化已经成功完成,所以数据库已经填充了存储在卷db_data中的数据。现在,我将PostgreSQL版本更改为13(image: postgres:13),结果如下:

test-db-1  | PostgreSQL Database directory appears to contain a database; Skipping initialization
test-db-1  | 
test-db-1  | 2023-12-10 02:25:02.528 UTC [1] FATAL:  database files are incompatible with server
test-db-1  | 2023-12-10 02:25:02.528 UTC [1] DETAIL:  The data directory was initialized by PostgreSQL version 16, which is not compatible with this version 13.13 (Debian 13.13-1.pgdg120+1).


如果我再次将PostgreSQL版本更改回16(image: postgres:16),一切都恢复正常:

test-db-1  | PostgreSQL Database directory appears to contain a database; Skipping initialization
test-db-1  | 
test-db-1  | 2023-12-10 02:26:03.538 UTC [1] LOG:  starting PostgreSQL 16.1 (Debian 16.1-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
test-db-1  | 2023-12-10 02:26:03.540 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
test-db-1  | 2023-12-10 02:26:03.542 UTC [1] LOG:  could not create IPv6 socket for address "::": Address family not supported by protocol
test-db-1  | 2023-12-10 02:26:03.554 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
test-db-1  | 2023-12-10 02:26:03.576 UTC [29] LOG:  database system was shut down at 2023-12-10 02:24:19 UTC
test-db-1  | 2023-12-10 02:26:03.588 UTC [1] LOG:  database system is ready to accept connections


顺便说一下,我想不出路径/Program Files/PostgreSQL/13/data在你的配置中来自哪里,因为在PostgreSQL Docker镜像中,PostgreSQL数据的默认路径是/var/lib/postgresql/data(如我的配置中所示),除非你在PGDATA环境变量中设置另一个路径。

编辑一:

我刚刚注意到你需要使用旧版本的PostgreSQL。因此,你必须重新初始化数据库,因为,即使PostgreSQL有工具将数据从旧版本迁移到新版本,我不相信(但我可能是错误的)它有工具将数据从新版本迁移到旧版本(就像你的情况一样)。为此,你有两个简单的选择:
1.重新配置卷postgres_data_volume,以便创建新卷,然后PostgreSQL重新配置数据库。* 这是最好的选择 *,因为您将保留旧卷postgres_data_volume(及其所有数据),以备以后需要。
1.使用docker compose down -v命令删除卷postgres_data_volume(仅当数据库中没有重要数据时才这样做),然后执行docker compose up命令重新创建它,这也将使PostgreSQL再次初始化数据库。

相关问题