ÁÖÀÇ´ë»ó °ü·Ã ( SUSPECT - °ü·ÃÄõ¸® )
Á¶È¸ : 317 À̸§ : ¾Æ¹«³ª
E-mail :

====================================================================================

-- 1. ¸ÕÀú ½Ã½ºÅÛ Ä«Å»·Î±×¸¦ ¼öÁ¤ ÇÒ ¼ö ÀÖ°Ô ÇØ ÁÝ´Ï´Ù.

Use master
Go

Sp_configure 'allow update', 1
Reconfigure with override
Go

-- 2. ÇØ´ç DB¸¦ ÀÀ±Þ ¸ðµå(32768 = emergency mode)·Î º¯°æ ÇÕ´Ï´Ù.
update sysdatabases set STATUS=STATUS|32768 where name = 'db_name'

-- 3. SQL ¼­ºñ½º¸¦ Àç½ÃÀÛ ÇÕ´Ï´Ù. Àç½ÃÀÛ ÈÄ ÇØ´ç DB¸¦ º¸¸é ÀÀ±Þ¸ðµå·Î ³ª¿À°Ô µÈ´Ù.
-- ¼­ºñ½º Àç½ÃÀÛ ÀÛ¾÷½Ã ¼­ºñ½º ÁßÁö ÈÄ ½ÃÀÛ Àü¿¡ ±âÁ¸ LDF ÆÄÀÏÀ» ¸®³×ÀÓ ¶Ç´Â CopyÇÏ¿© ¹ÝµíÀÌ Backup

-- 4. ·Î±× ÆÄÀÏ Àç »ý¼º
dbcc rebuild_log ('db_name' , 'ldf ÆÄÀÏÀÇ ¹°¸®Àû °æ·Î')
-- ex) dbcc rebuild_log ('TestDB' , 'D:\MSSQL\DATA\testdb_log.ldf')
-- ÀÌ »óÅ ±îÁö ÁøÇàÀ» ÇÏ°Ô µÇ¸é DBÀÇ Ldf ÆÄÀÏÀÌ ÃʱâÈ­ µÇ¸é¼­ DB´Â DBO¸¸ »ç¿ë»óÅ·ΠȰ¼ºÈ­ µË´Ï´Ù. ±×·¯¸é ÀÌÁ¦ DB¸¦ º¸Åë ¸ðµå·Î ¹Ù²Ù´Â ÀÛ¾÷À» ÇÕ´Ï´Ù.

-- 5. DBÀÇ »óŸ¦ ¸ÕÀú È®ÀÎ ÇÕ´Ï´Ù.
Select status From sysdatabases
-- À̶§ ¾Æ±î º¹±¸ÇÑ DBÀÇ »óÅ°¡ '2048 = dbo use only' »óÅ·ΠµÇ¾î ÀÖÀ» °Í ÀÔ´Ï´Ù.

-- 6. º¹±¸ÇÑ DBÀÇ status º¹¿ø.
update sysdatabases set status=STATUS&~32768 where name = 'db_name'

--
EXEC SP_RESETSTATSUS 'DBNAME' -- ÁÖÀÇ ´ë»ó ¸ðµå ÇØÁ¦

EXEC SP_CONFIGURE 'ALLOW UPDATES',0
GO
RECONFIGURE WITH OVERRIDE
GO

====================================================================================

SUSPECT -> EMERGENCY (¿øÀκм® & º¹±¸Ã³¸®) ->NORMAL



2k5

