我将 postgres 从 13.5 升级到了 16.2 版本(将 RHEL 从 7.5 升级到了 8.9)。问题是,python 没有升级。
我创建了过程 pyver():
CREATE OR REPLACE FUNCTION pyver ()
RETURNS TEXT
AS $$
import sys
pyversion = sys.version
return pyversion
$$ LANGUAGE 'plpython3u';
显示 Postgres 使用的 python 版本。
当我在 Python 13.5 上运行它时,得到以下结果:
psql (13.5)
Type "help" for help.
postgres@database # select pyver();
pyver
-----------------------------------------
3.6.8 (default, Aug 13 2020, 07:36:02) +
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
(1 řádka)
postgres@database #
当我在升级的数据库上运行它时,我得到了以下结果:
psql (16.2)
Type "help" for help.
database=# select pyver();
pyver
-----------------------------------------
3.6.8 (default, Jan 5 2024, 09:14:44) +
[GCC 8.5.0 20210514 (Red Hat 8.5.0-20)]
(1 row)
database=#
新的RedHat上安装了Python 3.9.18。
如何让 postgres 使用较新版本的 python?
升级是通过这种方式进行的:
- 安装了带有 RedHat 8.9(Python 3.9)的新服务器
- 安装了 Postgres 二进制文件(版本 13.5)并创建了用户 postgres
- 然后从旧服务器连接磁盘和 Postgres 数据库(版本 13.5)
- 数据库已在新服务器上启动
- 下一步是安装 Postgres 16.2
- 然后通过以下命令开始将 DB 升级到新的 Postgres 版本:
time /usr/pgsql-16/bin/pg_upgrade --jobs=16 -d /postgres/pgsql/database/data13 -D /postgres/pgsql/database/data16 -b /usr/pgsql-13/bin/ -B /usr/pgsql-16/bin/ --link
- 升级后在新版本上运行数据库
现在我们发现了 Python 中存在的问题。
主数据库大小为70TB。
谢谢 Michal
plpython3u 扩展应该针对正确的 python 头文件进行编译。
考虑到事实
预计 redhat 8 中 postgresql 的 plpython3 包是使用 python 3.6 标头构建的。
您需要升级到 RHEL 9(其中 Python 3.9 是默认的 Python 实现)或使用所需的头文件自行编译 plpython3u。