cat_tools

用于操作 PostgreSQL 系统目录的工具集

概览

扩展包名版本分类许可证语言
cat_tools0.3.0ADMINMITSQL
ID扩展名BinLibLoadCreateTrustReloc模式
5290cat_toolscat_tools
相关扩展plpgsql pg_catalog_get_defs pg_global_catalog meta_triggers pg_catcheck pgdd ddlx meta object_reference
下游依赖extension_drop object_reference

Promoted from a source-only universe row to PIGSTY RPM and DEB packages at 0.3.0; control fixes schema cat_tools and META declares the plpgsql runtime dependency.

版本

类型仓库版本PG 大版本包名依赖
EXTPIGSTY0.3.01817161514cat_toolsplpgsql
RPMPIGSTY0.3.01817161514cat_tools_$v-
DEBPIGSTY0.3.01817161514postgresql-$v-cat-tools-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
d12.aarch64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
d13.x86_64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
d13.aarch64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
u22.x86_64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
u22.aarch64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
u24.x86_64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
u24.aarch64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
u26.x86_64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
u26.aarch64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0

构建

您可以使用 pig build 命令构建 cat_tools 扩展的 RPM / DEB 包:

pig build pkg cat_tools         # 构建 RPM / DEB 包

安装

您可以直接安装 cat_tools 扩展包的预置二进制包,首先确保 PGDGPIGSTY 仓库已经添加并启用:

pig repo add pgsql -u          # 添加仓库并更新缓存

使用 pig 或者是 apt/yum/dnf 安装扩展:

pig install cat_tools;          # 当前活跃 PG 版本安装
pig ext install -y cat_tools -v 18  # PG 18
pig ext install -y cat_tools -v 17  # PG 17
pig ext install -y cat_tools -v 16  # PG 16
pig ext install -y cat_tools -v 15  # PG 15
pig ext install -y cat_tools -v 14  # PG 14
dnf install -y cat_tools_18       # PG 18
dnf install -y cat_tools_17       # PG 17
dnf install -y cat_tools_16       # PG 16
dnf install -y cat_tools_15       # PG 15
dnf install -y cat_tools_14       # PG 14
apt install -y postgresql-18-cat-tools   # PG 18
apt install -y postgresql-17-cat-tools   # PG 17
apt install -y postgresql-16-cat-tools   # PG 16
apt install -y postgresql-15-cat-tools   # PG 15
apt install -y postgresql-14-cat-tools   # PG 14

创建扩展

CREATE EXTENSION cat_tools CASCADE;  -- 依赖: plpgsql

用法

来源:

cat_tools 提供用于 PostgreSQL 目录自省的带类型视图、枚举和辅助函数。它面向需要比反复解析原始 pg_catalog 字段更稳定、更易读接口的数据库代码;这些视图仍会跟随 PostgreSQL 目录变化,因此每次跨大版本升级时都必须审查。

安装并授予访问权限

CREATE EXTENSION cat_tools;
GRANT cat_tools__usage TO app_introspection;

扩展安装在固定的 cat_tools 模式中,要求 plpgsql,且不可重定位。应授予 cat_tools__usage 角色,而不是直接暴露内部 _cat_tools 辅助对象。

检查关系与列

SELECT cat_tools.relation__kind(c.relkind::text)
FROM pg_catalog.pg_class AS c
WHERE c.oid = 'public.orders'::regclass;

SELECT cat_tools.relation__column_names('public.orders'::regclass);
SELECT cat_tools.pg_attribute__get('public.orders'::regclass, 'id');

常用的关系辅助函数包括 pg_class(regclass)relation__is_catalogrelation__is_temprelation__kindrelation__relkind。带类型的映射函数能明确表示目录中的单字符代码。

检查例程

版本 0.3 新增了同时覆盖函数和过程的函数与类型:

SELECT cat_tools.routine__arg_types(
  'public.calculate_total(integer, numeric)'::regprocedure
);

SELECT cat_tools.routine__parse_arg_names(
  'IN account_id integer, INOUT total numeric'
);

例程接口包括 routine__parse_arg_typesroutine__parse_arg_namesroutine__arg_typesroutine__arg_names、它们的文本变体,以及用于例程种类、参数模式、易变性和并行安全性的映射。function__arg_typesfunction__arg_types_text 已弃用;请改用例程解析器。

版本 0.3.0 与注意事项

  • 上游版本 0.3.0 支持 PostgreSQL 12-18+;当前 Pigsty 软件包覆盖 PostgreSQL 14-18。
  • 该版本修正了复合类型、外部表和物化视图对应的 cfm 映射。任何曾绕过旧映射问题的代码都应重新测试。
  • 内部 _cat_tools 辅助对象现在会撤销 PUBLICEXECUTE;调用者应继承 cat_tools__usage 并使用受支持的接口。
  • 从 0.2.3 更新至 0.3.0 会新增枚举值,因此无法在 PostgreSQL 11 或更早版本上运行。请按照上游文档规定的顺序升级数据库大版本和扩展。
  • PostgreSQL 不承诺跨大版本的目录兼容性。即使使用这些包装器,也应针对每个受支持的 PostgreSQL 大版本固定测试。

最后修改:2026-08-09: update extension count (30409e7)