Token导航 LogoToken导航TokenDH.com
开发敏感数据github未标认证来源可访问许可证需确认审计提醒

implementing-database-audit-logging实施数据库审计日志记录

Agent Skill

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。它适合让 Agent 分析 schema、编写 SQL、排查查询问题、整理索引或生成迁移建议。使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更;涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护,避免误操作。

总安装

654

周安装

27

GitHub Stars

2,061

下载量

214
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:implementing-database-audit-logging(实施数据库审计日志记录)
来源仓库:https://github.com/jeremylongshore/claude-code-plugins-plus-skills
仓库路径:skills/implementing-database-audit-logging
安装命令:
npx skills add https://github.com/jeremylongshore/claude-code-plugins-plus-skills --skill implementing-database-audit-logging
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/jeremylongshore/claude-code-plugins-plus-skills --skill implementing-database-audit-logging

简介

implementing-database-audit-logging 用于辅助数据库表结构、查询语句和迁移脚本编写,支持索引优化建议。

  • 适用于分析 schema、排查查询问题或生成数据维护方案等数据库任务。
  • 可编写 SQL 语句,但需明确数据库类型与连接环境,区分只读与分析操作。
  • 安装命令为 npx skills add https://github.com/jeremylongshore/claude-code-plugins-plus-skills --skill implementing-database-audit-logging。
  • 涉及删除或更新操作时应优先 dry-run 或事务保护,避免误操作。

SKILL.md

Database Audit Logger

Overview

Implement database audit logging to track all data modifications (INSERT, UPDATE, DELETE) with full before/after values, user identity, timestamps, and application context. This skill supports trigger-based auditing for PostgreSQL and MySQL, change data capture (CDC) patterns, and application-level audit logging.

Prerequisites

  • Database credentials with CREATE TABLE, CREATE FUNCTION, and CREATE TRIGGER permissions
  • psql or mysql CLI for executing audit setup DDL
  • Understanding of applicable compliance requirements (which tables, which operations, retention period)
  • Estimated storage for audit logs: plan for 10-30% of the audited table's data volume per year
  • Separate tablespace or storage volume for audit data to prevent audit growth from affecting application performance

Instructions

  1. Identify tables requiring audit logging based on compliance and business needs:

- Tables containing PII (users, contacts, addresses) -- GDPR/HIPAA requirement - Tables containing financial data (transactions, payments, invoices) -- SOX/PCI-DSS requirement - Tables containing access control data (roles, permissions, API keys) -- security requirement - Determine which operations to audit per table: INSERT, UPDATE, DELETE, or all three

  1. Create the audit log table with comprehensive metadata: CREATE TABLE audit_log (id BIGSERIAL PRIMARY KEY, table_name VARCHAR(100) NOT NULL, record_id TEXT NOT NULL, action VARCHAR(10) NOT NULL CHECK (action IN ('INSERT', 'UPDATE', 'DELETE')), old_values JSONB, new_values JSONB, changed_columns TEXT[], changed_by VARCHAR(100), changed_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), client_ip INET, application_name VARCHAR(100), transaction_id BIGINT);
  2. Add indexes for common audit queries:

- CREATE INDEX idx_audit_table_record ON audit_log (table_name, record_id) - CREATE INDEX idx_audit_changed_at ON audit_log (changed_at) - CREATE INDEX idx_audit_changed_by ON audit_log (changed_by) - CREATE INDEX idx_audit_action ON audit_log (table_name, action)

  1. Create the PostgreSQL audit trigger function: CREATE OR REPLACE FUNCTION audit_trigger_func() RETURNS TRIGGER AS $$ BEGIN IF TG_OP = 'INSERT' THEN INSERT INTO audit_log (table_name, record_id, action, new_values, changed_by, client_ip, application_name, transaction_id) VALUES (TG_TABLE_NAME, NEW.id::text, 'INSERT', to_jsonb(NEW), current_setting('app.user', true), inet_client_addr(), current_setting('application_name'), txid_current()); ELSIF TG_OP = 'UPDATE' THEN INSERT INTO audit_log (table_name, record_id, action, old_values, new_values, changed_by, client_ip, application_name, transaction_id) VALUES (TG_TABLE_NAME, NEW.id::text, 'UPDATE', to_jsonb(OLD), to_jsonb(NEW), current_setting('app.user', true), inet_client_addr(), current_setting('application_name'), txid_current()); ELSIF TG_OP = 'DELETE' THEN INSERT INTO audit_log (table_name, record_id, action, old_values, changed_by, client_ip, application_name, transaction_id) VALUES (TG_TABLE_NAME, OLD.id::text, 'DELETE', to_jsonb(OLD), current_setting('app.user', true), inet_client_addr(), current_setting('application_name'), txid_current()); END IF; RETURN COALESCE(NEW, OLD); END; $$ LANGUAGE plpgsql;
  2. Attach triggers to each audited table:

- CREATE TRIGGER audit_users AFTER INSERT OR UPDATE OR DELETE ON users FOR EACH ROW EXECUTE FUNCTION audit_trigger_func() - Repeat for each table requiring audit logging

  1. Pass application-level user context to the database session so audit logs capture the actual application user (not just the database role):

- At the start of each request: SET LOCAL app.user = 'user@example.com' - For connection pools, set in the connection checkout hook - This value is captured by current_setting('app.user', true) in the trigger

  1. Partition the audit_log table by month for efficient querying and archival:

- CREATE TABLE audit_log (...) PARTITION BY RANGE (changed_at) - Create monthly partitions: CREATE TABLE audit_log_2024_01 PARTITION OF audit_log FOR VALUES FROM ('2024-01-01') TO ('2024-02-01') - Automate partition creation for future months

  1. Protect audit log integrity:

- Revoke UPDATE and DELETE permissions on audit_log from all application users - Grant only INSERT permission to the trigger execution context - Consider using pg_audit extension for additional tamper protection - Ship audit logs to an external system (SIEM, S3) for independent retention

  1. Create compliance report queries:

- Change history for a record: SELECT * FROM audit_log WHERE table_name = 'users' AND record_id = '12345' ORDER BY changed_at - All changes by a user: SELECT * FROM audit_log WHERE changed_by = 'user@example.com' ORDER BY changed_at DESC - Bulk operations detection: SELECT changed_by, table_name, action, COUNT(*) FROM audit_log WHERE changed_at > NOW() - INTERVAL '1 hour' GROUP BY 1,2,3 HAVING COUNT(*) > 100 - Off-hours activity: SELECT * FROM audit_log WHERE EXTRACT(HOUR FROM changed_at) NOT BETWEEN 8 AND 18

  1. Set up audit log archival: move audit records older than the retention period to cold storage (S3, Azure Blob). Maintain the archive manifest for retrieval. Typical retention: 1-3 years in database, 7+ years in cold storage for financial data.

Output

  • Audit table DDL with proper columns, indexes, and partitioning
  • Audit trigger function capturing full before/after values with user context
  • Trigger attachment scripts for each audited table
  • Compliance report queries for common audit scenarios
  • Archival configuration for audit log lifecycle management

Error Handling

ErrorCauseSolution
Audit trigger slows INSERT/UPDATE operationsTrigger overhead on high-write tablesAudit only critical columns instead of full rows; use asynchronous audit with pg_notify and a listener process; batch audit writes
Audit table consuming excessive disk spaceHigh write volume tables generating millions of audit recordsPartition by month; archive old partitions to cold storage; audit only specific columns with WHEN clause on trigger
current_setting('app.user') returns NULLApplication not setting session variable before database operationsSet default in trigger: COALESCE(current_setting('app.user', true), current_user); add connection pool checkout hook
Audit log INSERT fails, blocking application operationAudit table full, permission error, or constraint violationUse BEGIN... EXCEPTION WHEN OTHERS THEN NULL; END in trigger to prevent audit failures from blocking operations; alert on audit failures
Cannot determine which columns changed in UPDATEFull row stored as JSON, no column-level diffAdd changed_columns computation in trigger: compare OLD and NEW field by field; store only changed fields in new_values

Examples

HIPAA-compliant audit logging for a healthcare database: Audit triggers on patient_records, prescriptions, and lab_results tables capture all modifications with practitioner identity. Audit logs are immutable (no UPDATE/DELETE grants), partitioned monthly, and archived to encrypted S3 after 1 year. Quarterly compliance reports show access patterns per practitioner and flag unusual access (patient records accessed without an appointment).

Detecting unauthorized data modifications: Audit log query reveals 500 DELETE operations on the billing table by a service account at 3 AM, outside normal business hours. Alert triggers for bulk operations exceeding 100 rows. Investigation traces the operations to a misconfigured cleanup job. Audit log provides the complete list of deleted records for restoration.

GDPR data access request fulfillment: When a user requests their data access log under GDPR Article 15, the audit system provides a complete history of who accessed or modified their personal data: SELECT changed_by, action, changed_at, changed_columns FROM audit_log WHERE table_name = 'users' AND record_id = '12345' ORDER BY changed_at. The report is generated within the 30-day compliance window.

Resources

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

33.28%
按下载量换算71

Claude

28.5%
按下载量换算61

Cursor

18.35%
按下载量换算39

Gemini CLI

10.36%
按下载量换算22

安全审计

Gen Agent Trust Hub

可疑

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills