program tip

SQL Server : 데이터베이스가 "복원 중"상태로 멈춤

radiobox 2020. 10. 4. 10:48
반응형

SQL Server : 데이터베이스가 "복원 중"상태로 멈춤


데이터베이스를 백업했습니다.

BACKUP DATABASE MyDatabase
TO DISK = 'MyDatabase.bak'
WITH INIT --overwrite existing

그런 다음 복원을 시도했습니다.

RESTORE DATABASE MyDatabase
   FROM DISK = 'MyDatabase.bak'
   WITH REPLACE --force restore over specified database

이제 데이터베이스는 복원 중 상태에 있습니다.

일부 사람들은 백업에 로그 파일이 없기 때문에 다음을 사용하여 롤 포워드해야한다고 이론화했습니다.

RESTORE DATABASE MyDatabase
WITH RECOVERY 

물론 실패한 점을 제외하고는 :

Msg 4333, Level 16, State 1, Line 1
The database cannot be recovered because the log was not restored.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.

치명적인 상황에서 정확히 원하는 것은 작동하지 않는 복원입니다.


백업에는 데이터와 로그 파일이 모두 포함됩니다.

RESTORE FILELISTONLY 
FROM DISK = 'MyDatabase.bak'

Logical Name    PhysicalName
=============   ===============
MyDatabase    C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\MyDatabase.mdf
MyDatabase_log  C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\MyDatabase_log.LDF

복원 프로세스의 일부로 데이터베이스를 온라인 상태로 만들려면 데이터베이스 명령 WITH RECOVERY과 함께 옵션 을 사용해야합니다 RESTORE.

물론 이것은 트랜잭션 로그 백업을 복원하지 않으려는 경우에만 해당됩니다. 즉, 데이터베이스 백업 만 복원 한 다음 데이터베이스에 액세스 할 수 있습니다.

명령은 다음과 같아야합니다.

RESTORE DATABASE MyDatabase
   FROM DISK = 'MyDatabase.bak'
   WITH REPLACE,RECOVERY

SQL Server Management Studio의 데이터베이스 복원 마법사를 사용하면 더 많은 성공을 거둘 수 있습니다. 이렇게하면 특정 파일 위치, 덮어 쓰기 옵션 및 WITH 복구 옵션을 선택할 수 있습니다.


Symantec Backup Exec 11d를 사용하여 데이터베이스를 SQL Server 2005 Standard Edition 인스턴스로 복원하는 상황이 발생했습니다. 복원 작업이 완료된 후 데이터베이스는 "복원 중"상태로 유지되었습니다. 디스크 공간 문제가 없었습니다. 데이터베이스가 "복원 중"상태에서 벗어나지 않았습니다.

SQL Server 인스턴스에 대해 다음 쿼리를 실행 한 결과 데이터베이스를 즉시 사용할 수있게되었습니다.

RESTORE DATABASE <database name> WITH RECOVERY

방법은 다음과 같습니다.

  1. 서비스를 중지하십시오 (MSSQLSERVER).
  2. 데이터베이스 및 로그 파일 (C : \ Program Files \ Microsoft SQL Server \ MSSQL.1 \ MSSQL \ Data ...) 또는 파일이있는 위치에서 이름을 바꾸거나 삭제합니다.
  3. 서비스를 시작하십시오 (MSSQLSERVER).
  4. 문제가있는 데이터베이스를 삭제하십시오.
  5. 데이터베이스를 다시 복원하십시오.

로그 전달 보조 서버를 중지하는 것과 유사한 사건이 발생했습니다. 로그 전달에서 서버를 제거하고 기본 서버에서 로그 전달을 중지하는 명령 후 보조 서버의 데이터베이스가 명령 후 복원 상태에서 멈췄습니다.

RESTORE DATABASE <database name> WITH RECOVERY

데이터베이스 메시지 :

RESTORE DATABASE는 18.530 초 (0.000MB / 초)에 0 페이지를 성공적으로 처리했습니다.

그 18 초 후에 데이터베이스를 다시 사용할 수있게되었습니다.


SQL Management Studio를 사용하여 복원하는 것과 비슷한 문제가있었습니다. 데이터베이스 백업을 다른 이름의 새 데이터베이스로 복원하려고했습니다. 처음에는 실패하고 새 데이터베이스의 파일 이름을 수정 한 후 성공적으로 수행되었습니다. 어떤 경우에도 처음부터이 권한을 얻었더라도 설명하고있는 문제가 다시 발생했습니다. 따라서 복원 후 원래 데이터베이스는 이름 옆에 (복원 중 ...)이 표시됩니다. 위의 포럼 (Bhusan 's)의 답변을 고려하여 다음 측면의 쿼리 편집기에서 실행 해 보았습니다.

RESTORE DATABASE "[NAME_OF_DATABASE_STUCK_IN_RESTORING_STATE]"

문제가 해결되었습니다. 처음에는 특수 문자가 포함 된 데이터베이스 이름 때문에 문제가 발생했습니다. 나는 주위에 큰 따옴표를 추가하여이 문제를 해결했습니다. 작은 따옴표는 "... 근처에 잘못된 구문이 있습니다."오류가 발생하지 않습니다.

이것은 내가이 문제를 해결하기 위해 시도한 최소한의 솔루션 (데이터베이스 복원 상태에 멈춤)이었고 더 많은 경우에 적용될 수 있기를 바랍니다.


좋아요, 비슷한 문제가 있는데 Pauk의 경우와 똑같이 복원하는 동안 서버의 디스크 공간이 부족하여 영구 복원 상태가 발생했습니다. SQL Server 서비스를 중지하지 않고이 상태를 종료하는 방법은 무엇입니까?

해결책을 찾았습니다. :)

Drop database *dbname*

WITH RECOVERY 옵션은 RESTORE DATABASE / RESTORE LOG 명령이 실행될 때 기본적으로 사용됩니다. "복원"프로세스에서 멈춘 경우 다음을 실행하여 데이터베이스를 온라인 상태로 되돌릴 수 있습니다.

RESTORE DATABASE YourDB WITH RECOVERY
GO

여러 파일을 복원해야하는 경우 CLI 명령에 각각 WITH NORECOVERY 및 WITH RECOVERY가 필요합니다. 명령의 마지막 파일에만 WITH RECOVERY가 있어야 데이터베이스를 온라인 상태로 되돌릴 수 있습니다.

RESTORE DATABASE YourDB FROM DISK = 'Z:\YourDB.bak'
WITH NORECOVERY
GO
RESTORE LOG YourDB FROM DISK = 'Z:\YourDB.trn'
WITH RECOVERY
GO

SQL Server Management Studio 마법사를 사용할 수도 있습니다.

여기에 이미지 설명 입력

가상 복원 프로세스도 있지만 타사 솔루션을 사용해야합니다. 일반적으로 데이터베이스 백업을 라이브 온라인 데이터베이스로 사용할 수 있습니다. ApexSQL 및 Idera에는 자체 솔루션이 있습니다. SQL Hammer에서 ApexSQL 복원에 대해 검토합니다 . 가상 복원은 많은 수의 백업을 처리하는 경우 좋은 솔루션입니다. 복원 프로세스가 훨씬 빠르며 디스크 드라이브의 많은 공간을 절약 할 수도 있습니다. 비교를 위해 여기 에서 인포 그래픽을 살펴볼 수 있습니다 .


이것은 상당히 분명 할 수 있지만 지금은 나를 넘어 뜨 렸습니다.

테일 로그 백업을 수행하는 경우이 문제는 SSMS 복원 마법사에서이 옵션을 선택하여 발생할 수도 있습니다- "원본 데이터베이스를 복원 상태로두기 (WITH NORECOVERY)"

여기에 이미지 설명 입력


나는 이유를 알아 냈다.

RESTORE DATABASE명령 을 실행 한 클라이언트 가 복원 중에 연결이 끊어지면 복원이 중단됩니다.

클라이언트 연결을 통해 데이터베이스를 복원하라는 명령을 받았을 때 클라이언트가 계속 연결되어 있지 않으면 서버가 복원을 완료하지 못하는 것은 이상합니다.


이것은 작동했습니다.

http://social.msdn.microsoft.com/Forums/en/sqldatabaseengine/thread/8dd1b91d-3e14-4486-abe6-e3a550bfe457

데이터베이스가 복원 상태를 표시하고 쿼리를 실행할 수없고 소프트웨어와 연결할 수없는 상황이 발생했습니다.

