plugin-database-plus-manager
v1.3.0
Published
Advanced multi-datasource database tooling, streaming log console, slow SQL monitor, audit diff trail, request tracing, external storage backup/offload, alerting, and AI diagnostics.
Maintainers
Readme
plugin-database-plus-manager
Database Plus Manager is a NocoBase 2.x plugin that unifies multi-datasource database tooling and real-time Logs & Audit observability under a single shared DataSource selector.
- Supports NocoBase Main (
PostgreSQL,MySQL,MariaDB,SQLite), External SQL (PostgreSQL,MySQL,MariaDB,MSSQL), and External Non-SQL (e.g.Elasticsearch) data sources connected throughdataSourceManager. - Zero Schema Pollution on external databases: All 7 observability/audit tables (
dpmLogConfigs,dpmAuditLogs,dpmSlowQueries,dpmAlertRules,dpmAlertLogs,dpmAiRecords,dpmLogBackups) live strictly in NocoBase'smaindatabase with adataSourceKeydiscriminator; external databases are never modified. - External Storage Backup & Offload: Integrates directly with NocoBase File Storage Management (
@nocobase/plugin-file-manager—storagescollection, supportinglocal, AWSs3/ MinIO / Cloudflare R2,ali-oss,tx-cos,s3-private, andsftp-private) to compress, archive, and offload rotated log files (.log.gz) and Audit/Slow-SQL records (.jsonl.gz) off local disk/DB while keeping online streaming preview and 1-click DB restore available. - Dual-runtime client support (
clientv1 andclient-v2) with full localization (en-US,vi-VN,zh-CN).
Feature Summary
1. Shared Multi-DataSource Header
- Single top-level Data source selector automatically discovers all active data sources from
dataSourceManagerwith capability flags (supportsSql,supportsIndexes,supportsKeyset,supportsAggregate). - Workspace switcher toggles between Database Tools and Logs & Audit.
- In Logs & Audit mode, an
All data sourcesoption aggregates metrics, files, slow queries, audit records, and traces across every connected data source.
2. Database Tools (5 Tabs)
| Tab | Capabilities |
| --- | --- |
| Pagination | Configure global default pagination mode (offset, keyset, cursor), defaultLimit, and per-source/collection overrides (${dataSource}:${collection}). Includes a Cursor / Keyset Playground supporting custom primary keys and NULL-safe ordering. |
| Statistics | Inspect collections, physical tables/views, row counts, estimated sizes, schemas, primary keys, and field/column metadata across SQL and Non-SQL data sources, with an Include system collections toggle. |
| Indexes | List, create (single/composite, ASC/DESC, UNIQUE), and drop SQL indexes on main and external SQL data sources with custom schema support. Displays a clear capability notice for Non-SQL sources. |
| SQL Console | Read-only SQL console (SELECT / WITH only) with write/DDL blocking, dialect-aware row limiting (including MSSQL ORDER BY + OFFSET ... FETCH NEXT), tabular result viewer, and truncation metadata. |
| Aggregate | Visual aggregate query builder (COUNT, SUM, AVG, MIN, MAX) with multi-dimension grouping, sorting, and collection/field/row-level ACL enforcement. |
3. Logs & Audit (8 Tabs + AI Diagnostics Drawer)
| Tab / Surface | Capabilities |
| --- | --- |
| Overview | Daily KPIs (audits, errors, slow queries, alerts, log file count & disk usage), 7-day operation/error trend chart, Top Slow Queries, Top Active Users, and Top Modified Collections. |
| Log Console | Browse NocoBase system/request/SQL logs alongside per-DataSource daily rotating logs (storage/logs/<app>/datasources/<safeKey>/sql_YYYY-MM-DD.log, operations_YYYY-MM-DD.log). Includes byte-offset Live Tail, level/keyword/ReDoS-safe Regex search, Natural-Language filter (EN/VI), truncate/delete, and .tar.gz archive download. |
| Slow Queries | Captures slow SQL queries on main, external SequelizeDataSource connections, and slow Non-SQL repository operations with normalized SQL fingerprints and reqId correlation. Provides 1-click jump directly to Database Tools -> SQL Console (pre-filled SQL + target DataSource), Indexes, or AI Diagnose. |
| Audit & Diff | Captures write operations (create, update, destroy, batch*, and sensitive plugin admin actions) with Visual Field Diff (old vs new), automatic sensitive-field masking (password, secret, token, apiKey, etc.), zero-diff skip, multi-field filtering, and formula-injection-safe CSV (UTF-8 BOM) / JSON export. |
| Request Trace | Reconstructs full request Lifecycle Waterfalls by X-Request-Id (reqId), correlating HTTP inbound/outbound, Audit records, Slow SQL entries, and matching log file lines. |
| Alerts | Rule-based anomaly alerting for error_log, status_5xx, slow_sql, and keyword events with per-DataSource scoping, silence windows (silenceMinutes), and delivery history. Supports NocoBase Notification Manager, NocoBase Workflow, Slack, Teams, Telegram, WeCom, DingTalk, Feishu, and Custom Webhooks with SSRF protection (blocking private/loopback/metadata IPs). |
| External Storage | Integrates with NocoBase File Storage Management (storages: S3, MinIO, Cloudflare R2, OSS, COS, s3-private, sftp-private, local) across 3 modes (local_only, backup_copy, offload_external) with global or per-DataSource overrides. Includes live connection probe, SHA-256 verified .log.gz / .jsonl.gz archiving, immediate local file/DB purge on offload, online remote .gz stream preview (with search + AI Diagnose), .gz download, and 1-click DB restore into dpmAuditLogs / dpmSlowQueries. |
| Config & Retention | Hot-reload runtime settings (log level, SQL logging, slow query threshold, audit collection/action filters) with per-DataSource overrides synced across HA nodes via Redis PubSub (syncMessageManager). Includes disk/DB storage stats, HA-locked scheduled sync & cleanup (app.lockManager), and batched cleanup protecting .audit.json. |
| AI Diagnostics & SQL Advisor | Diagnoses errors and slow queries using NocoBase AI Employees / LLM services or the Built-in Rule Engine fallback. Sanitizes PII/tokens before dispatch, automatically attaches target table schema & existing indexes, renders formatted Markdown reports, and persists diagnosis history. |
Quick Start Guide
1. Install & Enable
- Install or copy
plugin-database-plus-managerinto NocoBase's plugin storage directory (or install from npm). - Enable Database Plus Manager in Plugin Manager (
Settings -> Plugin manager). - When upgrading from
1.1.x/1.2.xto1.3.x, NocoBase automatically syncs the 7dpm*tables onmain(yarn nocobase upgradeor container startup--quickstart).
2. Configure Permissions (ACL)
pm.plugin-database-plus-manager: Full admin access to the Database Plus Manager settings page, SQL/Index/Aggregate tools, and all Logs & Audit endpoints.pm.plugin-database-plus-manager.cursor(and defaultloggedInallowance ondatabasePlusManager:cursor): Allows authenticated users to invoke cursor/keyset pagination without exposing admin SQL/index/log endpoints.
3. Using Database Tools & External DataSources
- Open Settings -> Database Plus Manager (
/v/admin/settings/database-plus-manager). - Select a data source from the top Data source dropdown (for example
Main (postgres), an external PostgreSQL/MySQL/MSSQL connection, or an Elasticsearch data source). - Use Pagination, Statistics, Indexes, SQL Console, or Aggregate against the selected source.
- Non-SQL data sources automatically disable raw SQL and index DDL with an informational notice while keeping Statistics and Logs & Audit available.
4. Using Logs & Audit
- Switch the top-right segmented toggle to Logs & Audit.
- Choose either
All data sourcesfor global visibility or a specific data source to isolate its KPIs, log files, slow queries, and audit trail. - Investigate a Slow Query:
- Open Slow Queries and inspect high-latency entries.
- Click SQL Console to jump straight into read-only SQL Console with the data source and query pre-filled, click Indexes to inspect/add missing indexes on the target table, or click AI Diagnose to analyze the query with schema & index context.
- Tune Runtime Logging Without Restart:
- Open Config & Retention, select either Global (
All data sources) or a specific DataSource to create scoped overrides (for example loweringslow_query_threshold_mstemporarily on one external database), and click Apply & Save. - In multi-node HA clusters, config updates automatically broadcast to peer nodes via
syncMessageManager.
- Open Config & Retention, select either Global (
- Configure External Storage Backup & Offload:
- Prerequisite: Configure any desired storage engine in NocoBase File Manager (
Settings -> File manager -> Storages, e.g., AWS S3, MinIO, Cloudflare R2, Aliyun OSS, Tencent COS,s3-private,sftp-private, or a secondary path). - Open Logs & Audit -> External Storage (select
All data sourcesfor global policy or a specific DataSource for scoped overrides). - Choose a Storage Mode:
local_only(default): Keep log files and DB audit/slow-SQL rows locally only.backup_copy: Compress rotated log files (.log.gz) anddpmAuditLogs/dpmSlowQueriesbatches (.jsonl.gz) to external storage withSHA-256verification while keeping local copies untilretention_days.offload_external: Upload compressed.gzarchives to external storage, verifySHA-256, record index metadata indpmLogBackups, and immediately purge/truncate local log files and DB rows older thanoffload_local_hot_hoursto keep local disk & DB lean.
- Click Test Storage Connection to verify live upload/read/delete permissions, Save Policy to persist, and Sync / Offload Now (or Force Include Today & Hot Window) to trigger immediate archiving.
- From the External Log & Audit Archives table below, click Preview to stream and search lines directly from remote
.gzfiles (with AI Diagnose support), Download to fetch the.gzfile, or Restore to DB on.jsonl.gzarchives to re-hydratedpmAuditLogs/dpmSlowQueriesfor SQL/UI filtering.
- Prerequisite: Configure any desired storage engine in NocoBase File Manager (
API Endpoints (databasePlusManager)
- Database Tools:
getSettings,saveSettings,cursor,statistics,listIndexes,addIndex,removeIndex,runSql,aggregate - Logs & Files:
logsDashboard,logsFiles,logsReadLines,logsTail,logsClearFile,logsDeleteFile,logsDownload - Slow SQL, Audit & Trace:
logsSlowQueries,logsAuditList,logsAuditExport,logsRecentTraces,logsTrace,logsNlFilter - External Storage & Offload:
logsStorageOptions,logsTestStorage,logsSyncExternalStorage,logsListBackups,logsPreviewBackup,logsDownloadBackup,logsDeleteBackup,logsRestoreBackup - Runtime Config & Retention:
logsGetConfigs,logsUpdateConfigs,logsResetConfigs,logsStorageStats,logsClean,logsCleanCount,logsCleanBatch - Alerts & AI Diagnostics:
logsListAlertRules,logsSaveAlertRule,logsDeleteAlertRule,logsTestAlert,logsListAlertLogs,logsAiMeta,logsAiAnalyze,logsAiHistory,logsDeleteAiRecord
Development, Testing & Packaging
Run from the repository root (PowerShell on Windows):
# Client unit/component tests
yarn test packages/plugins/plugin-database-plus-manager/src/client-v2/__tests__/logs-workspace.test.tsx --run
yarn test packages/plugins/plugin-database-plus-manager/src/client-v2/__tests__/panes.test.tsx --run
# Server unit & integration tests (run sequentially)
yarn test packages/plugins/plugin-database-plus-manager/src/server/__tests__/external-datasource-and-logs-unit.test.ts
yarn test packages/plugins/plugin-database-plus-manager/src/server/__tests__/logs-integration.test.ts
yarn test packages/plugins/plugin-database-plus-manager/src/server/__tests__/actions-integration.test.ts
# Lint, build, and pack
yarn eslint --fix "packages/plugins/plugin-database-plus-manager/src"
yarn nocobase build plugin-database-plus-manager --no-dts
Set-Location "packages/plugins/plugin-database-plus-manager"; npm packLicense
Apache-2.0
