community.postgresql.postgresql_lang 模块 – 在 PostgreSQL 数据库中添加、删除或更改过程语言

注意

此模块是 community.postgresql 集合 (版本 3.9.0) 的一部分。

如果您使用的是 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用: ansible-galaxy collection install community.postgresql。您需要其他要求才能使用此模块,有关详细信息,请参见 要求

要在 playbook 中使用它,请指定: community.postgresql.postgresql_lang

已弃用

在以下版本中移除:

4.0.0 版本

原因:

从 PostgreSQL 9.1 开始,大多数过程语言都已成为扩展。

替代方案:

改用 community.postgresql.postgresql_ext

概要

  • 在 PostgreSQL 数据库中添加、删除或更改过程语言。

  • 此模块允许您添加语言、删除语言或更改与 PostgreSQL 数据库的信任关系。

  • 此模块可以在执行它的机器上或远程主机上使用。

  • 从数据库中删除语言时,依赖项可能会阻止数据库被删除。在这种情况下,您可以指定 *cascade=true* 自动删除依赖于该语言的对象(例如,该语言中的函数)。

  • 如果由于数据库系统需要该语言而无法删除该语言,您可以指定 *fail_on_drop=false* 以忽略错误。

  • 将语言标记为受信任时请小心,因为这可能是潜在的安全漏洞。不受信任的语言仅允许拥有 PostgreSQL 超级用户权限的用户使用此语言创建新函数。

要求

执行此模块的主机需要以下要求。

  • psycopg2 >= 2.5.1

参数

参数

注释

ca_cert

别名:ssl_rootcert

字符串

指定包含 SSL 证书颁发机构 (CA) 证书的文件名。

如果文件存在,则会验证服务器的证书是否由这些颁发机构之一签名。

cascade

布尔值

删除语言时,还删除依赖于此语言的对象。

仅在 *state=absent* 时使用。

选项

  • false ← (默认)

  • true

connect_params

字典

在 community.postgresql 2.3.0 中添加

要传递给 libpg 的任何其他参数。

这些参数具有优先级。

默认: {}

db

别名:login_db

字符串 / 必需

要连接到的数据库名称,以及将在其中添加、删除或更改语言的数据库。

fail_on_drop

布尔值

如果 true,则在删除语言时失败。否则,只记录并继续。

在某些情况下,无法删除语言(数据库系统使用)。

当依赖项阻止删除时,请考虑使用 *cascade*。

选项

  • false

  • true ← (默认)

force_trust

布尔值

将语言标记为受信任,即使它在 pg_pltemplate 中被标记为不受信任。

谨慎使用!

选项

  • false ← (默认)

  • true

lang

别名:name

字符串 / 必需

要添加、删除或更改的过程语言的名称。

login_host

别名:host

字符串

运行数据库的主机。

如果您在使用 localhost 时遇到连接问题,请尝试使用 127.0.0.1

默认: ""

login_password

字符串

此模块应使用此密码来建立其 PostgreSQL 会话。

默认: ""

login_unix_socket

别名:unix_socket

字符串

本地连接的 Unix 域套接字的路径。

默认: ""

login_user

别名:login

字符串

此模块应使用此用户名来建立其 PostgreSQL 会话。

默认: "postgres"

owner

字符串

在 community.postgresql 0.2.0 中添加

为语言设置所有者。

在 *state=absent* 时忽略。

port

别名:login_port

整数

要连接到的数据库端口。

默认: 5432

session_role

字符串

连接后切换到 session_role。

指定的 *session_role* 必须是当前 *login_user* 属于的角色。

SQL 命令的权限检查将执行,就像 *session_role* 是最初登录的角色一样。

ssl_cert

路径

在 community.postgresql 2.4.0 中添加

指定客户端 SSL 证书的文件名。

ssl_key

路径

在 community.postgresql 2.4.0 中添加

指定用于客户端证书的密钥的位置。

