pgdisablelogerror

按 SQLSTATE 错误码禁止部分错误写入 PostgreSQL 服务器日志。

概览

扩展包名版本分类许可证语言
pgdisablelogerror1.0ADMINBSDC
ID扩展名BinLibLoadCreateTrustReloc模式
5260pgdisablelogerror-
相关扩展logerrors pgauditlogtofile

PGDG RPM and Pigsty DEB package fmbiete/pgdisablelogerror 1.0; control is relocatable=true and requires shared_preload_libraries.

版本

类型仓库版本PG 大版本包名依赖
EXTPGDG1.01817161514pgdisablelogerror-
RPMPGDG1.01817161514pgdisablelogerror_$v-
DEBPIGSTY1.01817161514postgresql-$v-pgdisablelogerror-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d12.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d13.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d13.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u26.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u26.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0

构建

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

pig build pkg pgdisablelogerror         # 构建 RPM / DEB 包

安装

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

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

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

pig install pgdisablelogerror;          # 当前活跃 PG 版本安装
pig ext install -y pgdisablelogerror -v 18  # PG 18
pig ext install -y pgdisablelogerror -v 17  # PG 17
pig ext install -y pgdisablelogerror -v 16  # PG 16
pig ext install -y pgdisablelogerror -v 15  # PG 15
pig ext install -y pgdisablelogerror -v 14  # PG 14
dnf install -y pgdisablelogerror_18       # PG 18
dnf install -y pgdisablelogerror_17       # PG 17
dnf install -y pgdisablelogerror_16       # PG 16
dnf install -y pgdisablelogerror_15       # PG 15
dnf install -y pgdisablelogerror_14       # PG 14
apt install -y postgresql-18-pgdisablelogerror   # PG 18
apt install -y postgresql-17-pgdisablelogerror   # PG 17
apt install -y postgresql-16-pgdisablelogerror   # PG 16
apt install -y postgresql-15-pgdisablelogerror   # PG 15
apt install -y postgresql-14-pgdisablelogerror   # PG 14

预加载配置

shared_preload_libraries = '$libdir/pgdisablelogerror';

创建扩展

CREATE EXTENSION pgdisablelogerror;

用法

来源:READMEv1.0 releasecontrol file

pgdisablelogerror 会抑制配置的 SQLSTATE error codes 在 PostgreSQL server log 中的记录。对于 duplicate-key violations 等预期应用错误过于频繁、污染 server log 的场景,它比较有用。

启用 Hook

加载 module 并重启 PostgreSQL:

shared_preload_libraries = 'pgdisablelogerror'

postgres 数据库中创建一次扩展:

CREATE EXTENSION pgdisablelogerror;

配置 SQLSTATE Codes

pgdisablelogerror.sqlerrcode 设为逗号分隔的 SQLSTATE codes:

pgdisablelogerror.sqlerrcode = '23505,23503'

空值或 NULL 会禁用 suppression:

pgdisablelogerror.sqlerrcode = ''

要在普通 PostgreSQL 日志中识别 SQLSTATE 值,可以在 log_line_prefix 中添加 %e

注意事项

  • 版本 1.0 支持 PostgreSQL 14-18。
  • 该扩展影响日志,不影响错误行为。客户端仍会收到原始错误。
  • SQLSTATE 列表应尽量窄。抑制过宽的错误类别可能隐藏真实运维问题。

最后修改 2026-07-01: routine extension update (d1ad21a)