我在 Postgres 16.2 中使用 plpython 过程和库制表时遇到问题。
我创建了程序:
CREATE OR REPLACE PROCEDURE dpl.__test_tabulate()
LANGUAGE plpython3u AS $plpy$
from tabulate import tabulate
plpy.info('%s' % tabulate([["one", "two"], ["three", "four"]], colalign=("right",)))
$plpy$;
但是当我在 psql 中运行它时,出现错误:
database=# CALL dpl.__test_tabulate();
ERROR: TypeError: tabulate() got an unexpected keyword argument 'colalign'
CONTEXT: Traceback (most recent call last):
PL/Python function "__test_tabulate", line 4, in <module>
plpy.info('%s' % tabulate([["one", "two"], ["three", "four"]], colalign=("right",)))
PL/Python procedure "__test_tabulate"
database=#
我的 postgres 在 RHEL 8.9 上运行。
RHEL 上安装了 Python 3.9(连同 3.6)。
当我在 Python 3.9 中运行此过程时,它有效:
# python
Python 3.9.18 (main, Sep 22 2023, 18:24:59)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-20)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from tabulate import tabulate
>>> print(tabulate([["one", "two"], ["three", "four"]], colalign=("right",)))
----- ----
one two
three four
----- ----
但是Postgres 16.2使用python 3.6,并且该过程不起作用。当我在 RHEL python 3.6 中运行该过程时,它也不起作用。
如何强制 Postgres 使用 python 3.9 而不是 3.6 版本?
postgres@server:/var/lib/pgsql # python3 -V
Python 3.9.18
postgres@server:/var/lib/pgsql # pip show tabulate
Name: tabulate
Version: 0.9.0
Summary: Pretty-print tabular data
Home-page:
Author:
Author-email: Sergey Astanin <[email protected]>
License: MIT
Location: /usr/local/lib/python3.9/site-packages
Requires:
Required-by: apache-airflow
postgres@server:/var/lib/pgsql # psql -d 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=#
从13.5版本升级到新版本16.2后发现该问题。升级设置>
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
主数据库有70TB大小。
从该存储库下载安装包: https://download.postgresql.org/pub/repos/yum/16/redhat/rhel-8.9-ppc64le/
在另一个论坛中我询问了我的问题,我收到信息说 RHEL 8 默认情况下有 Python 3.6。
这对我来说已经足够了。我担心我在升级过程中犯了错误。 现在我知道我在升级过程中没有犯错误。
更改所使用的Python的一种方法是重新编译plpython3u。但专家强烈不建议这样做。 因此,唯一的可能性是将 RHEL 升级到版本 9。但是当 Postgres 16 也可用于 ppc64le 平台时,我可以做到这一点。
所以谢谢大家。