ALTER DATABASE yourDBname SET EMERGENCY -- ÀÀ±Þ»óÅ·Πº¯°æ // read-only·Î Ç¥½Ã,·Î±ëºñÈ°¼º,sysadmin¸¸ ¾×¼¼½º
DBCC CheckDB ('yourDBname') -- ¹®Á¦Á¡ ÆľÇ
ALTER DATABASE yourDBname SET SINGLE_USER WITH ROLLBACK IMMEDIATE -- Repar ÇÏ·Á¸é ½Ì±ÛÀ¯Àú »óÅ¿©¾ßÇÑ´Ù.
DBCC CheckDB ('yourDBname', REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE yourDBname SET MULTI_USER

ALTER DATABASE yourDBname SET ONLINE
http://www.codeproject.com/kb/reporting-services/sql_2005_suspect_database.aspx

http://lazydeveloper.net/2567064

-- 2k0ÀÇ SP_ATTACH_DB_SINGLE_FILE_DB ¿Í µ¿ÀÏ

CREATE DATABASE DB¸í
ON (NAME='DB¸í', FILENAME='c:\aa.mdf')
FOR ATTACH_REBUILD_LOG



-- 2k0ÀÇ dbcc rebuild_log¿Í µ¿ÀÏ

ALTER DATABASE dbname REBUILD LOG ON

(NAME=logname, FILENAME='LDFÆÄÀÏ°æ·Î\logname.ldf')







2k0

ÀÀ±Þ¸ðµå º¯°æ
USE MASTER
GO
EXEC SP_CONFIGURE 'ALLOW UPDATES',1
GO
RECONFIGURE WITH OVERRIDE
GO

UPDATE SYSDATABASES SET STATUS=STATUS|32768 WHERE NAME ='DBNAME' -- ÀÀ±Þ¸ðµå ¼³Á¤

DBCC REBUILD_LOG('DBNAME', 'H:\MSSQL\DATA\DBNAME_LOG2.LDF') -- ·Î±×ÆÄÀÏ Àç»ý¼º
DBCC CHECKDB('DBNAME') -- ¿øÀκм®

UPDATE SYSDATABASES SET STATUS=STATUS&~32768 WHERE NAME ='DBNAME' -- ÀÀ±Þ¸ðµå ÇØÁ¦

EXEC SP_RESETSTATSUS 'DBNAME' -- ÁÖÀÇ ´ë»ó ¸ðµå ÇØÁ¦

DBCC DBRECOVER('DBNAME', IGNOREERRORS) -- DB Àç½ÃÀÛ, ¿À·ù¹ß»ýÇصµ º¹¿øó¸®

Alter Database TestDB Set single_user with rollback immediate -- ´ÜÀÏ »ç¿ëÀÚ ¸ðµå ¼³Á¤
DBCC CHECKDB('DBNAME', REPAIR_ALLOW_DATA_LOSS) -- ¼Õ»óµÈ ÆäÀÌÁö º¹±¸

DBCC CHECKDB('DBNAME') -- º¹±¸ È®ÀÎ

ALTER DATABASE yourDBname SET MULTI_USER WITH NO_WAIT -- ´ÜÀÏ »ç¿ëÀÚ ¸ðµå ÇØÁ¦

EXEC SP_CONFIGURE 'ALLOW UPDATES',0
GO
RECONFIGURE WITH OVERRIDE
GO

create database µðºñ¸í on (filename = 'C:\ÆÄÀϸí.mdf') for ATTACH_REBUILD_LOG;

[Âü°í] Rebuild_log ¼­½ºÆåÆ® suspect (sqlmvp) |ÀÛ¼ºÀÚ ¿Õ´«º½ÀÌ





-- 1. ¸ÕÀú ½Ã½ºÅÛ Ä«Å»·Î±×¸¦ ¼öÁ¤ ÇÒ ¼ö ÀÖ°Ô ÇØ ÁÝ´Ï´Ù.
Use master
Go

Sp_configure 'allow update', 1
Reconfigure with override
Go

-- 2. ÇØ´ç DB¸¦ ÀÀ±Þ ¸ðµå(32768 = emergency mode)·Î º¯°æ ÇÕ´Ï´Ù.
update sysdatabases set STATUS=STATUS|32768 where name = 'db_name'

-- 3. SQL ¼­ºñ½º¸¦ Àç½ÃÀÛ ÇÕ´Ï´Ù. Àç½ÃÀÛ ÈÄ ÇØ´ç DB¸¦ º¸¸é ÀÀ±Þ¸ðµå·Î ³ª¿À°Ô µÈ´Ù.
-- ¼­ºñ½º Àç½ÃÀÛ ÀÛ¾÷½Ã ¼­ºñ½º ÁßÁö ÈÄ ½ÃÀÛ Àü¿¡ ±âÁ¸ LDF ÆÄÀÏÀ» ¸®³×ÀÓ ¶Ç´Â CopyÇÏ¿© ¹ÝµíÀÌ Backup

-- 4. ·Î±× ÆÄÀÏ Àç »ý¼º
dbcc rebuild_log ('db_name' , 'ldf ÆÄÀÏÀÇ ¹°¸®Àû °æ·Î')
-- ex) dbcc rebuild_log ('TestDB' , 'D:\MSSQL\DATA\testdb_log.ldf')
-- ÀÌ »óÅ ±îÁö ÁøÇàÀ» ÇÏ°Ô µÇ¸é DBÀÇ Ldf ÆÄÀÏÀÌ ÃʱâÈ­ µÇ¸é¼­ DB´Â DBO¸¸ »ç¿ë»óÅ·ΠȰ¼ºÈ­ µË´Ï´Ù. ±×·¯¸é ÀÌÁ¦ DB¸¦ º¸Åë ¸ðµå·Î ¹Ù²Ù´Â ÀÛ¾÷À» ÇÕ´Ï´Ù.

-- 5. DBÀÇ »óŸ¦ ¸ÕÀú È®ÀÎ ÇÕ´Ï´Ù.
Select status From sysdatabases
-- À̶§ ¾Æ±î º¹±¸ÇÑ DBÀÇ »óÅ°¡ '2048 = dbo use only' »óÅ·ΠµÇ¾î ÀÖÀ» °Í ÀÔ´Ï´Ù.

-- 6. º¹±¸ÇÑ DBÀÇ status º¹¿ø.
update sysdatabases set status=STATUS&~32768 where name = 'db_name'
--?? sp_resetstatus



-- 7. EMÀ» À翬°á Çϸé DBÀÇ »óÅ°¡ º¸ÅëÀ¸·Î º¯°æ µÊÀ» È®ÀÎ ÇÒ ¼ö ÀÖ½À´Ï´Ù.

-- 8. ÀÌÁ¦ DB¸¦ ´Ù½Ã ¸ÕÀú ½Ã½ºÅÛ Ä«Å»·Î±×¸¦ ¼öÁ¤ ÇÒ ¼ö ¾ø°Ô º¯°æÇØ ÁÝ´Ï´Ù.
Use master
Go
Sp_configure ¡®allow update¡¯, 0
Reconfigure with override
Go
-- ¿©±â±îÁö ÁøÇàÀÌ µÇ¾úÀ¸¸é ÀÌÁ¦´Â DB ÀÏ°ü¼º °Ë»ç¸¦ ÁøÇà ÇÏ¿© Àß ¸øµÈ ºÎºÐÀÌ ¾ø´ÂÁö È®ÀÎ ÇÕ´Ï´Ù.

-- 9. DBCC Checkdb
-- ÀÏ°ü¼º ¿À·ù°¡ ÀÖ´ÂÁö °Ë»ç ÇÕ´Ï´Ù.


