community.postgresql.postgresql_user_obj_stat_info 模块 – 收集关于 PostgreSQL 用户对象的统计信息

注意

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

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

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

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

community.postgresql 0.2.0 中的新增功能

概要

  • 收集有关 PostgreSQL 用户对象的统计信息。

要求

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

  • psycopg2 >= 2.5.1

参数

参数

注释

ca_cert

别名:ssl_rootcert

字符串

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

如果该文件存在,则将验证服务器的证书是否由此类机构签名。

connect_params

字典

在 community.postgresql 2.3.0 中添加

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

这些参数优先。

默认值: {}

db

别名:login_db

字符串

要连接的数据库名称。

filter

列表 / 元素=字符串

通过逗号分隔的字符串或 YAML 列表限制收集的信息。

允许的值为 functionsindexestables

默认情况下,收集所有子集。

不支持的值将被忽略。

login_host

别名:host

字符串

运行数据库的主机。

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

默认值: ""

login_password

字符串

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

默认值: ""

login_unix_socket

别名:unix_socket

字符串

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

默认值: ""

login_user

别名:login

字符串

此模块应使用的用户名,以建立其 PostgreSQL 会话。

默认值: "postgres"

port

别名:login_port

整数

要连接的数据库端口。

默认值: 5432

schema

字符串

按特定模式限制输出。

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 默认值匹配。

选项

  • "allow"

  • "disable"

  • "prefer" ←(默认值)

  • "require"

  • "verify-ca"

  • "verify-full"

trust_input

布尔值

在 community.postgresql 0.2.0 中添加

如果 false,则检查 session_role 的值是否具有潜在危险性。

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

选项

  • false

  • true ←(默认值)

属性

属性

支持

描述

check_mode

支持: 完全

可以在 check_mode 中运行并返回更改的状态预测,而无需修改目标。

注意

注意

  • 返回的 sizetotal_size 值以字节为单位。

  • 为了跟踪函数统计信息,必须启用 PostgreSQL 的 track_functions 参数。有关更多信息,请参见 https://postgresql.ac.cn/docs/current/runtime-config-statistics.html

  • 默认身份验证假定您正在以主机上的 postgres 账户身份登录或 sudo 到该账户。

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

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

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

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

参见

另请参见

community.postgresql.postgresql_info

收集有关 PostgreSQL 服务器的信息。

community.postgresql.postgresql_ping

检查远程 PostgreSQL 服务器的可用性。

PostgreSQL 统计信息收集器参考

PostgreSQL 统计信息收集器文档的完整参考。

示例

- name: Collect information about all supported user objects of the acme database
  community.postgresql.postgresql_user_obj_stat_info:
    db: acme

- name: Collect information about all supported user objects in the custom schema of the acme database
  community.postgresql.postgresql_user_obj_stat_info:
    db: acme
    schema: custom

- name: Collect information about user tables and indexes in the acme database
  community.postgresql.postgresql_user_obj_stat_info:
    db: acme
    filter: tables, indexes

返回值

通用返回值在此处记录 此处,以下是此模块特有的字段

描述

functions

字典

用户函数统计信息。

返回: 成功

示例: {"public": {"inc": {"calls": 1, "funcid": 26722, "self_time": 0.23, "total_time": 0.23}}}

indexes

字典

用户索引统计信息。

返回: 成功

示例: {"public": {"test_id_idx": {"...": null, "idx_scan": 0, "idx_tup_fetch": 0, "idx_tup_read": 0, "relname": "test", "size": 8192}}}

tables

字典

用户表统计信息。

返回: 成功

示例: {"public": {"test": {"...": null, "analyze_count": 3, "n_dead_tup": 0, "n_live_tup": 0, "seq_scan": 2, "size": 0, "total_size": 8192}}}

作者

  • Andrew Klychkov (@Andersson007)

  • Thomas O’Donnell (@andytom)