SQL SERVER MOVING SYSTEM DATABASES

來源:互聯網
上載者:User

標籤:

  • 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- onlyrecovery 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 4Special databases 143
3. For each fie in the database to be moved, use the ALTER DATABASE command with the  MODIFY FILEoption 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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.