-- 10. ÀÏ°ü¼º ¿À·ù¸¦ ¼öÁ¤Çϱâ À§ÇØ user¸¦ ½Ì±Û À¯Àú·Î º¯°æ ÇÕ´Ï´Ù.
Alter Database TestDB Set single_user with rollback immediate


-- 11. ¿À·ù¸¦ ¼öÁ¤ ÇÕ´Ï´Ù.
DBCC CheckDB('db_name', REPAIR_ALLOW_DATA_LOSS)
-- Ex) DBCC CheckDB ('TestDB' , REPAIR_ALLOW_DATA_LOSS)

-- 12. ¿À·ù¸¦ ¼öÁ¤ ÇÏ¿´´Ù¸é ´Ù½Ã DBCC Checkdb ¸¦ ¼öÇà ÇÕ´Ï´Ù.
-- 13. ¿À·ù°¡ ´õ ÀÌ»ó ¾ø´Ù¸é user¸ðµå¸¦ ´Ù½Ã º¯°æ ÇÏ¿© ÁÝ´Ï´Ù.
User master
go
Alter Database TestDB Set multi_user
go

-- ÀÛ¾÷ ¿Ï·á

http://laigo.kr/27

====================================================================================

[Tip]Á×¾î¹ö¸° Sharepoint ÆÀ »çÀÌÆ®¸¦ »ì·Á¶ó 1 - Suspect »óÅÂÀÇ DB ȸº¹½ÃÅ°±â
Á×¾î¹ö¸° Sharepoint ÆÀ »çÀÌÆ®¸¦ »ì·Á¶ó. »ç°Ç°³¿ä º¸±â

»ç°í Á÷ÈÄ, DB¸¦ SQL Management Studio¸¦ ¿­¾ú´õ´Ï DB´Â ¿ÀÇÁ¶óÀÎ »óÅ·ΠµÇ¾î ÀÖ¾ú°í, DB À̸§ ¿·¿¡ (Suspect)¶ó°í µÇ¾î ÀÖ¾ú´Ù. DB¿¡ ¼Õ»óÀÌ ÀÖ¾ú±¸³ª¶ó´Â ÁüÀÛÀ» ÇÒ ¼ö ÀÖ¾ú´Ù.

Âü°í·Î DatabaseÀÇ °¢ State´Â ´ÙÀ½°ú °°´Ù.

»óÅ Á¤ÀÇ
ONLINE
µ¥ÀÌÅͺ£À̽º´Â Á¢¼ÓÀÌ °¡´ÉÇÑ »óÅÂÀÌ´Ù. ºñ·Ï ¸®Ä¿¹ö¸®ÀÇ Undo°¡ ³¡³ªÁö ¾Ê¾Ò¾îµµ , ÇÁ¶óÀ̸Ӹ® ÆÄÀÏ ±×·ìÀÌ ¿Â¶óÀÎ »óÅÂÀÌ´Ù.

OFFLINE
µ¥ÀÌÅͺ£À̽º´Â Á¢¼Ó ºÒ°¡´ÉÇÑ »óÅÂÀÌ´Ù. »ç¿ëÀÚ°¡ ¸í½ÃÀûÀ¸·Î offlineÀ¸·Î ÁöÁ¤Çß´Ù¸é, ±×°ÍÀ» ´Ù½Ã µÇµ¹¸®±â Àü±îÁö´Â µ¥ÀÌÅͺ£À̽º´Â °è¼Ó offline»óÅ·Π¸Ó¹«¸£°Ô µÈ´Ù. ¿¹¸¦ µé¸é »õ·Î¿î µð½ºÅ©·Î ÆÄÀÏÀ» ¿Å±â±â À§Çؼ­ offline¸ðµå·Î ¹Ù²Ü ¼ö ÀÖ´Ù. ÀÌ ÆÄÀÏ À̵¿ ÀÛ¾÷ÀÌ ³¡³ª¸é ´Ù½Ã onlineÀ¸·Î µÇµ¹¸± ¼ö ÀÖ´Ù.

RESTORING
ÇÁ¶óÀ̸Ӹ® ÆÄÀÏ ±×·ìÀÇ Çϳª ÀÌ»óÀÇ ÆÄÀÏÀÌ º¹±¸µÇ°í ÀÖÀ» ¶§, ȤÀº ¼¼ÄÁ´õ¸® ÆÄÀÏ ±×·ìÀÇ ÆÄÀÏÀÌ º¹±¸µÇ°í ÀÖ´Â »óÅÂÀÌ´Ù. µ¥ÀÌÅͺ£À̽º Á¢¼ÓÀº ºÒ°¡´ÉÇÏ´Ù.

RECOVERING
µ¥ÀÌÅͺ£À̽º°¡ ¸®Ä¿¹ö¸®µÇ°í ÀÖ´Â »óÅÂÀÌ´Ù. ¸®Ä¿¹ö¸® ÇÁ·Î¼¼½º´Â ÀϽÃÀûÀÎ °ÍÀ¸·Î, ¸®Ä¿¹ö¸®°¡ ¼º°øµÇ¸é ÀÚµ¿ÀûÀ¸·Î µ¥ÀÌÅͺ£À̽º´Â ¿Â¶óÀÎ »óÅ·Πº¹±¸µÈ´Ù. ÇÏÁö¸¸ ¸®Ä¿¹ö¸®°¡ ½ÇÆÐÇÏ¸é µ¥ÀÌÅͺ£À̽º´Â suspect »óÅ·Π¹Ù²î°Ô µÈ´Ù. ÀÌ ¶§µµ ¿ª½Ã µ¥ÀÌÅͺ£À̽º Á¢¼ÓÀº ºÒ°¡´ÉÇÏ´Ù.

