1 Answer
- Newest
- Most votes
- Most comments
0
This is a common issue with metadata locks in RDS MySQL when applications maintain persistent connections. Here's how to address your situation:
- RDS-specific approaches to force schema/table drop:
- Use
CALL mysql.rds_kill_query()to terminate specific blocking queries rather than entire sessions - For persistent issues, consider a brief maintenance window where you:
- Modify security groups to block all application traffic temporarily
- Kill all existing connections with
mysql.rds_kill() - Execute your DDL operations
- Restore security group settings
- Note that dropping databases created via the RDS CreateDBInstance API is not allowed; only databases created using
rdsadmin.create_databasecan be dropped
- Recommended timeout values:
- Set
lock_wait_timeout(not metadata_lock_timeout) to a reasonable value like 60-300 seconds - Configure
wait_timeoutandinteractive_timeoutto shorter values (e.g., 300-600 seconds) during maintenance to prevent long-lived idle connections
- Preventing reconnects during maintenance:
- Temporarily modify security groups to block application traffic completely (not just restricting to 0.0.0.0/32 which is invalid)
- Use Network ACLs as a secondary defense if security groups aren't sufficient
- The Event Scheduler can be used to call
mysql.rds_killon RDS, but ensure it doesn't conflict with other maintenance operations
- Identifying and killing MDL holders:
- In Aurora MySQL version 2, you can identify blocked sessions by querying
performance_schematables orsysschema views - Example query to find blocking sessions:
SELECT blocking_session_id FROM performance_schema.metadata_locks ml
JOIN performance_schema.threads t ON ml.owner_thread_id = t.thread_id
WHERE ml.object_schema = 'your_schema_name'
- To enable MDL instrumentation, ensure the Performance Schema is enabled and the metadata_locks consumer is turned on
- Use
CALL mysql.rds_kill()with the identified session IDs
For your Hangfire issue specifically, I recommend temporarily blocking all application traffic at the security group level, killing all existing connections, performing your DDL operations, and then restoring access. This approach ensures the applications can't reconnect during the critical maintenance window.
Sources
Troubleshooting for Amazon RDS for Db2 - Amazon Relational Database Service
MySQL RDS instance connection error | AWS re:Post
synch/cond/sql/MDL_context::COND_wait_status - Amazon Aurora
answered 9 months ago
Relevant content
asked 4 years ago
- AWS OFFICIALUpdated 4 years ago

What I already tried:
Clarification (MySQL on RDS): I understand DROP DATABASE is allowed for normal MySQL schemas (not system schemas). The earlier note about only dropping DBs created via rdsadmin.create_database applies to RDS Oracle, not RDS MySQL.