5061: ALTER DATABASE failed because a lock could not be placed on database (데이터베이스에 락을 걸 수 없어 ALTER DATABASE 실패)
SQL Server의미
ALTER DATABASE 작업(예: single-user 모드 전환, 파일 변경, 옵션 설정)이 다른 활성 연결/세션이 데이터베이스를 사용하고 있어 필요한 락을 획득할 수 없었다.
원인
데이터베이스가 사용 중일 때 작업을 시도해, 활성 사용자 연결 때문에 SET SINGLE_USER, RESTRICTED_USER 또는 유사한 옵션 변경에 필요한 배타적 락을 획득할 수 없었다. 애플리케이션 연결이 열려 있는 상태에서 잦은 배포/유지보수를 할 때 흔하다.
해결 방법
데이터베이스에 연결된 다른 세션을 식별하고(sys.dm_exec_sessions, sp_who2) 안전하게 닫는다. 유지보수 시에는 ROLLBACK 옵션으로 열린 트랜잭션을 롤백하면서 모드를 변경한다: ALTER DATABASE [db] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; 애플리케이션 트래픽이 적을 때나 유지보수 시간에 작업을 수행한다. 완료 후 MULTI_USER로 되돌리는 것을 잊지 않는다.
같은 데이터베이스의 다른 항목
- 40501The service is currently busy. Retry the request after 10 seconds (서비스가 현재 바쁨. 10초 후 재시도)
- 8645A time out occurred while waiting for memory resources to execute the query (쿼리 실행을 위한 메모리 리소스를 기다리는 중 타임아웃 발생)
- 8651Could not perform the operation because the requested memory grant was not available (요청한 memory grant를 사용할 수 없어 작업을 수행할 수 없음)
- 3702Cannot drop database because it is currently in use (사용 중이어서 데이터베이스 삭제 불가)
- 15138The database principal owns a schema in the database, and cannot be dropped (database principal이 스키마를 소유하고 있어 삭제 불가)
- 1934INSERT/UPDATE failed because the following SET options have incorrect settings (다음 SET 옵션의 설정이 잘못되어 INSERT/UPDATE 실패)
- 468Cannot resolve the collation conflict