惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
美团技术团队
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
雷峰网
雷峰网
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗
IT之家
IT之家
Google DeepMind News
Google DeepMind News
D
Docker
J
Java Code Geeks
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 【当耐特】
V
V2EX
Hugging Face - Blog
Hugging Face - Blog
博客园 - Franky
月光博客
月光博客
宝玉的分享
宝玉的分享
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How to Audit Only Critical Operations Like DROP TABLE in ...
Michael · 2026-05-15 · via DEV Community

Michael

GBase 8a’s audit log can capture virtually every SQL operation. To keep logs lean and focused on security, you can configure a policy that records only high‑risk actions — like DROP TABLE — using the CREATE AUDIT POLICY command. This post shows you exactly how to set it up in a gbase database.

What the Audit Log Can Record

The audit framework covers all major SQL categories:

  • DDL: CREATE, ALTER, DROP (including DROP_TABLE, DROP_DB), TRUNCATE, RENAME_USER
  • DML: SELECT, INSERT, DELETE, UPDATE, LOAD, MERGE
  • DCL & Users: GRANT, REVOKE, CREATE_USER, DROP_USER
  • OTHERS: any SQL not explicitly listed

Step‑by‑Step: Record Only High‑Risk Operations

1. Enable Audit Logging to a Table

SET GLOBAL log_output = 'table';
SET GLOBAL audit_log = 1;

-- Verify
SHOW VARIABLES LIKE '%audit_log%';
SHOW VARIABLES LIKE '%log_output%';

Enter fullscreen mode Exit fullscreen mode

2. Create an Audit Policy (the key part)

Use CREATE AUDIT POLICY and list the exact commands you want to capture. Commands must be separated by commas with no spaces.

-- Only record DROP_TABLE, DROP_DB, TRUNCATE, DROP_USER
CREATE AUDIT POLICY audit_critical (
    enable = 'Y',
    sql_commands = 'DROP_TABLE,DROP_DB,TRUNCATE,DROP_USER'
);

Enter fullscreen mode Exit fullscreen mode

3. Test and Verify

Run a forbidden operation and check the log:

DROP TABLE t1;
DROP DATABASE test_db;

SELECT start_time, user_host, sql_command, LEFT(sql_text, 100) AS sql_sample
FROM gbase.audit_log
ORDER BY start_time DESC;

Enter fullscreen mode Exit fullscreen mode

If the policy is correct, you’ll see only DROP_TABLE and DROP_DB events — ordinary SELECT statements won’t appear.

4. Clean Up (Optional)

TRUNCATE SELF audit_log;

Enter fullscreen mode Exit fullscreen mode

Going Further: Fine‑Grained Filtering

You can combine sql_commands with other dimensions for even tighter control:

Parameter Description Example
user Limit to a specific user user='app_user'
hosts Filter by IP pattern (supports %, _) hosts='192.168.1.%'
db Limit to a particular database db='finance_db'
long_query_time Only log slow queries (seconds) long_query_time=10
status Capture only failed or successful ops status='FAILED'

Example: record DROP_TABLE only when executed by admin from host 192.168.1.100 on the prod_db database.

CREATE AUDIT POLICY audit_admin_drop (
    enable = 'Y',
    user = 'admin',
    hosts = '192.168.1.100',
    db = 'prod_db',
    sql_commands = 'DROP_TABLE'
);

Enter fullscreen mode Exit fullscreen mode

With a targeted policy like this, your gbase database keeps a tight security audit trail without drowning in unnecessary log data. It’s a simple but powerful capability every DBA should have in their toolkit.