码迷,mamicode.com
首页 > 数据库 > 详细

SQL SERVER MOVING SYSTEM DATABASES

时间:2014-12-25 10:02:54      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:

  • Moving system databases
You might need to move system databases as part of a planned relocation or scheduled maintenance
operation. If you move a system database and later rebuild the master database, you must move that
system database again because the rebuild operation installs all system databases to their default
location. The steps for moving tempdb, model, and msdb are slightly different than for moving the
master database.
Note In SQL Server 2012, the mssqlsystemresource database can’t be moved. If you move
the fies for this database, you won’t be able to restart your SQL Server service.
Here are the steps for moving an undamaged system database (other than the master database):
1. For each fie in the database to be moved, use the ALTER DATABASE command with the
MODIFY FILE option to specify the new physical location.
2. Stop the SQL Server instance.
3. Physically move the fies.
4. Restart the SQL Server instance.
5. Verify the change by running the following query:
SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys.master_files

WHERE database_id = DB_ID(N‘<database_name>‘);


If the system database needs to be moved because of a hardware failure, the solution is a bit more
problematic because you might not have access to the server to run the ALTER DATABASE command.
Follow these steps to move a damaged system database (other than the master database or the
resource database):
1. Stop the instance of SQL Server if it has been started.
2. Start the instance of SQL Server in master-only recovery mode (by specifying traceflg 3608)
by entering one of the following commands at the command prompt:
-- If the instance is the default instance:
NET START MSSQLSERVER /f /T3608
-- For a named instance:
NET START MSSQL$instancename /f /T3608
/f indicates that the instance of SQL Server starts with minimal confiuration.
CHAPTER 4 Special databases 143
3. For each fie in the database to be moved, use the ALTER DATABASE command with the MODIFY FILE option to specify the new physical location. You can use    either Management Studio or the SQLCMD utility.
4. Exit Management Studio or the SQLCMD utility.
5. Stop the instance of SQL Server.
6. Physically move the fie or fies to the new location.
7. Restart the instance of SQL Server without traceflg 3608. For example, run NET START MSSQLSERVER.
8. Verify the change by running the following query:
SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys.master_files
WHERE database_id = DB_ID(N‘<database_name>‘);
  • Moving the master database
Full details on moving the master database can be found in SQL Server Books Online, but the steps are
summarized here. The biggest difference between moving this database and moving other system
databases is that you must go through the SQL Server Confiuration Manager.
To move the master database, followw these steps.
1. Open the SQL Server Confiuration Manager. Right-click the desired instance of SQL Server,
choose Properties, and then click the Startup Parameters tab.
2. Edit the Startup Parameters values to point to the new directory location for the master
database data and log fies and click Update. If you want, you can also move the SQL Server
error log fies. The parameter value for the data fie must follow the –d parameter, the value
for the log fie must follow the –l parameter, and the value for the error log must follow the –e
parameter, as shown here:
-dE:\Data\master.mdf
-lE:\Data\mastlog.ldf
-eE:\Data\LOG\ERRORLOG
3. Stop the instance of SQL Server and physically move the fies for to the new location.
4. Restart the instance of SQL Server.
5. Verify the fie change for the master database by running the following query:
SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys.master_files
WHERE database_id = DB_ID(‘master‘);
144 Microsoft SQL Server 2012 Internals
Finally, if you are also changing your drive letters or folders, you need to verify and perhaps
change the location of the SQL Server Agent error log fie and the confiured database default
locations setting. The Database default locations setting is defied on Server Properties | Database
Settings.


SQL SERVER MOVING SYSTEM DATABASES

标签:

原文地址:http://blog.csdn.net/wangzhpwang/article/details/42142285

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!