跳转到主要内容

pglinter

PG数据库规则检查插件

pglinter · PG数据库规则检查插件

概览

ID扩展软件包版本类别许可证编程语言
5090pglinterpglinter2.0.0ADMINApache-2.0Rust
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-dt-否是否是否是

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY2.0.019 18 17 16 15pglinter-
RPMPIGSTY2.0.019 18 17 16 15pglinter_$v-
DEBPIGSTY2.0.019 18 17 16 15postgresql-$v-pglinter-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0
el8.aarch64N/APIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0
el9.x86_64PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0
el9.aarch64PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0
el10.x86_64PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0
el10.aarch64PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0
d12.x86_64PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0
d12.aarch64PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0
d13.x86_64PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0
d13.aarch64PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0
u22.x86_64PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0
u22.aarch64PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0
u24.x86_64PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0
u24.aarch64PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0
u26.x86_64PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0
u26.aarch64PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0PIGSTY 2.0.0
软件包版本平台仓库大小下载
pglinter_192.0.0el9.x86_64pigsty503.7 KiBpglinter_19-2.0.0-3PGSTY.el9.x86_64.rpm
pglinter_192.0.0el9.aarch64pigsty486.7 KiBpglinter_19-2.0.0-3PGSTY.el9.aarch64.rpm
pglinter_192.0.0el10.x86_64pigsty505.2 KiBpglinter_19-2.0.0-3PGSTY.el10.x86_64.rpm
pglinter_192.0.0el10.aarch64pigsty488.0 KiBpglinter_19-2.0.0-3PGSTY.el10.aarch64.rpm
postgresql-19-pglinter2.0.0d12.x86_64pigsty368.1 KiBpostgresql-19-pglinter_2.0.0-3PGSTY~bookworm_amd64.deb
postgresql-19-pglinter2.0.0d12.aarch64pigsty322.4 KiBpostgresql-19-pglinter_2.0.0-3PGSTY~bookworm_arm64.deb
postgresql-19-pglinter2.0.0d13.x86_64pigsty368.5 KiBpostgresql-19-pglinter_2.0.0-3PGSTY~trixie_amd64.deb
postgresql-19-pglinter2.0.0d13.aarch64pigsty323.0 KiBpostgresql-19-pglinter_2.0.0-3PGSTY~trixie_arm64.deb
postgresql-19-pglinter2.0.0u22.x86_64pigsty399.9 KiBpostgresql-19-pglinter_2.0.0-3PGSTY~jammy_amd64.deb
postgresql-19-pglinter2.0.0u22.aarch64pigsty374.0 KiBpostgresql-19-pglinter_2.0.0-3PGSTY~jammy_arm64.deb
postgresql-19-pglinter2.0.0u24.x86_64pigsty395.3 KiBpostgresql-19-pglinter_2.0.0-3PGSTY~noble_amd64.deb
postgresql-19-pglinter2.0.0u24.aarch64pigsty372.0 KiBpostgresql-19-pglinter_2.0.0-3PGSTY~noble_arm64.deb
postgresql-19-pglinter2.0.0u26.x86_64pigsty394.9 KiBpostgresql-19-pglinter_2.0.0-3PGSTY~resolute_amd64.deb
postgresql-19-pglinter2.0.0u26.aarch64pigsty370.8 KiBpostgresql-19-pglinter_2.0.0-3PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pglinter_182.0.0el8.x86_64pigsty467.3 KiBpglinter_18-2.0.0-2PIGSTY.el8.x86_64.rpm
pglinter_182.0.0el8.aarch64pigsty409.0 KiBpglinter_18-2.0.0-2PIGSTY.el8.aarch64.rpm
pglinter_182.0.0el9.x86_64pigsty500.1 KiBpglinter_18-2.0.0-3PGSTY.el9.x86_64.rpm
pglinter_182.0.0el9.aarch64pigsty482.5 KiBpglinter_18-2.0.0-3PGSTY.el9.aarch64.rpm
pglinter_182.0.0el10.x86_64pigsty499.9 KiBpglinter_18-2.0.0-3PGSTY.el10.x86_64.rpm
pglinter_182.0.0el10.aarch64pigsty483.3 KiBpglinter_18-2.0.0-3PGSTY.el10.aarch64.rpm
postgresql-18-pglinter2.0.0d12.x86_64pigsty365.8 KiBpostgresql-18-pglinter_2.0.0-3PGSTY~bookworm_amd64.deb
postgresql-18-pglinter2.0.0d12.aarch64pigsty320.6 KiBpostgresql-18-pglinter_2.0.0-3PGSTY~bookworm_arm64.deb
postgresql-18-pglinter2.0.0d13.x86_64pigsty366.0 KiBpostgresql-18-pglinter_2.0.0-3PGSTY~trixie_amd64.deb
postgresql-18-pglinter2.0.0d13.aarch64pigsty322.6 KiBpostgresql-18-pglinter_2.0.0-3PGSTY~trixie_arm64.deb
postgresql-18-pglinter2.0.0u22.x86_64pigsty397.2 KiBpostgresql-18-pglinter_2.0.0-3PGSTY~jammy_amd64.deb
postgresql-18-pglinter2.0.0u22.aarch64pigsty372.4 KiBpostgresql-18-pglinter_2.0.0-3PGSTY~jammy_arm64.deb
postgresql-18-pglinter2.0.0u24.x86_64pigsty392.6 KiBpostgresql-18-pglinter_2.0.0-3PGSTY~noble_amd64.deb
postgresql-18-pglinter2.0.0u24.aarch64pigsty369.8 KiBpostgresql-18-pglinter_2.0.0-3PGSTY~noble_arm64.deb
postgresql-18-pglinter2.0.0u26.x86_64pigsty392.3 KiBpostgresql-18-pglinter_2.0.0-3PGSTY~resolute_amd64.deb
postgresql-18-pglinter2.0.0u26.aarch64pigsty368.6 KiBpostgresql-18-pglinter_2.0.0-3PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pglinter_172.0.0el8.x86_64pigsty467.3 KiBpglinter_17-2.0.0-2PIGSTY.el8.x86_64.rpm
pglinter_172.0.0el8.aarch64pigsty409.0 KiBpglinter_17-2.0.0-2PIGSTY.el8.aarch64.rpm
pglinter_172.0.0el9.x86_64pigsty494.8 KiBpglinter_17-2.0.0-3PGSTY.el9.x86_64.rpm
pglinter_172.0.0el9.aarch64pigsty478.4 KiBpglinter_17-2.0.0-3PGSTY.el9.aarch64.rpm
pglinter_172.0.0el10.x86_64pigsty495.2 KiBpglinter_17-2.0.0-3PGSTY.el10.x86_64.rpm
pglinter_172.0.0el10.aarch64pigsty478.8 KiBpglinter_17-2.0.0-3PGSTY.el10.aarch64.rpm
postgresql-17-pglinter2.0.0d12.x86_64pigsty363.5 KiBpostgresql-17-pglinter_2.0.0-3PGSTY~bookworm_amd64.deb
postgresql-17-pglinter2.0.0d12.aarch64pigsty318.9 KiBpostgresql-17-pglinter_2.0.0-3PGSTY~bookworm_arm64.deb
postgresql-17-pglinter2.0.0d13.x86_64pigsty363.8 KiBpostgresql-17-pglinter_2.0.0-3PGSTY~trixie_amd64.deb
postgresql-17-pglinter2.0.0d13.aarch64pigsty320.2 KiBpostgresql-17-pglinter_2.0.0-3PGSTY~trixie_arm64.deb
postgresql-17-pglinter2.0.0u22.x86_64pigsty394.1 KiBpostgresql-17-pglinter_2.0.0-3PGSTY~jammy_amd64.deb
postgresql-17-pglinter2.0.0u22.aarch64pigsty370.0 KiBpostgresql-17-pglinter_2.0.0-3PGSTY~jammy_arm64.deb
postgresql-17-pglinter2.0.0u24.x86_64pigsty390.3 KiBpostgresql-17-pglinter_2.0.0-3PGSTY~noble_amd64.deb
postgresql-17-pglinter2.0.0u24.aarch64pigsty367.0 KiBpostgresql-17-pglinter_2.0.0-3PGSTY~noble_arm64.deb
postgresql-17-pglinter2.0.0u26.x86_64pigsty389.6 KiBpostgresql-17-pglinter_2.0.0-3PGSTY~resolute_amd64.deb
postgresql-17-pglinter2.0.0u26.aarch64pigsty366.1 KiBpostgresql-17-pglinter_2.0.0-3PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pglinter_162.0.0el8.x86_64pigsty467.5 KiBpglinter_16-2.0.0-2PIGSTY.el8.x86_64.rpm
pglinter_162.0.0el8.aarch64pigsty409.1 KiBpglinter_16-2.0.0-2PIGSTY.el8.aarch64.rpm
pglinter_162.0.0el9.x86_64pigsty493.0 KiBpglinter_16-2.0.0-3PGSTY.el9.x86_64.rpm
pglinter_162.0.0el9.aarch64pigsty476.4 KiBpglinter_16-2.0.0-3PGSTY.el9.aarch64.rpm
pglinter_162.0.0el10.x86_64pigsty493.1 KiBpglinter_16-2.0.0-3PGSTY.el10.x86_64.rpm
pglinter_162.0.0el10.aarch64pigsty476.9 KiBpglinter_16-2.0.0-3PGSTY.el10.aarch64.rpm
postgresql-16-pglinter2.0.0d12.x86_64pigsty362.6 KiBpostgresql-16-pglinter_2.0.0-3PGSTY~bookworm_amd64.deb
postgresql-16-pglinter2.0.0d12.aarch64pigsty317.7 KiBpostgresql-16-pglinter_2.0.0-3PGSTY~bookworm_arm64.deb
postgresql-16-pglinter2.0.0d13.x86_64pigsty362.5 KiBpostgresql-16-pglinter_2.0.0-3PGSTY~trixie_amd64.deb
postgresql-16-pglinter2.0.0d13.aarch64pigsty318.2 KiBpostgresql-16-pglinter_2.0.0-3PGSTY~trixie_arm64.deb
postgresql-16-pglinter2.0.0u22.x86_64pigsty392.9 KiBpostgresql-16-pglinter_2.0.0-3PGSTY~jammy_amd64.deb
postgresql-16-pglinter2.0.0u22.aarch64pigsty369.5 KiBpostgresql-16-pglinter_2.0.0-3PGSTY~jammy_arm64.deb
postgresql-16-pglinter2.0.0u24.x86_64pigsty388.9 KiBpostgresql-16-pglinter_2.0.0-3PGSTY~noble_amd64.deb
postgresql-16-pglinter2.0.0u24.aarch64pigsty365.3 KiBpostgresql-16-pglinter_2.0.0-3PGSTY~noble_arm64.deb
postgresql-16-pglinter2.0.0u26.x86_64pigsty388.1 KiBpostgresql-16-pglinter_2.0.0-3PGSTY~resolute_amd64.deb
postgresql-16-pglinter2.0.0u26.aarch64pigsty364.7 KiBpostgresql-16-pglinter_2.0.0-3PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pglinter_152.0.0el8.x86_64pigsty467.3 KiBpglinter_15-2.0.0-2PIGSTY.el8.x86_64.rpm
pglinter_152.0.0el8.aarch64pigsty409.2 KiBpglinter_15-2.0.0-2PIGSTY.el8.aarch64.rpm
pglinter_152.0.0el9.x86_64pigsty486.2 KiBpglinter_15-2.0.0-3PGSTY.el9.x86_64.rpm
pglinter_152.0.0el9.aarch64pigsty470.2 KiBpglinter_15-2.0.0-3PGSTY.el9.aarch64.rpm
pglinter_152.0.0el10.x86_64pigsty486.2 KiBpglinter_15-2.0.0-3PGSTY.el10.x86_64.rpm
pglinter_152.0.0el10.aarch64pigsty470.8 KiBpglinter_15-2.0.0-3PGSTY.el10.aarch64.rpm
postgresql-15-pglinter2.0.0d12.x86_64pigsty359.6 KiBpostgresql-15-pglinter_2.0.0-3PGSTY~bookworm_amd64.deb
postgresql-15-pglinter2.0.0d12.aarch64pigsty315.6 KiBpostgresql-15-pglinter_2.0.0-3PGSTY~bookworm_arm64.deb
postgresql-15-pglinter2.0.0d13.x86_64pigsty359.5 KiBpostgresql-15-pglinter_2.0.0-3PGSTY~trixie_amd64.deb
postgresql-15-pglinter2.0.0d13.aarch64pigsty315.7 KiBpostgresql-15-pglinter_2.0.0-3PGSTY~trixie_arm64.deb
postgresql-15-pglinter2.0.0u22.x86_64pigsty389.3 KiBpostgresql-15-pglinter_2.0.0-3PGSTY~jammy_amd64.deb
postgresql-15-pglinter2.0.0u22.aarch64pigsty366.6 KiBpostgresql-15-pglinter_2.0.0-3PGSTY~jammy_arm64.deb
postgresql-15-pglinter2.0.0u24.x86_64pigsty385.5 KiBpostgresql-15-pglinter_2.0.0-3PGSTY~noble_amd64.deb
postgresql-15-pglinter2.0.0u24.aarch64pigsty362.6 KiBpostgresql-15-pglinter_2.0.0-3PGSTY~noble_arm64.deb
postgresql-15-pglinter2.0.0u26.x86_64pigsty384.9 KiBpostgresql-15-pglinter_2.0.0-3PGSTY~resolute_amd64.deb
postgresql-15-pglinter2.0.0u26.aarch64pigsty361.3 KiBpostgresql-15-pglinter_2.0.0-3PGSTY~resolute_arm64.deb

源码

pig build pkg pglinter;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

pig repo add pgsql -u   # add both repo and update cache

使用 pig 安装扩展。

pig install pglinter;		# install by package name

pig install pglinter -v 19;   # install for PG 19
pig install pglinter -v 18;   # install for PG 18
pig install pglinter -v 17;   # install for PG 17
pig install pglinter -v 16;   # install for PG 16
pig install pglinter -v 15;   # install for PG 15

在数据库中创建扩展。

CREATE EXTENSION pglinter;

用法

来源:README、how-to、examples、rules、2.0.0 release

pglinter 会分析 PostgreSQL 数据库中的潜在问题、性能问题和最佳实践违规。当前用户文档通过 pglinter.get_violations() 暴露检查结果,该函数返回已启用规则的违规行,可过滤,也可连接到 pg_identify_object()。

运行检查

SELECT * FROM pglinter.get_violations();
SELECT * FROM pglinter.get_violations() WHERE rule_code = 'B001';

SELECT
  rule_code,
  (pg_identify_object(classid, objid, objsubid)).type AS object_type,
  (pg_identify_object(classid, objid, objsubid)).schema AS object_schema,
  (pg_identify_object(classid, objid, objsubid)).name AS object_name,
  (pg_identify_object(classid, objid, objsubid)).identity AS object_identity
