无法升级到 PostgreSQL 15/

您好,我阅读了这篇文章:PostgreSQL 15 update - 并尝试升级到 15 版本,但在运行重建命令时,遇到了我不熟悉的错误,并且我所有的研究都未能解决这个问题。如果您能提供任何帮助,我将不胜感激。

它抱怨 Locale 和 postgres 都是从 13 版本初始化的,与 15 版本不兼容。

WARNING: Docker version 20.10.7 deprecated, recommend upgrade to 24.0.7 or newer.
x86_64 arch detected.
WARNING: containers/app.yml file is world-readable. You can secure this file by running: chmod o-rwx containers/app.yml
Ensuring launcher is up to date
Fetching origin
Launcher is up-to-date
Stopping old container
+ /usr/bin/docker stop -t 600 app
app
2.0.20250129-0720: Pulling from discourse/base
Digest: sha256:01b8516e5504c0e9bc3707773015ff4407be03a89154194ff3b5b8699291bc26
Status: Image is up to date for discourse/base:2.0.20250129-0720
docker.io/discourse/base:2.0.20250129-0720
/usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups.rb
/usr/local/bin/pups --stdin
I, [2025-02-25T12:02:47.588312 #1]  INFO -- : Reading from stdin
I, [2025-02-25T12:02:47.603317 #1]  INFO -- : File > /etc/service/postgres/run  chmod: +x  chown:
I, [2025-02-25T12:02:47.608602 #1]  INFO -- : File > /etc/service/postgres/log/run  chmod: +x  chown:
I, [2025-02-25T12:02:47.614271 #1]  INFO -- : File > /etc/runit/3.d/99-postgres  chmod: +x  chown:
I, [2025-02-25T12:02:47.619607 #1]  INFO -- : File > /root/install_postgres  chmod: +x  chown:
I, [2025-02-25T12:02:47.623993 #1]  INFO -- : File > /root/upgrade_postgres  chmod: +x  chown:
I, [2025-02-25T12:02:47.624696 #1]  INFO -- : Replacing data_directory = '/var/lib/postgresql/15/main' with data_directory = '/shared/postgres_data' in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-25T12:02:47.628520 #1]  INFO -- : Replacing (?-mix:#?listen_addresses *=.*) with listen_addresses = '*' in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-25T12:02:47.629701 #1]  INFO -- : Replacing (?-mix:#?synchronous_commit *=.*) with synchronous_commit = $db_synchronous_commit in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-25T12:02:47.635680 #1]  INFO -- : Replacing (?-mix:#?shared_buffers *=.*) with shared_buffers = $db_shared_buffers in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-25T12:02:47.636635 #1]  INFO -- : Replacing (?-mix:#?work_mem *=.*) with work_mem = $db_work_mem in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-25T12:02:47.637658 #1]  INFO -- : Replacing (?-mix:#?default_text_search_config *=.*) with default_text_search_config = '$db_default_text_search_config' in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-25T12:02:47.638584 #1]  INFO -- : Replacing (?-mix:#?checkpoint_segments *=.*) with checkpoint_segments = $db_checkpoint_segments in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-25T12:02:47.639215 #1]  INFO -- : Replacing (?-mix:#?logging_collector *=.*) with logging_collector = $db_logging_collector in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-25T12:02:47.639833 #1]  INFO -- : Replacing (?-mix:#?log_min_duration_statement *=.*) with log_min_duration_statement = $db_log_min_duration_statement in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-25T12:02:47.640892 #1]  INFO -- : Replacing (?-mix:^#local +replication +postgres +peer$) with local replication postgres  peer in /etc/postgresql/15/main/pg_hba.conf
I, [2025-02-25T12:02:47.641570 #1]  INFO -- : Replacing (?-mix:^host.*all.*all.*127.*$) with host all all 0.0.0.0/0 md5 in /etc/postgresql/15/main/pg_hba.conf
I, [2025-02-25T12:02:47.642114 #1]  INFO -- : Replacing (?-mix:^host.*all.*all.*::1\/128.*$) with host all all ::/0 md5 in /etc/postgresql/15/main/pg_hba.conf
I, [2025-02-25T12:02:47.642818 #1]  INFO -- : > if [ -f /root/install_postgres ]; then
  /root/install_postgres && rm -f /root/install_postgres
elif [ -e /shared/postgres_run/.s.PGSQL.5432 ]; then
  socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
fi

failed to set locale!
[error] character map file `UTF-8' not found: No such file or directory
failed to set locale!
[error] default character map file `ANSI_X3.4-1968' not found: No such file or directory
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = "en_US.UTF-8",
        LC_ALL = "en_US.UTF-8",
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
popen failure: Cannot allocate memory
initdb: error: program "postgres" is needed by initdb but was not found in the same directory as "/usr/lib/postgresql/15/bin/initdb"
I, [2025-02-25T12:02:49.979779 #1]  INFO -- : Generating locales (this might take a while)...
  en_US.UTF-8... done
Generation complete.
Upgrading PostgreSQL from version 13 to 15

I, [2025-02-25T12:02:49.980481 #1]  INFO -- : > HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/15/bin/postmaster -D /etc/postgresql/15/main
I, [2025-02-25T12:02:49.983148 #1]  INFO -- : Terminating async processes
2025-02-25 12:02:50.007 UTC [51] FATAL:  database files are incompatible with server
2025-02-25 12:02:50.007 UTC [51] DETAIL:  The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 15.10 (Debian 15.10-1.pgdg120+1).

提前感谢!

这可能是最严重的问题——您需要更多的内存(RAM)或需要添加交换空间(swap)。

请粘贴以下快速诊断的输出:

感谢您抽出宝贵时间。我完全忽略了那个内存问题,这是您要的结果:

root@glorious-discourse-forum:~# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"
root@glorious-discourse-forum:~# uptime
 13:27:58 up 1341 days, 22:37,  2 users,  load average: 0.07, 0.03, 0.00
root@glorious-discourse-forum:~# df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        49G   41G  7.7G  85% /
root@glorious-discourse-forum:~# free
              total        used        free      shared  buff/cache   available
Mem:        2040976      416492      436628       20940     1187856     1433788
Swap:       2097148       85248     2011900
root@glorious-discourse-forum:~# swapon
NAME      TYPE SIZE  USED PRIO
/swapfile file   2G 83.3M   -2
root@glorious-discourse-forum:~# vmstat 5 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----\n r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st\n 0  0  85248 436692 444416 743440    8    8   268    88    0    0  3  1 96  0  0\n 0  0  85248 436684 444416 743440    0    0     0     0   50   87  0  0 100  0  0\n 0  0  85248 436716 444416 743440    0    0     0     8   48   78  0  0 100  0  0\n 0  0  85248 436716 444416 743440    0    0     0     6   39   63  0  0 100  0  0\n 0  0  85248 436716 444416 743440    0    0     0     0   54   91  0  0 100  0  0\nroot@glorious-discourse-forum:~# dmesg|egrep -i "memory|oom|kill"\nroot@glorious-discourse-forum:~# ps auxrc
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      5781  0.0  0.1  40100  3332 pts/6    R+   13:28   0:00 ps

谢谢。我认为你可以尝试添加 2G 或 4G 的交换空间。但是关于 Docker 过期以及运行 18.04LTS 的消息,意味着如果你迁移到一个全新安装的操作系统的新实例,情况会好得多:最好是 24.04。我目前同时运行 24.04 和 22.04。

迁移到一个全新的实例可能比尝试就地升级更省力。甚至可能干扰更小。无论你做什么,都很可能需要一点停机时间。

第一步是进行备份(包括下载)并将其下载以妥善保管。同时复制你的 app.yml 文件。

我昨天也因为类似的原因进行了一次迁移。此外,通过更换托管提供商更新的套餐,我可以用相同的成本获得更好的机器。

我遵循了这里的迁移指南和技巧

另外,为了获得最佳效果,请阅读
MKJ\u0026rsquo;s Opinionated Discourse Deployment Configuration

你的磁盘空间也有些不足,特别是如果你添加交换空间的话。我通常会运行
du -kx / | sort -n | tail -55
或类似的命令,看看是否有任何不需要的大文件。

1 个赞

另一种迁移方法,而不是备份和恢复,是使用 rsync。我还没试过,但这里有一个方法:

另一个问题是您的 Docker 版本和操作系统需要升级。

Docker 版本 24.0.7 或更高版本需要比 18 更高的 Ubuntu LTS。该 LTS 的长期服务已停止支持。

我见过一些网站使用18.04进行了升级,但大多数都没有。

我见过人们成功地进行了dist-upgrade,但其成功率不确定,而且你真的想让你的6年老操作系统残留下来,在24.04支持的未来5年里可能引起问题吗?此外,升级18.04只能让你升级到20.04,而20.04的支持时间大约还有60天,所以你需要运行3次dist-upgrade才能升级到最新的操作系统。

我遇到了完全相同的错误,只不过我运行了./launcher rebuild。我没有关注论坛和警告,只是盲目地运行了更新。我该如何终止/回滚这次运行?直接 Ctrl+C 退出运行吗?

发生了什么?是出错了?它有提示再次运行重建吗?

你升级了 Docker 吗?

你试过

 ./launcher start app

你查看过 PostgreSQL 15 更新 了吗?

DETAIL: 数据目录由PostgreSQL版本13初始化,与此版本15.10(Debian 15.10-1.pgdg120+1)不兼容。之后它停止了任何操作。
我重启了服务器,这使服务器恢复了。
现在正在运行更多更新,由于某些原因,Docker卡在20,还有其他依赖项。真是度过星期五晚上的好方法,哈哈

真倒霉。

我会等到周一再迁移到新的虚拟机。我猜这个虚拟机已经过了使用寿命。

我更新了主机操作系统、Docker 版本,然后数据库更新也成功了,我还增加了更多内存,哈哈,应该能再用 5 年了吧?

如果你进行操作系统升级(尤其是 Docker),可能可以!

2 个赞