I upgraded my postgres from 13.5 to 16.2 version (and the RHEL from 7.5 to 8.9). The problem is, python was not upgraded.

I created procedure pyver():

AS $$
    import sys
    pyversion = sys.version
    return pyversion
$$ LANGUAGE 'plpython3u'; 

For show of python version used by Postgres.

When I run it on Python 13.5, I get this result:

psql (13.5)
Type "help" for help.

postgres@database # select 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 #

And when I run it on upgraded DB, I get this result:

psql (16.2)
Type "help" for help.

database=# select pyver();
 3.6.8 (default, Jan  5 2024, 09:14:44) +
 [GCC 8.5.0 20210514 (Red Hat 8.5.0-20)]
(1 row)


On the new RedHat is Python 3.9.18 installed.

How do I get postgres to use a newer version of python?

Upgrade was made by this way:

  • was installed new server with RedHat 8.9 (Python 3.9)
  • was installed Postgres binaries (version 13.5) and created user postgres
  • then was connected disk with Postgres databases (version 13.5) from old server
  • the DB's was started on new server
  • next step was installation of Postgres 16.2
  • then was start with upgrade of DB's to new Postgres version via this command:
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
  • after upgrade runs DB's on new version

And now we find the proglem with Python.

The main DB has 70TB size.

Thanks Michal

  • In python 3.6.8, the script using the tabulate library does not work. Specifically, it does not know the colalign parameter. When I searched for the cause of this malfunction, I was surprised that postgres 13.5 and 16.2 have the same version of python.
    – Misudka
    Commented Jun 20 at 7:51
  • So I assumed that with the PosgtreSQL upgrade, the Python it uses would also be upgraded.
    – Misudka
    Commented Jun 20 at 8:54
  • PostgreSQL doesn't have a version of Python, it uses a version of Python. So that version must be installed on your new machine. To help you any further, we need you to edit your question and describe how exactly you upgraded. Commented Jun 21 at 6:13

1 Answer 1


plpython3u extension should be compiled against the correct python header files.

Considering the fact

In Red Hat Enterprise Linux 8, Python 3.6 is the default.

It is expected that the plpython3 packages for postgresql in redhat 8 are built using python 3.6 headers.

You'll need to upgrade to RHEL 9 (where Python 3.9 is the default Python implementation) or compile plpython3u yourself with the desired header files.

  • Thank you for yours answer. I was worried that I had made some mistake during the upgrade.
    – Misudka
    Commented Jun 21 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.