polardb/polardbx-sql/polardbx-ttl20
- community
Checking that the SKILL.md file is still in the repository.
Generate correct TTL 2.0 definitions and archive table statements for PolarDB-X 2.0 Enterprise Edition AUTO mode. Analyzes table schemas to recommend the optimal archiving strategy (row-based or partition-based) and produces production-ready SQL. Also covers auto-add Range partitions (add-only, no cleanup). Triggers: "TTL", "TTL 2.0", "冷数据归档", "数据过期", "cold data archive", "TTL table", "数据生命周期", "expire data", "TTL配置", "LOCAL PARTITION", "TTL 1.0", "local partition迁移", "TTL迁移", "data expiration", "archiving", "归档", "过期清理", "TTL_EXPR", "MODIFY TTL", "ARCHIVE_TYPE", "TTL_CLEANUP", "TTL_ENABLE", "auto add partition", "自动加分区", "range partition auto", "自动预建分区", "分区自动扩展", "Range分区自动", "partition pre-allocate", "auto-add-range-parts", "Range partition预创建", "分区不够用", "自动新增分区"
Install
npx vskill@latest install polardb/polardbx-sql/polardbx-ttl20SKILL.md
PolarDB-X TTL 2.0 — Cold Data Archiving & Auto-Add Range Partitions
Generate correct TTL (Time-to-Live) definitions and archive table statements for PolarDB-X 2.0 Enterprise Edition (AUTO mode). This skill covers two scenarios:
- Cold data archiving / data expiration: Analyzes table schemas, recommends row-based or partition-based archiving strategy, produces production-ready SQL.
- Auto-add Range partitions (add-only, no cleanup): Configures TTL mechanism to automatically pre-create future Range partitions, preventing write failures.
Scope: PolarDB-X 2.0 Enterprise Edition + AUTO mode database only.
⚠️ CRITICAL: Read the Reference Guide First
You MUST read the relevant reference guide in full BEFORE generating any SQL:
- TTL archiving / data expiration: references/ttl20-user-guide.md
- Auto-add Range partitions only: references/auto-add-range-parts.md
TTL syntax is unique to PolarDB-X and cannot be guessed from MySQL knowledge. Answering from memory WILL produce incorrect syntax.
Core Workflow
Scenario A: Cold Data Archiving / Data Expiration
- Read references/ttl20-user-guide.md in full.
- Gather required information from the user (table name, CREATE TABLE statement, TTL time column, retention period, whether archiving is needed).
- Analyze table schema and determine archiving strategy (broadcast → not supported; single table → ROW only; partition-based only when Range partition on TTL column, no GSI, no MAXVALUE).
- Generate complete SQL statements in order: TTL definition → local index (row-based only) → archive table creation → enable cleanup.
Scenario B: Auto-Add Range Partitions (Add-Only, No Cleanup)
- Read references/auto-add-range-parts.md in full.
- Confirm the table uses a time-type Range partition column (
DATE/DATETIME/TIMESTAMP). Integer-type columns are NOT supported. - Determine partition interval and pre-allocation count.
- Generate
ALTER TABLE ... MODIFY TTL SET ... TTL_CLEANUP = 'OFF'statement. - Always include the immediate trigger step:
ALTER TABLE ... CLEANUP EXPIRED DATA WITH TTL_CLEANUP = 'OFF';
TTL SQL Quick Reference
Correct ALTER TABLE TTL syntax:
TTL_EXPR by column type:
- DATETIME/TIMESTAMP/DATE: `
TTL_EXPR =colEXPIRE AFTER N {DAY|MONTH|YEAR} TIMEZONE '+08:00'` - INT/BIGINT (Unix seconds): `
TTL_EXPR = FROM_UNIXTIME(col) EXPIRE AFTER N {DAY|MONTH|YEAR} TIMEZONE '+08:00'` - INT/BIGINT (Unix milliseconds): `
TTL_EXPR = FROM_UNIXTIME(col/1000) EXPIRE AFTER N {DAY|MONTH|YEAR} TIMEZONE '+08:00'` - INT/BIGINT (non-timestamp, monotonic): `
TTL_EXPR =colEXPIRE OVER M PARTITIONS`
ARCHIVE_TYPE values: 'ROW' | 'PARTITION' | 'SUBPARTITION' — no other values exist.
Create archive table:
Key Constraints
- Broadcast tables do NOT support TTL at all. Do NOT recommend converting broadcast tables to another type solely for TTL.
- SINGLE tables DO support TTL using
ARCHIVE_TYPE = 'ROW'. Do NOT tell users TTL requires partitioned tables. - Row-based archiving requires a local index on the TTL column (single-column or composite with TTL column as first column).
- Partition-based archiving requires: Range partition on TTL column + NO MAXVALUE partition + NO GSI/UGSI.
- TTL_CLEANUP must stay 'OFF' until archive table creation completes — to avoid permanent deletion of data that should have been archived.
- LOCAL PARTITION (TTL 1.0) is DEPRECATED — never recommend it for new tables.
ANTI-PATTERNS — These Do NOT Exist in PolarDB-X
- ❌
TTL = col + INTERVAL 14 DAY - ❌
TTL_ACTION = ARCHIVE,TTL_COLUMN = 'col' - ❌
TTL_CONDITION = '...',TTL_JOB_INTERVAL = '...' - ❌
TTL BY col INTERVAL ... - ❌
TTL_ARCHIVE = true,TTL_ARCHIVE_TABLE = ...,TTL_ARCHIVE_STORAGE_POLICY = ...,TTL_DELETE_BATCH_SIZE = ... - ❌
CREATE STORAGE POLICY .../ARCHIVE COLD DATA— these do not exist in PolarDB-X - ❌
LOCAL PARTITION BY RANGE ...(TTL 1.0, deprecated)
Version Requirements
- Row-based archiving: instance version >=
5.4.19-20240927 - Partition-based archiving: instance version >=
5.4.20-20250328
Full Reference
- Cold data archiving / data expiration (complete workflow, decision tree, all examples, EXPIRE OVER, migration from TTL 1.0, management operations): references/ttl20-user-guide.md
- Auto-add Range partitions (first-level monthly/daily, second-level subpartitions, management commands): references/auto-add-range-parts.md
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingpolardbx-executor/src/main/resources/ai/skills/polardbx-ttl20/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/polardb/polardbx-sql/polardbx-ttl20)