이 상황에서 벗어나기 위해 내가 한 일은 다음과 같습니다.

  1. Windows 서비스에서 모든 SQL 관련 서비스를 중지합니다.

  2. Ldf 및 Mdf 파일이 SQL 디렉터리에있는 DATA 폴더를 열었습니다. 일반적으로 "C : \ Program Files *********** \ MSSQL \ DATA

  3. 그런 다음 데이터베이스의 Ldf 및 Mdf 파일을 모두 복사했습니다. [db name] .mdf 및 [db name] _log.ldf

이 두 파일을 모두 다른 폴더에 복사했습니다.

  1. 그런 다음 Windows 서비스에서 모든 SQL 관련 서비스 (1 단계)를 다시 시작했습니다.

  2. 일반 로그인으로 MS SQL Management Studio를 시작했습니다.

  3. 범인 데이터베이스를 마우스 오른쪽 버튼으로 클릭하고 DELETE를 누르십시오 (데이터베이스를 전혀 삭제하려면).

  4. 이 데이터베이스와 관련된 모든 LDF 및 MDF 파일은 DATA 폴더에서 가져 왔습니다 (2 단계에서 언급).

  5. 동일한 이름으로 새 데이터베이스를 생성했습니다 (6 단계에서 삭제 한 것과 동일한 이름-범인 데이터베이스).

  6. 그런 다음 [데이터베이스 이름]-> 오른쪽 클릭-> 작업-> 오프라인으로 전환합니다.

  7. 그런 다음 두 파일 (3 단계에서)을 다시 DATA 폴더 (2 단계)로 복사했습니다.

  8. [데이터베이스 이름]-> 오른쪽 클릭-> 작업-> 온라인으로 가져 오기.


나는. 내 데이터베이스 이름에 쿼리가 작동하지 않았습니다. ( '.'근처에 잘못된 구문이라고 말함) 그런 다음 이름에 대괄호가 필요하다는 것을 깨달았습니다.

RESTORE DATABASE [My.DB.Name] WITH RECOVERY

제 경우 에는 SQL 명령으로 "Restoring ..." 상태에 있는 데이터베이스삭제하는 것으로 충분했습니다.

 drop database <dbname> 

쿼리 창에서.

그런 다음 데이터베이스를 마우스 오른쪽 버튼으로 클릭 하고 새로 고침선택 하여 Management Studio에서 항목을 제거했습니다. 그 후 잘 작동하는 새 복원을 수행했습니다 (오프라인으로 전환하지 않고 SQL 서비스를 다시 시작해도 작동하지 않았으며 서버 재부팅도 작동하지 않음).


이벤트 로그에서 TCP 오류를 수신했을 때도이 문제가 발생했습니다.

Drop the DB with sql or right click on it in manager "delete" And restore again.

I have actually started doing this by default. Script the DB drop, recreate and then restore.


By default, every RESTORE DATABASE comes with RECOVERY set up. The 'NORECOVERY' options, basically tells the SQL Server that the database is waiting for more restore files (could be a DIFF file and LOG file and, could include tail-log backup file, if possible). The 'RECOVERY' options, finish all transactions and let the database ready to perform transactions.

So:

  1. if your database is set up with SIMPLE recovery model, you can only perform a FULL restore with NORECOVERY option, when you have a DIFF backup. No LOG backup are allowed in SIMPLE recovery model database.
  2. Otherwise, if your database is set up with FULL or BULK-LOGGED recovery model, you can perform a FULL restore followed by NORECOVERYoption, then perform a DIFF followed by NORECOVERY, and, at last, perform LOG restore with RECOVERY option.

Remember, THE LAST RESTORE QUERY MUST HAVE RECOVERY OPTION. It could be an explicit way or not. In therms of T-SQL, the situation:

1.

 USE [master]
    GO
    RESTORE DATABASE Database_name 
    FROM DISK = N'\\path_of_backup_file.bak WITH FILE = 1, [REPLACE],NOUNLOAD, 
    RECOVERY -- This option could be omitted.
    GO

WITH REPLACE option must be used with caution as it can lead to data loss