ssl_mode

字符串

确定是否以及以什么优先级与服务器协商安全的 SSL TCP/IP 连接。

有关模式的更多信息,请参见 https://postgresql.ac.cn/docs/current/static/libpq-ssl.html

prefer 的默认值与 libpq 默认值匹配。

选项

  • “允许”

  • “禁用”

  • "prefer" ← (默认)

  • “必需”

  • “验证CA”

  • “完全验证”

状态

字符串

所选数据库的语言状态。

选项

  • “不存在”

  • "present" ← (默认)

信任

布尔值

使此语言对所选数据库受信任。

选项

  • false ← (默认)

  • true

trust_input

布尔值

在 community.postgresql 0.2.0 中添加

如果 false,则检查参数 *lang*、*session_role*、*owner* 的值是否潜在危险。

只有当可能通过参数进行 SQL 注入时,使用 false 才有意义。

选项

  • false

  • true ← (默认)

属性

属性

支持

描述

check_mode

支持:完全支持

可以在 check_mode 下运行,并在不修改目标的情况下返回更改状态预测。

备注

注意

  • 默认身份验证假设您正在以主机上的 postgres 帐户身份登录或使用 sudo。

  • 为了避免“用户 postgres 的对等身份验证失败”错误,请使用 postgres 用户作为 *become_user*。

  • 此模块使用 psycopg,这是一个 Python PostgreSQL 数据库适配器。在使用此模块之前,必须确保主机上安装了 psycopg2 >= 2.5.1psycopg3 >= 3.1.8

  • 如果远程主机是 PostgreSQL 服务器(默认情况),则远程主机上也必须安装 PostgreSQL。

  • 对于基于 Ubuntu 的系统,在使用此模块之前,请在远程主机上安装 postgresqllibpq-devpython3-psycopg2 包。

另请参阅

另请参阅

PostgreSQL 语言

关于 PostgreSQL 语言的常规信息。

CREATE LANGUAGE 参考

CREATE LANGUAGE 命令文档的完整参考。

ALTER LANGUAGE 参考

ALTER LANGUAGE 命令文档的完整参考。

DROP LANGUAGE 参考

DROP LANGUAGE 命令文档的完整参考。

示例

- name: Add language pltclu to database testdb if it doesn't exist
  community.postgresql.postgresql_lang: db=testdb lang=pltclu state=present

# Add language pltclu to database testdb if it doesn't exist and mark it as trusted.
# Marks the language as trusted if it exists but isn't trusted yet.
# force_trust makes sure that the language will be marked as trusted
- name: Add language pltclu to database testdb if it doesn't exist and mark it as trusted
  community.postgresql.postgresql_lang:
    db: testdb
    lang: pltclu
    state: present
    trust: true
    force_trust: true

- name: Remove language pltclu from database testdb
  community.postgresql.postgresql_lang:
    db: testdb
    lang: pltclu
    state: absent

- name: Remove language pltclu from database testdb and remove all dependencies
  community.postgresql.postgresql_lang:
    db: testdb
    lang: pltclu
    state: absent
    cascade: true

- name: Remove language c from database testdb but ignore errors if something prevents the removal
  community.postgresql.postgresql_lang:
    db: testdb
    lang: pltclu
    state: absent
    fail_on_drop: false

- name: In testdb change owner of mylang to alice
  community.postgresql.postgresql_lang:
    db: testdb
    lang: mylang
    owner: alice

返回值

常用的返回值已在 此处 记录,以下是此模块独有的字段

描述

queries

列表 / 元素=字符串

已执行查询的列表。

已返回:成功

示例:["CREATE LANGUAGE \"acme\""]

状态

  • 此模块将在 4.0.0 版本中移除。 *[已弃用]*

  • 更多信息请参见 已弃用

作者

  • Jens Depuydt (@jensdepuydt)

  • Thomas O’Donnell (@andytom)