0

我在Ubuntu 19.10上安装的PostgreSQL 11.5my_db=# CREATE EXTENSION IF NOT EXISTS plpythonu SCHEMA pg_catalog VERSION '1.0';中使用查询来创建plpythonu 扩展。但是我遇到了以下错误:

ERROR:  could not open extension control file "/usr/share/postgresql/10/extension/plpythonu.control": No such file or directory

为了安装plpythonu 包,我使用sudo apt-get update && apt-get install postgresql-plpython3了命令并成功安装。然后,我检查了目录,在我的案例中/usr/share/postgresql10 个11 个目录。我用谷歌搜索错误,发现PostgreSQL: how to install plpythonu extension and Postgres database crash when installed plpython posts 并遵循答案,但在我的情况下它们不起作用。另外,我在这里第 43 章的文档中读到了它。 PL/Python - Python Procedural Language但仍然找不到解决错误的解决方案,我无法在数据库中创建 plpythonu 扩展。现在,我想知道我是否应该删除或卸载任何东西,或者我的 PostgreSQL 有什么问题?请指导我创建扩展程序应遵循的步骤。

4

1 回答 1

1

看起来你在 postgresql 10 上安装了错误的版本 plpython3u。

你可以试试:

操作系统级安装:

  1. 更新本地存储库

    适当的更新

  2. 通过以下方式为您的数据库搜索支持的 plpython 版本

    apt-cache 搜索 plpython

  3. 检查结果,为 postgres 10 plpython3u 找到正确的包,下面是我基于 debian 的 postgres dockers 容器中的示例列表

postgresql-plpython3-10 - PostgreSQL 10 的 PL/Python 3 过程语言 postgresql-plpython3-10-dbgsym - postgresql-plpython3-10 的调试符号 postgresql-plpython3-11-dbgsym - postgresql-plpython3-11 的调试符号 postgresql-plpython3 -12 - 用于 PostgreSQL 12 的 PL/Python 3 过程语言 postgresql-plpython3-12-dbgsym - 用于 postgresql-plpython3-12 的调试符号 postgresql-plpython3-13 - 用于 PostgreSQL 13 的 PL/Python 3 过程语言 postgresql-plpython3-13-dbgsym

  • postgresql-plpython3-13 的调试符号
  1. 安装正确的包 pg10 + plpython3u 而不是调试版本

    易于安装 postgresql-plpython3-10

Postgresql 级别安装和配置

1.连接到您的 postgresql 10 DB 并通过创建扩展

=# 创建扩展 plpython3u; 创建扩展

  1. 检查准备就绪

=# \dx 已安装扩展名列表 版本 | 架构 | 说明 ------------+---------+------------+------------- ------------------------------ plpgsql | 1.0 | pg_catalog | PL/pgSQL 过程语言plpython3u | 1.0 | pg_catalog | PL/Python3U 不受信任的过程语言(2 行)

  1. 通过以下方式运行第一个 plpython3u 函数 pymax:

    <DB name>=# CREATE FUNCTION pymax (a integer, b integer)
     RETURNS integer
     AS $$
     if a > b:
         return a
     return b
    

    $$ 语言 plpythonu;

如果一切正常,你就有了第一个 plpython3u 函数。享受。

注意:您可能需要先通过 apt install python3 安装 python3

于 2020-12-08T04:49:21.777 回答