Diagnose historical lock wait issues on PolarDB MySQL and RDS MySQL instances. Identifies the root cause, complete lock chain, and lock holder.
Architecture: PolarDB/RDS MySQL + DAS (Database Autonomy Service) + Aliyun CLI
Supported lock types: InnoDB row locks (Record/Gap/Next-Key), MDL (Metadata Lock), Table Lock, Deadlock, FLUSH cascading, AUTO-INC Lock
Pre-check: Aliyun CLI >= 3.3.3 required
Run
aliyun versionto verify >= 3.3.3. If not installed or version too low, runcurl -fsSL https://aliyuncli.alicdn.com/setup.sh | bashto install/update, or seereferences/cli-installation-guide.mdfor installation instructions.
Pre-check: Aliyun CLI plugin update required
[MUST] run
aliyun configure set --auto-plugin-install trueto enable automatic plugin installation. [MUST] runaliyun plugin updateto ensure that any existing plugins are always up-to-date.
[MUST] CLI User-Agent — Every aliyun CLI command that calls a cloud API must include:
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-history-lock-diagnose/{session-id}
(See Observability section below for session-id generation)
Runtime Requirements:
Pre-check: Alibaba Cloud Credentials Required
Security Rules:
- NEVER read, echo, or print AK/SK values
- NEVER ask the user to input AK/SK directly
- ONLY use
aliyun configure listto check credential statusbash
aliyun configure listCheck the output for a valid profile (AK, STS, or OAuth identity).
If no valid profile exists, STOP here.
Required permissions: hdm:GetDasSQLLogHotData, hdm:GetDeadLockHistory, hdm:GetDeadLockDetail, hdm:CreateLatestDeadLockAnalysis, hdm:DescribeSqlLogConfig, hdm:GetMySQLAllSessionAsync
[MUST] Permission Failure Handling: When any command or API call fails due to permission errors:
- Read
references/ram-policies.mdfor the full permission list- Use
ram-permission-diagnoseskill to guide the user- Pause and wait until permissions are granted
IMPORTANT: ALL parameters MUST be confirmed with the user before execution.
ParameterRequiredDescriptionInstanceIdYesRDS (rm-xxx) or PolarDB (pc-xxx)ProblemTimeYesLock wait time (e.g. 2026-06-08 17:02:35.894)ThreadIDYesBlocked thread IDBlockedSQLYesBlocked SQL statement
Upon loading this skill, generate a random session ID (32-char lowercase hex string) once for the entire session. Use it as {session-id} below.
Rule: Every aliyun CLI command that calls a cloud API MUST include --user-agent.
Local commands ( configure, plugin, version) do not support this flag.
text
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-history-lock-diagnose/{session-id}
bash
aliyun version
aliyun configure list
[MUST] Execute the script directly with the command below. Do NOT read
scripts/smart-lock-diagnosis.py— it is 3700+ lines and reading it will waste context and slow down execution. The script handles everything internally: SQL audit query, lock type detection, blocking chain analysis, deadlock diagnosis, and report generation.
bash
SKILL_SESSION_ID={session-id} python3 scripts/smart-lock-diagnosis.py \
--instance-id {InstanceId} \
--time "{ProblemTime}" \
--thread-id {ThreadID} \
--sql "{BlockedSQL}"
The script automatically:
Extract the key findings from the script output and present to the user:
Key requirements:
10:39:28.390)GetDasSQLLogHotData retention depends on instance config (check HotRetention field). Data outside retention window may be unavailableGetDeadLockHistory) can query historical records beyond hot data windowCreateLatestDeadLockAnalysis triggers DAS server-side deadlock parsing (classified as Write) but does not alter the databaseThis is a diagnostic skill. No user resources are created or modified; no cleanup required.
Reference FileDescriptionreferences/ram-policies.mdRAM permission policy listreferences/related-commands.mdCLI command referencereferences/best-practices.mdDiagnosis best practices and known limitationsreferences/acceptance-criteria.mdAcceptance criteria and anti-patternsreferences/cli-installation-guide.mdCLI installation guidereferences/transaction-lifecycle.mdTransaction lifecycle rulesreferences/verification-method.mdVerification methods and checklist