SET READ_COMMITTED_SNAPSHOT ON은 얼마나 걸리나요?
실행하는 데 얼마나 걸립니까
ALTER DATABASE [MySite] SET READ_COMMITTED_SNAPSHOT ON
방금 실행했는데 10 분이 걸렸습니다.
적용 여부는 어떻게 확인할 수 있나요?
sys.databases보기를 사용하여 READ_COMMITTED_SNAPSHOT 설정의 상태를 확인할 수 있습니다 . is_read_committed_snapshot_on컬럼 의 값을 확인하십시오 . 이미 질문하고 대답했습니다 .
기간과 관련하여 온라인 설명서에는이 작업이 수행 될 때 데이터베이스에 대한 다른 연결이있을 수 없다고 나와 있지만 단일 사용자 모드는 필요하지 않습니다. 따라서 다른 활성 연결에 의해 차단 될 수 있습니다. 실행 sp_who(또는 sp_who2)하여 해당 데이터베이스에 연결된 다른 항목을 확인합니다.
이 시도:
ALTER DATABASE generic SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK IMMEDIATE
OK (저는 원래 질문자입니다) 그래서 이번 내내 제가 똥을 활성화하지 않은 것으로 밝혀졌습니다.
다음 은 스냅 샷 모드를 활성화하고 활성화되었는지 확인하기 위해 실행할 최종 코드 입니다.
SELECT is_read_committed_snapshot_on, snapshot_isolation_state_desc,snapshot_isolation_state FROM sys.databases WHERE name='shipperdb'
ALTER DATABASE shipperdb SET allow_snapshot_isolation ON
ALTER DATABASE shipperdb SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE shipperdb SET read_committed_snapshot ON
ALTER DATABASE shipperdb SET MULTI_USER
SELECT is_read_committed_snapshot_on, snapshot_isolation_state_desc,snapshot_isolation_state FROM sys.databases WHERE name='shipperdb'
이것은 연결이 활성화 된 상태에서도 작동합니다 (아마도 연결이 쫓겨나도 괜찮습니다).
이전 및 이후 상태를 볼 수 있으며 거의 즉시 실행됩니다.
중대한:
위의 READ_COMMITTED_SNAPSHOT 옵션은 .NET
의 IsolationLevel.ReadCommitted에 해당합니다. 위의 ALLOW_SNAPSHOT_ISOLATION 옵션 은 .NET 의 IsolationLevel.Snapshot에 해당합니다.
.NET 팁 :
Isolationlevel.ReadCommitted데이터베이스에서 활성화되지 않은 경우에도 코드에서 허용되는 것처럼 보입니다 . 경고가 표시되지 않습니다. 그러니 자신에게 호의를 베풀고 내가 한 것처럼 3 년 동안이라고 가정하기 전에 켜져 있는지 확인하십시오!
C #을 사용 하는 경우이 트랜잭션에서 쓰기를 수행하지 않는 한 ReadCommittedIsolationLevel을 원할 것입니다 Snapshot.
READ COMMITTED SNAPSHOT낙관적 읽기와 비관적 쓰기를 수행합니다. 반대로 SNAPSHOT낙관적 읽기와 낙관적 쓰기를 수행합니다. (여기에서)
bool snapshotEnabled = true;
using (var t = new TransactionScope(TransactionScopeOption.Required,
new TransactionOptions
{
IsolationLevel = IsolationLevel.ReadCommitted
}))
{
using (var shipDB = new ShipperDBDataContext())
{
}
}
또한 거래를 '승격 할 수 없음'에 대한 오류가 발생할 수 있습니다. .NET Framework 2.0의 System.Transactions 소개 에서 '프로모션'을 검색합니다 .
외부 데이터베이스 (또는 두 번째 데이터베이스)에 연결하는 것과 같은 특별한 작업을 수행하지 않는 한 새 DataContext를 만드는 것과 같은 간단한 작업으로 인해이 문제가 발생할 수 있습니다. 초기화시 자체 데이터 컨텍스트를 '스푼'하는 캐시가 있었고 트랜잭션을 전체 분산 트랜잭션으로 에스컬레이션하려고했습니다.
The solution was simple :
using (var tran = new TransactionScope(TransactionScopeOption.Suppress))
{
using (var shipDB = new ShipperDBDataContext())
{
// initialize cache
}
}
See also Deadlocked article by @CodingHorror
Try this code:
if(charindex('Microsoft SQL Server 2005',@@version) > 0)
begin
declare @sql varchar(8000)
select @sql = '
ALTER DATABASE ' + DB_NAME() + ' SET SINGLE_USER WITH ROLLBACK IMMEDIATE ;
ALTER DATABASE ' + DB_NAME() + ' SET READ_COMMITTED_SNAPSHOT ON;
ALTER DATABASE ' + DB_NAME() + ' SET MULTI_USER;'
Exec(@sql)
end
I tried the command:
ALTER DATABASE MyDB SET READ_COMMITTED_SNAPSHOT ON
GO
against a dev box but the it took 10+ minutes and so I killed it.
I then found this:
https://willwarren.com/2015/10/12/sql-server-read-committed-snapshot/
and used his code block (which took about 1:26 to run):
USE master
GO
/**
* Cut off live connections
* This will roll back any open transactions after 30 seconds and
* restricts access to the DB to logins with sysadmin, dbcreator or
* db_owner roles
*/
ALTER DATABASE MyDB SET RESTRICTED_USER WITH ROLLBACK AFTER 30 SECONDS
GO
-- Enable RCSI for MyDB
ALTER DATABASE MyDB SET READ_COMMITTED_SNAPSHOT ON
GO
-- Allow connections to be established once again
ALTER DATABASE MyDB SET MULTI_USER
GO
-- Check the status afterwards to make sure it worked
SELECT is_read_committed_snapshot_on
FROM sys.databases
WHERE [name] = 'MyDB '
Try use master database before altering current database.
USE Master
GO
ALTER DATABASE [YourDatabase] SET READ_COMMITTED_SNAPSHOT ON
GO
I didn't take a second for me when i changed my DB to single user
Try Shut off the other SQL services so that only the SQL server service is running.
Mine ran for 5 minutes then I cancelled it because it was obvious nothing was happening. Its a brand new server so there are no other users connected. I shut off the SQL Reporting Services and then ran it again.. took less than a second to complete.
참고URL : https://stackoverflow.com/questions/232333/how-long-should-set-read-committed-snapshot-on-take
'IT TIP' 카테고리의 다른 글
| C ++의 Qt에 파일이 있는지 확인하는 방법 (0) | 2020.11.01 |
|---|---|
| 'ABC'.replace ('B ','$` ')가 AAC를 제공하는 이유 (0) | 2020.11.01 |
| Javascript가 모든 웹 페이지의 소스를 읽을 수 있습니까? (0) | 2020.10.31 |
| Django에서 새로운 사용자 지정 권한 추가 (0) | 2020.10.31 |
| npm의 일반 종속성에 대한 bundledDependencies의 장점 (0) | 2020.10.31 |