RECOVERY PENDING
¸®Ä¿¹ö¸® µµÁß¿¡ ¸®¼Ò½º °ü·Ã ¹®Á¦°¡ ¹ß»ýÇÑ »óÅÂÀÌ´Ù. µ¥ÀÌÅͺ£À̽º°¡ ¼Õ»óµÈ °ÍÀº ¾Æ´ÏÁö¸¸, ÆÄÀÏÀÌ ¾ø¾îÁ³À» ¼öµµ ÀÖ°í ½Ã½ºÅÛ »óÀÇ ¸®¼Ò½º Á¦¾à¶§¹®¿¡ ¹®Á¦°¡ ¹ß»ýÇßÀ» ¼öµµ ÀÖ´Ù. µ¥ÀÌÅͺ£À̽º Á¢¼ÓÀº ºÒ°¡´ÉÇÏ´Ù. ÀÌ ¹®Á¦¸¦ Ç®±â À§Çؼ­´Â »ç¿ëÀÚÀÇ ÇൿÀÌ ÇÊ¿äÇϸç, ±×·¡¾ß¸¸ÀÌ ¸®Ä¿¹ö¸® ÇÁ·Î¼¼½º°¡ ¿Ï·áµÉ ¼ö ÀÖ´Ù.

SUSPECT
ÇÁ¶óÀ̸Ӹ® ÆÄÀÏ ±×·ì¿¡ ¹®Á¦°¡ Àְųª ¼Õ»óµÈ °ÍÀÌ´Ù. SQL ¼­¹ö¸¦ ´Ù½Ã ½ÃÀÛ½ÃÄѵµ µ¥ÀÌÅͺ£À̽º´Â º¹±¸µÇÁö ¾Ê´Â´Ù. µ¥ÀÌÅͺ£À̽º Á¢¼ÓÀº ºÒ°¡´ÉÇÏ´Ù. ¹®Á¦¸¦ ÇØ°áÇϱâ À§Çؼ­´Â »ç¿ëÀÚÀÇ ÇൿÀÌ ÇÊ¿äÇÏ´Ù.

EMERGENCY
ÀÌ »óÅ´ »ç¿ëÀÚ°¡ ¼³Á¤ÇßÀ» ¶§¸¸ °¡´ÉÇÏ´Ù. µ¥ÀÌÅͺ£À̽º°¡ single-user ¸ðµåÀÏ ¶§¿¡¸¸ µ¥ÀÌÅͺ£À̽º´Â ¼ö¸®(Repair)¿Í º¹¿øÀÌ °¡´ÉÇÏ´Ù. À̶§ µ¥ÀÌÅͺ£À̽º´Â Àбâ Àü¿ëÀÌ¸ç ·Î±ëÀÌ ²¨Áö¸ç sysadmin ±×·ìÀÇ »ç¿ëÀÚ¸¸ÀÌ Á¢¼ÓÀÌ °¡´ÉÇÏ´Ù. ÀÌ Emergency »óÅ´ Àå¾Ö º¹±¸ÀÇ ¿ëµµ·Î »ç¿ëµÈ´Ù. ¿¹¸¦ µé¸é Suspect »óÅÂÀÇ µ¥ÀÌÅͺ£À̽º´Â Emergency»óÅ·Π¼³Á¤ÇÒ ¼ö ÀÖ´Ù. ÀÌ ¶§ system administrator´Â µ¥ÀÌÅͺ£À̽º¿¡ Àбâ Àü¿ëÀ¸·Î Á¢¼ÓÇÒ ¼ö ÀÖ´Ù. sysadmin±×·ìÀÇ »ç¿ëÀÚ¸¸ÀÌ µ¥ÀÌÅͺ£À̽º¸¦ Emergency»óÅ·Π¼³Á¤ÇÒ ¼ö ÀÖ´Ù.

* Á˼ÛÇÏ°Ôµµ ¹ø¿ªÀÌ ¸Å²ô·´Áö ¸øÇÏ´Ù. -_-;; ±×·¡µµ Á¦ µý¿¡´Â ÃÖ¼±À» ´ÙÇÑ °ÍÀÌ´Ï ¾çÇØ ºÎŹµå¸°´Ù. ¿À¿ªÀÌ ÀÖ´Ù¸é µ¡±Û·Î ³²°ÜÁֽñæ.. ¿øº»Àº SQL 2005 helpÀÌ´Ù.



°¡Àå ³»°¡ ¿ì¼±ÀûÀ¸·Î ÇØ¾ß ÇÒ ÀÏÀº DB¸¦ »ì¸®´Â °ÍÀ̾ú´Ù. suspect »óÅÂÀÇ DB¸¦ »ì¸®±â À§Çؼ­ ±¸±Û½Å¿¡°Ô ¹°¾îº¸¾Ò´õ´Ï, ¾Æ·¡¿Í °°Àº ´äÀ» Á̴ּÙ.

How to Restore SQL Server 2005 Suspect Database - The Code Project

À§ ÆäÀÌÁö¿¡¼­ Á¦½ÃÇÏ´Â ÇØ´äÀº ´ÙÀ½°ú °°´Ù. ¾Æ·¡ÀÇ ½ºÅÜÀ» ¼ø¼­´ë·Î ÇÏ¸é µÇ°Ú´Ù.

1. EXEC sp_resetstatus 'yourDBname';

