대량의 트랜잭션으로 인한 LogShipping 복원 지연시, 최종 복원일자 찾기
아래 쿼리를 통해, LogShipping Log 복원이 주 서버에서 언제 백업된 파일까지 복원했는지를 찾을 수 있다.
--
USE msdb
GO
/*2015-03-16 SQLDBWook@gmail.com / SQL Server 2012*/
--Primary 서버에서 대량의 트랜잭션이 발생한 이후,
-- LogShipping Secondary 서버의 IO병목등의 이유로 인해 Log복원 대기가 발생할 시
-- 현재까지 복원된 Log 중 최종 LogFile의 백업일시를 구한다.
DECLARE @vLogShippedDatabaseName sysname= N'trigger_sync_db_from_local_pcbang'
, @vDateChkVal char(2)= LEFT(YEAR(getdate()),2)
SELECT DATEADD( HOUR
,DATEDIFF(HOUR,GETUTCDATE(),GETDATE()) --Diff Hour With UTC Time
,CAST(
LEFT(SUBSTRING(last_restored_file,CHARINDEX(@vDateChkVal,last_restored_file,1),14),4) + '-'
+ SUBSTRING(SUBSTRING(last_restored_file,CHARINDEX(@vDateChkVal,last_restored_file,1),14),5,2) + '-'
+ SUBSTRING(SUBSTRING(last_restored_file,CHARINDEX(@vDateChkVal,last_restored_file,1),14),7,2) + ' '
+ SUBSTRING(SUBSTRING(last_restored_file,CHARINDEX(@vDateChkVal,last_restored_file,1),14),9,2) + ':'
+ SUBSTRING(SUBSTRING(last_restored_file,CHARINDEX(@vDateChkVal,last_restored_file,1),14),11,2) + ':'
+ SUBSTRING(SUBSTRING(last_restored_file,CHARINDEX(@vDateChkVal,last_restored_file,1),14),13,2)
AS datetime
)
) LastRestoredLogBackupsBackupDate
--, LEFT(SUBSTRING(last_restored_file,CHARINDEX(@vDateChkVal,last_restored_file,1),14),4) + '-'
-- + SUBSTRING(SUBSTRING(last_restored_file,CHARINDEX(@vDateChkVal,last_restored_file,1),14),5,2) + '-'
-- + SUBSTRING(SUBSTRING(last_restored_file,CHARINDEX(@vDateChkVal,last_restored_file,1),14),7,2) + ' '
-- + SUBSTRING(SUBSTRING(last_restored_file,CHARINDEX(@vDateChkVal,last_restored_file,1),14),9,2) + ':'
-- + SUBSTRING(SUBSTRING(last_restored_file,CHARINDEX(@vDateChkVal,last_restored_file,1),14),11,2) + ':'
-- + SUBSTRING(SUBSTRING(last_restored_file,CHARINDEX(@vDateChkVal,last_restored_file,1),14),13,2)
--, SUBSTRING(last_restored_file,CHARINDEX(@vDateChkVal,last_restored_file,1),14)
, *
FROM msdb.dbo.log_shipping_secondary_databases
WHERE secondary_database =@vLogShippedDatabaseName