Or, if you perform a FULL and DIFF backup, you can use this

   USE [master]
    GO
    RESTORE DATABASE Database_name
      FROM DISK = N'\\path_of_backup_file.bak' WITH FILE = 1, 
       NOUNLOAD,NORECOVERY
    GO
    RESTORE DATABASE Database_name
      FROM DISK =N'\\path_of_**diff**backup_file.bak' WITH FILE = 1, 
     NOUNLOAD, RECOVERY
    GO

 2. USE [master]
    GO
   -- Perform a Tail-Log backup, if possible. 
   BACKUP LOG Database_name
   GO
   -- Restoring a FULL backup
   RESTORE DATABASE Database_name
    FROM DISK = N'\\path_of_backup_file.bak' WITH FILE = 1, 
     NOUNLOAD,NORECOVERY
  GO 
  -- Restore the last DIFF backup
  RESTORE DATABASE Database_name
    FROM DISK = N'\\path_of_DIFF_backup_file.bak' WITH FILE = 1,
     NORECOVERY,NOUNLOAD
  GO
  -- Restore a Log backup
  RESTORE LOG Database_name
    FROM DISK = N'path_of_LOG_backup_file.trn' WITH FILE = 2,
    RECOVERY, NOUNLOAD
  GO

Of course, you can perform a restore with the option STATS = 10 that tells the SQL Server to report every 10% completed.

If you prefer, you can observe the process or restore in real-time based query. As follow:

USE[master]
GO
SELECT session_id AS SPID, command, a.text AS Query, start_time, percent_complete, dateadd(second,estimated_completion_time/1000, getdate()) as estimated_completion_time 
    FROM sys.dm_exec_requests r CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) a 
        WHERE r.command in ('BACKUP DATABASE','RESTORE DATABASE')
GO

Hope this help.


There can also be problem deleting a stuck database if snapshot is enabled. For me this worked:

  1. First I followed Tipu Delacablu steps (read a few posts up)
  2. run command: drop database [your database], which will give you an error telling you the name of the snapshot database
  3. run command: drop database [snapshot database], and then run the command in step 2 again.

Have you tried running a VERIFY ONLY? Just to make sure it's a sound backup.

http://msdn.microsoft.com/en-us/library/ms188902.aspx


  1. Let check and run SQL Agent Service firstly.
  2. Using following T-SQL:

    SELECT filename FROM master.sys.sysaltfiles WHERE dbid = DB_ID('db_name');

  3. Using T-SQL continuously:

    RESTORE DATABASE FROM DISK = 'DB_path' WITH RESTART, REPLACE;

Hope this help!


All the WITH RECOVERY based options did not work for me.

What did was to do the complete restore from Management Studio.

USE [master]
RESTORE DATABASE Sales_SSD
FROM  DISK = N'D:\databaseBackups02\Daily_Sales_20150309_0941.bak' 
WITH  FILE = 1,  
MOVE N'Sales_Data' TO N'C:\Data\SSD\Sales.mdf',  
MOVE N'Sales_Log' TO N'C:\Data\SSD\Sales_1.ldf',  
NOUNLOAD,  REPLACE,  STATS = 5

I had the same issue... although I do not know why my database experienced this problem as my drive was not full... It's like it got corrupted or something. I tried all of the above none of them fully worked, I especially thought the suggestion to stop the service and deleting the mdf and ldf files would work... but it still froze up on restore?

I ended up resolving this by deleting the files as mentioned but instead of trying to restore the DB again I copied over fresh .mdf and .ldf files and Attached these using the Front End Attachment wizard. Relief, it worked!!

It took FOREVER to copy over the new files as I am using a Virtual Machine... so copying and pasting using the clipboard took like an hour itself so I would only recommend this as a last attempt.


I have got the MyDbName (Restoring...) case because of SQL Express licensed limit.

In the log file, I found this:

CREATE DATABASE or ALTER DATABASE failed because the resulting cumulative database size would exceed your licensed limit of 10240 MB per database.

So if you are trying to restore a bigger database, you need to switch your SQL Express server to Developer edition for instance.


What fixed it for me was

  1. stopping the instance
  2. creating a backup of the .mdf and .ldf files in the data folder
  3. Restart the instance
  4. delete the database stuck restoring
  5. put the .mdf and.ldf files back into the data folder
  6. Attach the instance to the .mdf and .ldf files

RESTORE DATABASE {DatabaseName}
   FROM DISK = '{databasename}.bak'
   WITH REPLACE, RECOVERY

참고 URL : https://stackoverflow.com/questions/520967/sql-server-database-stuck-in-restoring-state

반응형