AlwaysON下迁移数据库----无需破坏HADR
来源:互联网 发布:达芬奇调色软件mac版 编辑:程序博客网 时间:2024/06/05 10:44
Move database without breaking alwaysON
This post is going to show the database movement from one drive to another drive, without breaking the database from alwaysON configuration. An application has created the database to both primary and secondary replica servers to the default location of C drive.
There are methods like detach/attach, backup/restore & alter database. For alwaysON HADR servers, the best method is Alter database. Since it is in the mirror/sync mode. Detach/attach will not work and backup/ restore, we need to break databases from the HADR.
Note:
It’s a two node synchronous replica, if you have more replica, you should plan each well.
If you have any standalone database (Without adding DBs into HADR), you need to plan for the downtime. Since, the secondary replica servers need to take down.
In primary, for high transaction system, make sure you have good space for transaction files.
Steps:
Before going to start the database movement, write the script for each step and you can write a dynamic SQL for larger number databases. That’s what I did. It will minimize the time.
- In primary server, suspend the database movement to all secondary databases. It will stop the sending the log to the secondary, which can increase the log size https://msdn.microsoft.com/en-us/library/ff878303.aspx
ALTER DATABASE <DB name> SET HADR suspend
- Change the Readable secondary to ‘NO’ for all the secondary replicas, otherwise you will get an error.
Right click the primary replica alwaysON group –> properties –> Readable secondary –> No
To use ALTER DATABASE, the database must be in a writable state in which a checkpoint can be executed.
- Note down all the files and file location from the system tables.
select db_name(a.database_id),a.name,a.physical_name,size/128.0 AS CurrentSizeMB,*
from sys.master_files a join sys.databases b
on a.database_id =b.database_id
–where a.physical_name like ‘c%’
–and a.database_id >4
–and type_desc <>’rows’
order by a.name
- On the mirror server run the “ALTER DATABASE <DB name> MODIFY FILE” command. You need to run this for each database.
use master
ALTER DATABASE <DB_name> MODIFY FILE (NAME =<logical name>
,FILENAME =’F:\SQL_DATA\DB_name.mdf’)
- On the secondary replica server stop the SQL Server instance.
- Move the database file (MDF & LDF) files to the changed location (Cut & Paste).
- Start the SQL Server instance and check the file locations using the above query.
- In primary replica server resume the database by using the following ALTER DATABASE statement:
ALTER DATABASE <DB name> SET HADR Resume.
- Change the Readable secondary to ‘Yes’
Fail over and repeat the steps for the partner server.
Additionally, if you add any files in the primary and the folder name is incorrect in the secondary, the database will go into suspend mode.
Just check the error log, you can get more info on, why the database is suspended mode.
Error: 5123, Severity: 16, State: 1.
CREATE FILE encountered operating system error 3(The system cannot find the path specified.) while attempting to open or create the physical file ‘L:\SQL_log\DB_name.ndf’.
Created the folder and resume the database, the resume database command will create a file.
ALTER DATABASE <db name> SET HADR RESUME;
转自:http://www.sqlservercentral.com/blogs/sql-server-blog-forum/2016/08/03/alwayson-move-database-without-breaking-hadr/
- AlwaysON下迁移数据库----无需破坏HADR
- Code First 迁移更新数据库 无需删除当前数据库
- DB2 HADR 恢复灾备数据库
- Ubuntu下MySQL数据库迁移
- 关于alwayson 数据库用户同步 权限问题
- Linux下informix安装及数据库迁移
- Mysql数据库不同字符集下迁移
- Centos6.5下MySQL5.5.45数据库迁移
- 11. ubuntu 下 mysql 数据库迁移
- CentOS下mysql数据库data目录迁移
- Linux下informix安装及数据库迁移
- Linux下informix安装及数据库迁移
- kettle7.0下实现数据库整体迁移
- Ubuntu 下mysql数据库存放位置迁移
- SQL Server 2012 AlwaysOn探索(下)
- SQL Server 2012 AlwaysOn探索(下)
- DB2数据库restore之后无法重新建立HADR的问题
- 数据库迁移
- C#入门3.5——本章总结及任务实施
- C++编译期多态与运行期多态
- javascript中call apply 与 bind方法详解
- runtime
- runtime实用2
- AlwaysON下迁移数据库----无需破坏HADR
- System V进程通信
- Linux下配置NTP 架设本地时间服务器
- jdfz 培训总结 Day1
- caffe源码学习:softmaxWithLoss前向计算
- OSI模型
- poj 2253 Frogger
- Linux内核对per-cpu变量的实现
- Cocos 学习笔记1