ÀÏ´Ü, DB¿¡¼­ Suspect ¸¶Å©¸¦ ¾ø¾Ø´Ù. sp_resetstatus´Â ¹Ù·Î ±× ÀÏÀ» ÇØÁÖ´Â ³»Àå ½ºÅä¾îµå ÇÁ·Î½ÃÀúÀÌ´Ù.

2. ALTER DATABASE yourDBname SET EMERGENCY

µ¥ÀÌÅͺ£À̽º »óŸ¦ Emergency·Î ¹Ù²Û´Ù.

3. DBCC checkdb('yourDBname')

Emergency¸ðµåÀ̹ǷÎ, ÇöÀç µ¥ÀÌÅͺ£À̽º´Â Àбâ Àü¿ëÀÌ´Ù. ÀÌ »óÅ¿¡¼­ ¸ÕÀú CheckDB¸¦ ¼öÇàÇؼ­ DB¹®Á¦Á¡À» ÆľÇÇÑ´Ù.

4. ALTER DATABASE yourDBname SET SINGLE_USER WITH ROLLBACK IMMEDIATE

Repair¸¦ À§Çؼ­, DB»óŸ¦ Sigle User ¸ðµå·Î ¹Ù²Û´Ù.

5. DBCC CheckDB ('yourDBname', REPAIR_ALLOW_DATA_LOSS)

CheckDB¸¦ ÅëÇؼ­ Repair¸¦ ¼öÇàÇϴµ¥, REPAIR_ALLOW_DATA_LOSS¿É¼ÇÀ» »ç¿ëÇÑ´Ù. À§¿¡ ¸µÅ©ÇÑ ¿øº» ±Û¿¡µµ ³ª¿Í ÀÖÁö¸¸, ÀÌ ¿É¼Ç¿Ü¿¡´Â ¾µ ¼ö°¡ ¾ø´Ù. (À§ ±ÛÀÇ ÀúÀÚ´Â ÀÚ½ÅÀÇ °æ¿ì ¾î¶² µ¥ÀÌÅÍ LOSSµµ ¾ø¾ú´Ù°í Çϴµ¥, ½ÇÁ¦·Î ³ª´Â µ¥ÀÌÅ͸¦ ´Ù¼Ò ÀÒ¾ú´Ù. -_-;; ÀÌ°Ç ÆÈÀÚ·Á´Ï »ý°¢ÇÏÀÚ.)

6. ALTER DATABASE yourDBname SET MULTI_USER

Repair°¡ ³¡³µ´Ù¸é Database¸¦ ´Ù½Ã Multi User¸ðµå·Î º¹¿ø½ÃÅ°¸é µÈ´Ù.

À§ ½ºÅÜÀ» Á¤¸®ÇÏÀÚ¸é ´ÙÀ½°ú °°´Ù.



