SQL Serverのクローンデータベース

著作権:コピー、ソースを明記してくださいhttps://blog.csdn.net/weixin_39392627/article/details/86853445

ENV:のWindows Server 2016

       SQL Serverの2016 SP2

       SQL Serverの2016 SP1

以前のスナップショットと、バックアップファイルを使用し、二つの方法でデータベースをコピーしました。

DBCC clonedatabase:SQL Server 2012のデータベースをコピーするコマンドを提供しています。

このディレクティブは、徐々に、新しいパラメータを追加していますが、このリンクを参照することができます:DBCC CLONEDATABASE(のTransact-SQL)

我々はいくつかの機能をテストするためにSQL 2016を使用します。

およそ200ギガバイトDBのコピー

 

1.引数なしで、データベースをコピーします。

コマンド:

DBCC CLONEDATABASE (TESTDB01_20190119, TESTDB01_20190119_Clone);    
GO

データベースのレプリケーションプロセスがDBをコピーするには非常に速く、非常に小さな部屋です

 

デフォルトのデータベースをコピーすると、「読み取り専用」であります

あなたは、次のコマンドは、「読み書き」に変更されて使用することができます

ALTER DATABASEのUgsDataWarehouse_20190119_Clone SET READ_WRITE

 

2.あなたは、このデータベースには、次の手順を介してコピーするかどうかを確認することができます。

コマンド:

USE [master]
GO
SELECT DATABASEPROPERTYEX('TESTDB01_20190119_Clone', 'IsClone')
GO

 

3.パラメータ「VERIFY_CLONEDBは、」SQL Serverの2016 SP2の新機能です。

コマンド:

DBCC CLONEDATABASE (TESTDB01_20190119, TESTDB01_20190119_Clone_1) WITH VERIFY_CLONEDB;    
GO

次のエラーが2016 SP1に含まれている場合、SQL Serverを実行します:

 

使用してSQL Server 2016 SP2を試してみてください4. パラメータを"VERIFY_CLONEDB"

コマンド:

DBCC CLONEDATABASE (TBTEST03, TBTEST03_CLONE) WITH VERIFY_CLONEDB;    
GO

 

エラーログ内容:

DBCC CHECKDB (TBTEST03_CLONE) WITH no_infomsgs executed by sa found 0 errors and repaired 0 errors. Elapsed time: 0 hours 0 minutes 0 seconds.  Internal database snapshot has split point LSN = 00000022:00000262:0001 and first LSN = 00000022:00000260:0001

 

5.檢查複製的資料庫在過程中是否有被verify

command:

USE [master]
GO
SELECT DATABASEPROPERTYEX('TBTEST03_CLONE', 'IsVerifiedClone')
GO

 

6.在複製指令中加入參數"VERIFY_CLONEDB"與"BACKUP_CLONEDB"

"BACKUP_CLONEDB"這個參數會在複製資料庫後進行備份,這個功能是在SQL Server 2016 SP2開始

command:

DBCC CLONEDATABASE (TBTEST03, TBTEST03_CLONE_1) WITH VERIFY_CLONEDB, BACKUP_CLONEDB;    
GO

 

errorlog內容,時間由近到遠:

CHECKDB for database 'TBTEST03_CLONE_1' finished without errors on 2019-01-19 09:40:35.853 (local time). This is an informational message only; no user action is required.

Database backed up. Database: TBTEST03_CLONE_1, creation date(time): 2019/01/19(09:40:34), pages dumped: 354, first LSN: 34:576:37, last LSN: 34:595:1, number of dump devices: 1, device information: (FILE=1, TYPE=DISK: {'E:\DBBackup\TBTEST03_CLONE_1_1176299034.bak'}). This is an informational message only. No user action is required.

CHECKDB for database 'TBTEST03_CLONE_1' finished without errors on 2019-01-19 09:40:35.853 (local time). This is an informational message only; no user action is required.

CHECKDB for database 'TBTEST03_CLONE_1' finished without errors on 2019-01-19 09:40:35.853 (local time). This is an informational message only; no user action is required.

DBCC CHECKDB (TBTEST03_CLONE_1) WITH no_infomsgs executed by sa found 0 errors and repaired 0 errors. Elapsed time: 0 hours 0 minutes 0 seconds.  Internal database snapshot has split point LSN = 00000022:00000233:0001 and first LSN = 00000022:00000231:0001.

DBCC CHECKDB (TBTEST03_CLONE_1) WITH no_infomsgs executed by sa found 0 errors and repaired 0 errors. Elapsed time: 0 hours 0 minutes 0 seconds.  Internal database snapshot has split point LSN = 00000022:00000233:0001 and first LSN = 00000022:00000231:0001.

Database 'TBTEST03_CLONE_1' is a cloned database. This database should be used for diagnostic purposes only and is not supported for use in a production environment.

 

結論:

這個功能方便使用,但是官方也提供以下警語。

這個是使用資料庫內部的快照功能來進行複製所以還是會產生LOCK。若要在生產環境使用,還是請再三評估。

 

DBCC CLONEDATABASE uses an internal database snapshot of the source database for the transactional consistency that is needed to perform the copy. Using this snapshot prevents blocking and concurrency problems when these commands are executed. If a snapshot can't be created, DBCC CLONEDATABASE will fail.

Database level locks are held during following steps of the copy process:

Validate the source database

Get S lock for the source database

Create snapshot of the source database

Create a clone database (an empty database inherited from the model database)

Get X lock for the clone database

クローン・データベースにメタデータをコピーします。

すべてのDBのロックを解除

すぐにコマンドの実行が完了したとして、内部スナップショットは削除されます。TRUSTWORTHYとDB_CHAININGオプションは、クローン化されたデータベース上でオフになっています。

おすすめ

転載: blog.csdn.net/weixin_39392627/article/details/86853445