FROM pglinter.get_violations();

规则管理

SELECT pglinter.show_rules();                -- Show all rules and their status
SELECT pglinter.explain_rule('B001');        -- Get rule details and suggested fixes
SELECT pglinter.enable_rule('B001');         -- Enable a specific rule
SELECT pglinter.disable_rule('B001');        -- Disable a specific rule
SELECT pglinter.is_rule_enabled('B001');     -- Check if a rule is enabled
SELECT pglinter.enable_all_rules();
SELECT pglinter.disable_all_rules();
SELECT pglinter.show_rule_queries('B001');   -- Inspect the rule query
SELECT pglinter.list_rules();                -- Return a formatted rule list

规则导入与导出

SELECT pglinter.export_rules_to_yaml();                -- Export rules to YAML
SELECT pglinter.import_rules_from_yaml('yaml...');     -- Import rules from YAML
SELECT pglinter.export_rules_to_file('/path/to/rules.yaml');
SELECT pglinter.import_rules_from_file('/path/to/rules.yaml');
SELECT pglinter.export_rulemessages_to_yaml();
SELECT pglinter.import_rule_messages_from_yaml('yaml...');

规则家族

基础规则(B 系列): B001 表缺少主键、B002 冗余索引、B003 外键缺少索引、B004 未使用的索引、B005 大写名称、B006 未使用的表、B007 跨模式外键、B008 外键类型不匹配、B009 共享触发器函数、B010 使用保留关键字、B011 单个模式存在多个所有者、B012 复合主键超过四列、B013 触发器逐行处理且没有 WHERE 子句。

集群规则(C 系列): C002 不安全的 pg_hba.conf 条目、C003 使用 MD5 密码加密。

模式规则(S 系列): S001 未设置默认角色授权、S002 名称带环境前缀或后缀、S003 public 模式未加固、S004 对象归系统角色所有、S005 单个模式存在多个所有者。

注意事项

版本 2.0.0 移除了较旧的 check() 和 check_rule() 函数;get_violations() 现在是唯一的检查 API。当前构建使用 pgrx 0.18.1。

上游 1.1.2 版本增加了 B013。主 README 相比其他文档和导出函数仍有部分滞后,因此本文使用 get_violations(),并省略已移除的 check() / check_rule() 示例。

表格阅读器