EXEC sp_resetstatus 'yourDBname';
ALTER DATABASE yourDBname SET EMERGENCY
DBCC checkdb('yourDBname')
ALTER DATABASE yourDBname SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB ('yourDBname', REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE yourDBname SET MULTI_USER



ÀÌ ½ºÅÜÀ» ÅëÇؼ­, Suspect »óÅÂÀÇ DB¸¦ °ÅÀÇ º¹±¸½Ãų ¼ö ÀÖ¾ú´Ù. ¾Æ¸¶ ´ëºÎºÐÀÇ °æ¿ì À§ ½ºÅÜÀ¸·Î °ÅÀÇ 100% º¹±¸°¡ °¡´ÉÇÒ °ÍÀ̶ó »ý°¢µÇ³ª.. ³» °æ¿ì´Â Á¶±Ý ´Þ¶ú´Ù. ¹®Á¦´Â µð½ºÅ©¿¡ ¿À·ù°¡ Àֱ⠶§¹®¿¡, DB´Â º¹±¸°¡ µÇ¾úÁö¸¸ Sharepoint ´Â ¹®Á¦°¡ °è¼Ó ÀÖ¾ú´ø °ÍÀÌ´Ù. µ¥ÀÌÅÍÀÇ Àбâ´Â ¾Æ¹«·± ¹®Á¦¾øÀÌ Á¤»óÀûÀε¥, ¹®¼­¸¦ ¿Ã¸®°Å³ª °Ô½Ã¹°À» ÀÛ¼ºÇϸé 2¹ø¿¡ 1¹ø ²Ã·Î ¿¡·¯°¡ ¹ß»ýÇß´Ù. ±×·¡¼­ ¾î¿ ¼ö ¾øÀÌ DB¸¦ Æ÷ÇÔÇؼ­ ¸ðµÎ¸¦ ´Ù¸¥ ¼­¹ö·Î ¿Å±â±â·Î Çß´Ù. ÀÌ À̾߱â´Â ´ÙÀ½¿¡..

To Be Continued...



2k5

ALTER DATABASE yourDBname SET EMERGENCY -- ÀÀ±Þ»óÅ·Πº¯°æ // read-only·Î Ç¥½Ã,·Î±ëºñÈ°¼º,sysadmin¸¸ ¾×¼¼½º
DBCC CheckDB ('yourDBname') -- ¹®Á¦Á¡ ÆľÇ
ALTER DATABASE yourDBname SET SINGLE_USER WITH ROLLBACK IMMEDIATE -- Repar ÇÏ·Á¸é ½Ì±ÛÀ¯Àú »óÅ¿©¾ßÇÑ´Ù.
DBCC CheckDB ('yourDBname', REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE yourDBname SET MULTI_USER

ALTER DATABASE yourDBname SET ONLINE
http://www.codeproject.com/kb/reporting-services/sql_2005_suspect_database.aspx

http://lazydeveloper.net/2567064

-- 2k0ÀÇ SP_ATTACH_DB_SINGLE_FILE_DB ¿Í µ¿ÀÏ

CREATE DATABASE DB¸í
ON (NAME='DB¸í', FILENAME='c:\aa.mdf')
FOR ATTACH_REBUILD_LOG



-- 2k0ÀÇ dbcc rebuild_log¿Í µ¿ÀÏ

ALTER DATABASE dbname REBUILD LOG ON

(NAME=logname, FILENAME='LDFÆÄÀÏ°æ·Î\logname.ldf')







2k0

ÀÀ±Þ¸ðµå º¯°æ
USE MASTER
GO
EXEC SP_CONFIGURE 'ALLOW UPDATES',1
GO
RECONFIGURE WITH OVERRIDE
GO

UPDATE SYSDATABASES SET STATUS=STATUS|32768 WHERE NAME ='DBNAME' -- ÀÀ±Þ¸ðµå ¼³Á¤

DBCC REBUILD_LOG('DBNAME', 'H:\MSSQL\DATA\DBNAME_LOG2.LDF') -- ·Î±×ÆÄÀÏ Àç»ý¼º
DBCC CHECKDB('DBNAME') -- ¿øÀκм®

UPDATE SYSDATABASES SET STATUS=STATUS&~32768 WHERE NAME ='DBNAME' -- ÀÀ±Þ¸ðµå ÇØÁ¦

EXEC SP_RESETSTATSUS 'DBNAME' -- ÁÖÀÇ ´ë»ó ¸ðµå ÇØÁ¦

DBCC DBRECOVER('DBNAME', IGNOREERRORS) -- DB Àç½ÃÀÛ, ¿À·ù¹ß»ýÇصµ º¹¿øó¸®

Alter Database TestDB Set single_user with rollback immediate -- ´ÜÀÏ »ç¿ëÀÚ ¸ðµå ¼³Á¤
DBCC CHECKDB('DBNAME', REPAIR_ALLOW_DATA_LOSS) -- ¼Õ»óµÈ ÆäÀÌÁö º¹±¸

DBCC CHECKDB('DBNAME') -- º¹±¸ È®ÀÎ

ALTER DATABASE yourDBname SET MULTI_USER WITH NO_WAIT -- ´ÜÀÏ »ç¿ëÀÚ ¸ðµå ÇØÁ¦

EXEC SP_CONFIGURE 'ALLOW UPDATES',0
GO
RECONFIGURE WITH OVERRIDE
GO

create database µðºñ¸í on (filename = 'C:\ÆÄÀϸí.mdf') for ATTACH_REBUILD_LOG;

[Âü°í] Rebuild_log ¼­½ºÆåÆ® suspect (sqlmvp) |ÀÛ¼ºÀÚ ¿Õ´«º½ÀÌ





-- 1. ¸ÕÀú ½Ã½ºÅÛ Ä«Å»·Î±×¸¦ ¼öÁ¤ ÇÒ ¼ö ÀÖ°Ô ÇØ ÁÝ´Ï´Ù.
Use master
Go

Sp_configure 'allow update', 1
Reconfigure with override
Go

-- 2. ÇØ´ç DB¸¦ ÀÀ±Þ ¸ðµå(32768 = emergency mode)·Î º¯°æ ÇÕ´Ï´Ù.
update sysdatabases set STATUS=STATUS|32768 where name = 'db_name'

-- 3. SQL ¼­ºñ½º¸¦ Àç½ÃÀÛ ÇÕ´Ï´Ù. Àç½ÃÀÛ ÈÄ ÇØ´ç DB¸¦ º¸¸é ÀÀ±Þ¸ðµå·Î ³ª¿À°Ô µÈ´Ù.
-- ¼­ºñ½º Àç½ÃÀÛ ÀÛ¾÷½Ã ¼­ºñ½º ÁßÁö ÈÄ ½ÃÀÛ Àü¿¡ ±âÁ¸ LDF ÆÄÀÏÀ» ¸®³×ÀÓ ¶Ç´Â CopyÇÏ¿© ¹ÝµíÀÌ Backup

-- 4. ·Î±× ÆÄÀÏ Àç »ý¼º
dbcc rebuild_log ('db_name' , 'ldf ÆÄÀÏÀÇ ¹°¸®Àû °æ·Î')
-- ex) dbcc rebuild_log ('TestDB' , 'D:\MSSQL\DATA\testdb_log.ldf')
-- ÀÌ »óÅ ±îÁö ÁøÇàÀ» ÇÏ°Ô µÇ¸é DBÀÇ Ldf ÆÄÀÏÀÌ ÃʱâÈ­ µÇ¸é¼­ DB´Â DBO¸¸ »ç¿ë»óÅ·ΠȰ¼ºÈ­ µË´Ï´Ù. ±×·¯¸é ÀÌÁ¦ DB¸¦ º¸Åë ¸ðµå·Î ¹Ù²Ù´Â ÀÛ¾÷À» ÇÕ´Ï´Ù.

-- 5. DBÀÇ »óŸ¦ ¸ÕÀú È®ÀÎ ÇÕ´Ï´Ù.
Select status From sysdatabases
-- À̶§ ¾Æ±î º¹±¸ÇÑ DBÀÇ »óÅ°¡ '2048 = dbo use only' »óÅ·ΠµÇ¾î ÀÖÀ» °Í ÀÔ´Ï´Ù.

-- 6. º¹±¸ÇÑ DBÀÇ status º¹¿ø.
update sysdatabases set status=STATUS&~32768 where name = 'db_name'
--?? update sysdatabases set status=0 where name='mdo2000db' /* DBO¸¸ »ç¿ë»óŸ¦ Á¤»óÀ¸·Î

--?? sp_resetstatus



-- 7. EMÀ» À翬°á Çϸé DBÀÇ »óÅ°¡ º¸ÅëÀ¸·Î º¯°æ µÊÀ» È®ÀÎ ÇÒ ¼ö ÀÖ½À´Ï´Ù.

-- 8. ÀÌÁ¦ DB¸¦ ´Ù½Ã ¸ÕÀú ½Ã½ºÅÛ Ä«Å»·Î±×¸¦ ¼öÁ¤ ÇÒ ¼ö ¾ø°Ô º¯°æÇØ ÁÝ´Ï´Ù.
Use master
Go
Sp_configure ¡®allow update¡¯, 0
Reconfigure with override
Go
-- ¿©±â±îÁö ÁøÇàÀÌ µÇ¾úÀ¸¸é ÀÌÁ¦´Â DB ÀÏ°ü¼º °Ë»ç¸¦ ÁøÇà ÇÏ¿© Àß ¸øµÈ ºÎºÐÀÌ ¾ø´ÂÁö È®ÀÎ ÇÕ´Ï´Ù.

-- 9. DBCC Checkdb
-- ÀÏ°ü¼º ¿À·ù°¡ ÀÖ´ÂÁö °Ë»ç ÇÕ´Ï´Ù.


-- 10. ÀÏ°ü¼º ¿À·ù¸¦ ¼öÁ¤Çϱâ À§ÇØ user¸¦ ½Ì±Û À¯Àú·Î º¯°æ ÇÕ´Ï´Ù.
Alter Database TestDB Set single_user with rollback immediate


-- 11. ¿À·ù¸¦ ¼öÁ¤ ÇÕ´Ï´Ù.
DBCC CheckDB('db_name', REPAIR_ALLOW_DATA_LOSS)
-- Ex) DBCC CheckDB ('TestDB' , REPAIR_ALLOW_DATA_LOSS)

-- 12. ¿À·ù¸¦ ¼öÁ¤ ÇÏ¿´´Ù¸é ´Ù½Ã DBCC Checkdb ¸¦ ¼öÇà ÇÕ´Ï´Ù.
-- 13. ¿À·ù°¡ ´õ ÀÌ»ó ¾ø´Ù¸é user¸ðµå¸¦ ´Ù½Ã º¯°æ ÇÏ¿© ÁÝ´Ï´Ù.
User master
go
Alter Database TestDB Set multi_user
go

-- ÀÛ¾÷ ¿Ï·á

http://laigo.kr/27

------------------------------------------------------------------------------------

[ÇØ°á¹æ¹ý]
ÇØ´ç µ¥ÀÌÅͺ£À̽º¿¡ Á¢±ÙÀÌ ºÒ°¡´ÉÇϹǷΠsuspect »óÅ¿¡¼­´Â ¾Æ¹«·± ÀÛ¾÷À» ÁøÇàÇÒ ¼ö ¾ø½À´Ï´Ù.
ÀÀ±Þ º¹±¸ ¸ðµå·Î º¯°æÇØ¾ß ÇϹǷΠ½Ã½ºÅÛ Å×À̺íÀ» º¯°æÇϱâ À§ÇØ ±¸¼º ¿É¼ÇÀ» º¯°æÇÕ´Ï´Ù.


USE MASTER
go

sp_configure 'allow update', 1
RECONFIGURE WITH OVERRIDE
go

ÇØ´ç µ¥ÀÌÅͺ£À̽º ÀÀ±Þ ¸ðµå(32768 = emergency mode)·Î º¯°æÇÕ´Ï´Ù.



UPDATE SYSDATABASES SET STATUS = 32768 WHERE NAME = 'laigo'


SQL ¼­ºñ½º¸¦ ÁßÁöÇÕ´Ï´Ù.
±âÁ¸ LDF ÆÄÀÏÀÇ À̸§À» º¯°æÇϰųª, º¹»çÇؼ­ ´Ù¸¥ °÷À¸·Î ¹é¾÷ÇÕ´Ï´Ù. SQL ¼­ºñ½º¸¦ Àç½ÃÀÛ ÇÕ´Ï´Ù.
·Î±× ÆÄÀÏÀ» Àç »ý¼ºÇÕ´Ï´Ù.


DBCC REBUILD_LOG('laigo' , 'D:\DATA\laigo_log.ldf')

DBÀÇ .ldf ÆÄÀÏÀÌ ÃʱâÈ­ µÇ¸é¼­, DB´Â DBO¸¸ »ç¿ë»óÅ·ΠȰ¼ºÈ­ µË´Ï´Ù.
´ÙÀ½ ¸í·ÉÀ¸·Î º¹±¸ÇÑ DBÀÇ »óÅ°¡ ¡®2048 = dbo use only¡¯ »óÅ·ΠµÇ¾î ÀÖ´ÂÁö È®ÀÎÇÕ´Ï´Ù.


SELECT * FROM SYSDATABASES





´ÙÀ½ ¸í·ÉÀ¸·Î º¹±¸ÇÑ DBÀÇ ¸ðµå¸¦ ¡®±âº»¸ðµå = 0¡¯ º¯°æÇÕ´Ï´Ù. ÀÌÁ¦ EMÀ» À翬°á Çϸé DBÀÇ »óÅ°¡ º¸ÅëÀ¸·Î
º¯°æ µÊÀ» È®ÀÎ ÇÒ ¼ö ÀÖ½À´Ï´Ù.(»ç¿ëÀÚ Á¢¼ÓÀÌ °¡´ÉÇÑ »óÅÂ)



UPDATE SYSDATABASES SET STATUS = 0 WHERE NAME = 'laigo'



ÀÏ°ü¼º ¿À·ù¸¦ üũÇϱâ À§ÇØ single user ¸ðµå·Î º¯°æÇϸç Áï½Ã »ç¿ëÀÚ Á¢¼ÓÀ» Â÷´ÜÇÕ´Ï´Ù.


ALTER DATABASE laigo SET single_user WITH ROLLBACK IMMEDIATE


µ¥ÀÌÅͺ£À̽º ¼Õ»ó ¿©ºÎ¸¦ °Ë»çÇϱâ À§ÇØ ÀÏ°ü¼º °Ë»ç¸¦ ÁøÇàÇÕ´Ï´Ù.
¸í·É ½ÇÇà ÈÄ ¿À·ù°¡ ¹ß°ßµÇÁö ¾Ê¾Ò´Ù¸é º¹±¸°¡ ¿Ï·áµÈ »óÅÂÀÔ´Ï´Ù.


DBCC CHECKDB('laigo')






ÀÏ°ü¼º ¿À·ù¸¦ ¼öÁ¤Çϱâ À§ÇØ ´ÙÀ½ ¸í·ÉÀ» ½ÇÇàÇÕ´Ï´Ù.

DBCC CHECKDB('laigo', ¿É¼Ç)

ÀÏ°ü¼º ¿À·ù°¡ ¹ß»ýµÇ¾úÀ» ¶§, ÇØ´çÇÏ´Â ÀûÇÕÇÑ ¿É¼ÇÀ» ºÎ¿©ÇÕ´Ï´Ù.



(1) REPAIR_FAST
µ¥ÀÌÅÍÀÇ ¼Õ½Ç À§Çè ¾øÀÌ ºü¸¥ º¹±¸ ÀÛ¾÷À» ¼öÇàÇÒ ¼ö ÀÖ½À´Ï´Ù(Ŭ·¯½ºÅ͵ÇÁö ¾ÊÀº À妽º º¹±¸ °¡´É)

(2) REPAIR_REBUILD
REPAIR_FASTÀÌ ÇÏ´Â ¸ðµç ÀÛ¾÷, À妽º Àç»ý¼º°ú °°ÀÌ ½Ã°£ÀÌ ¼Ò¿äµÇ´Â ÀÛ¾÷ÀÌ º¹±¸ °úÁ¤¿¡¼­ ÁøÇàµË´Ï´Ù. ¿ª½Ã µ¥ÀÌÅÍÀÇ ¼Õ½Ç À§ÇèÀº ¾ø½À´Ï´Ù.

(3) REPAIR_ALLOW_DATA_LOSS
REPAIR_REBUILDÀÌ ÇÏ´Â ¸ðµç ÀÛ¾÷, ÇÒ´ç ¿À·ù, ±¸Á¶Àû Çà ¿À·ù³ª ÆäÀÌÁö ¿À·ù, ¼Õ»óµÈ ÅؽºÆ® °³Ã¼ »èÁ¦¸¦ ¼öÁ¤Çϱâ À§ÇÑ Çà°ú ÆäÀÌ¡ÀÇ ÇÒ´ç ¹× ÇÒ´ç Ãë¼Ò µîÀÇ ÀÛ¾÷ÀÌ ÇàÇØÁý´Ï´Ù. ÀÌ·¯ÇÑ º¹±¸¸¦ ÇÒ °æ¿ì ÀϺΠµ¥ÀÌÅÍ°¡ ¼Õ½ÇµÉ ¼ö ÀÖ½À´Ï´Ù. º¹±¸¸¦ ¿Ï·áÇÑ ÈÄ µ¥ÀÌÅͺ£À̽º¸¦ ¹é¾÷ÇÕ´Ï´Ù.


¸í·ÉÀÌ ¿Ï·áµÇ¸é, ´Ù½Ã Çѹø DBCC CHECKDB ¸í·ÉÀ» ¼öÇàÇÏ¿© ÀÏ°ü¼º ¿À·ù°¡ ¼öÁ¤µÇ¾ú´ÂÁö È®ÀÎÇÕ´Ï´Ù.



DBCC CHECKDB('laigo')

´õ ÀÌ»ó ¿À·ù°¡ ¹ß°ßµÇÁö ¾ÊÀ¸¸é, multi_user ¸ðµå·Î º¯°æÇÏ¿© »ç¿ëÀÚ Á¢¼ÓÀÌ °¡´ÉÇÏ°Ô ÇØÁÝ´Ï´Ù.

ALTER DATABASE laigo SET multi_user


»ç¿ëÀÚ Á¢¼ÓÀÌ µÇ°í ÀÖ´ÂÁö ¸ð´ÏÅ͸µ ÇÕ´Ï´Ù.



sp_who2




¸ðµç ÀÛ¾÷ÀÌ ¿Ï·áµÇ¸é, ½Ã½ºÅÛ Ä«Å»·Î±×¸¦ ¼öÁ¤ ÇÒ ¼ö ¾ø°Ô º¯°æÇØ ÁÝ´Ï´Ù.



sp_configure 'allow update', 0
RECONFIGURE WITH OVERRIDE
go
ÀÛ¼º ³¯Â¥ : 2014-01-21