env: Windows Server 2016
SQL Server 2016
這幾天出現一件震驚的事,系統人員在沒有告知DBA把磁碟標編擅自做更改,把E disk換為F disk。這個變更不僅讓資料庫無法運作。也造成SQL Server無法開啟。
啟動SQL Server錯誤訊息:
我們這次模擬已經安裝完畢後的SQL Server,並且變更磁碟造成路徑問題,嘗試修復此問題。
1.我們安裝的SQL Server路徑內容。
模擬的環境一樣是把SQL Server目錄設定在E disk。
2.開始在測試環境模擬變更SQL Server路徑。
Turn off SQL Server 2016 service
3.Change drive letter from e disk to f disk
4.Update the file directory from E to F of SQL Server in configuration manager
變更SQL Server Configuration Manager裡面設定的啟始參數路徑
5.Turn on SQL Server 2016 service
啟動SQL Server
6.SQL Server startup log
2019-06-23 13:21:11.56 spid5s Starting up database 'msdb'.
2019-06-23 13:21:11.56 spid5s Error: 17204, Severity: 16, State: 1.
2019-06-23 13:21:11.56 spid5s FCB::Open failed: Could not open file E:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\MSDBData.mdf for file number 1. OS error: 3(The system cannot find the path specified.).
2019-06-23 13:21:11.56 spid5s Error: 5120, Severity: 16, State: 101.
2019-06-23 13:21:11.56 spid5s Unable to open the physical file "E:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\MSDBData.mdf". Operating system error 3: "3(The system cannot find the path specified.)".
2019-06-23 13:21:11.56 spid5s Error: 17207, Severity: 16, State: 1.
2019-06-23 13:21:11.56 spid5s FileMgr::StartLogFiles: Operating system error 2(The system cannot find the file specified.) occurred while creating or opening file 'E:\Program Files\Microsoft S
2019-06-23 13:21:12.72 spid6s Starting up database 'model'.
2019-06-23 13:21:12.72 spid6s Error: 17204, Severity: 16, State: 1.
2019-06-23 13:21:12.72 spid6s FCB::Open failed: Could not open file E:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\model.mdf for file number 1. OS error: 3(The system cannot find the path specified.).
2019-06-23 13:21:12.72 spid6s Error: 5120, Severity: 16, State: 101.
2019-06-23 13:21:12.72 spid6s Unable to open the physical file "E:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\model.mdf". Operating system error 3: "3(The system cannot find the path specified.)".
2019-06-23 13:21:12.72 spid6s Error: 17207, Severity: 16, State: 1.
7.過程中我們嘗試修改registry。但是無法完成,MSDB還是有檔案路徑不正確的狀況。
因此必須還原之前的做法。
8.找出系統資料庫檔案路徑。
語法:
SELECT name, physical_name AS CurrentLocation
FROM sys.master_files
WHERE database_id IN(DB_ID(N'master'),DB_ID(N'model'),DB_ID(N'msdb'),DB_ID(N'tempdb'));
GO
9.變更資料庫路徑。
語法:
USE master;
GO
ALTER DATABASE [master]
MODIFY FILE (NAME = master, FILENAME = 'F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\master.mdf');
GO
ALTER DATABASE [master]
MODIFY FILE (NAME = mastlog, FILENAME = 'F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\mastlog.ldf');
GO
錯誤訊息:
Msg 5121, Level 16, State 1, Line 3
The path specified by "F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\master.mdf" is not in a valid directory.
Msg 5121, Level 16, State 1, Line 6
The path specified by "F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\mastlog.ldf" is not in a valid directory.
10.增加磁碟F disk,並增加對應的路徑'F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\'
語法:
New-Item -ItemType directory -Path 'F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\'
11.再次變更系統資料庫檔案路徑。
語法:
USE master;
GO
ALTER DATABASE [master]
MODIFY FILE (NAME = master, FILENAME = 'F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\master.mdf');
GO
ALTER DATABASE [master]
MODIFY FILE (NAME = mastlog, FILENAME = 'F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\mastlog.ldf');
GO
ALTER DATABASE [tempdb]
MODIFY FILE (NAME = tempdev, FILENAME = 'F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\tempdb.mdf');
GO
ALTER DATABASE [tempdb]
MODIFY FILE (NAME = templog, FILENAME = 'F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\templog.ldf');
GO
ALTER DATABASE [model]
MODIFY FILE (NAME = modeldev, FILENAME = 'F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\model.mdf');
GO
ALTER DATABASE [model]
MODIFY FILE (NAME = modellog, FILENAME = 'F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\modellog.ldf');
GO
ALTER DATABASE [msdb]
MODIFY FILE (NAME = MSDBData, FILENAME = 'F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\MSDBData.mdf');
GO
ALTER DATABASE [msdb]
MODIFY FILE (NAME = MSDBLog, FILENAME = 'F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\MSDBLog.ldf');
GO
訊息:
The file "master" has been modified in the system catalog. The new path will be used the next time the database is started.
The file "mastlog" has been modified in the system catalog. The new path will be used the next time the database is started.
The file "tempdev" has been modified in the system catalog. The new path will be used the next time the database is started.
The file "templog" has been modified in the system catalog. The new path will be used the next time the database is started.
The file "modeldev" has been modified in the system catalog. The new path will be used the next time the database is started.
The file "modellog" has been modified in the system catalog. The new path will be used the next time the database is started.
The file "MSDBData" has been modified in the system catalog. The new path will be used the next time the database is started.
The file "MSDBLog" has been modified in the system catalog. The new path will be used the next time the database is started.
12.停用SQL Server service。
13.移除第10步驟增加的F disk。
14.再次修改SQL Server Configuration Manager啟動路徑參數
15.啟動SQL Server service。
若沒有錯誤就是修改成功。
我的啟動log如下。
2019-06-23 14:25:11.88 Server Microsoft SQL Server 2016 (RTM) - 13.0.1601.5 (X64)
Apr 29 2016 23:23:58
Copyright (c) Microsoft Corporation
Enterprise Evaluation Edition (64-bit) on Windows Server 2016 Standard Evaluation 6.3 <X64> (Build 14393: )
2019-06-23 14:25:11.88 Server UTC adjustment: 8:00
2019-06-23 14:25:11.88 Server (c) Microsoft Corporation.
2019-06-23 14:25:11.88 Server All rights reserved.
2019-06-23 14:25:11.88 Server Server process ID is 3908.
2019-06-23 14:25:11.88 Server System Manufacturer: 'innotek GmbH', System Model: 'VirtualBox'.
2019-06-23 14:25:11.88 Server Authentication mode is MIXED.
2019-06-23 14:25:11.88 Server Logging SQL Server messages in file 'F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Log\ERRORLO'.
2019-06-23 14:25:11.88 Server The service account is 'NT Service\MSSQLSERVER'. This is an informational message; no user action is required.
2019-06-23 14:25:11.88 Server Registry startup parameters:
-d F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\master.mdf
-e F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Log\ERRORLO
-l F:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\mastlog.ldf
2019-06-23 14:25:11.88 Server Command Line Startup Parameters:
-s "MSSQLSERVER"
2019-06-23 14:25:11.88 Server SQL Server detected 1 sockets with 1 cores per socket and 1 logical processors per socket, 1 total logical processors; using 1 logical processors based on SQL Server licensing. This is an informational message; no user action is required.
2019-06-23 14:25:11.88 Server SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required.
2019-06-23 14:25:11.88 Server Detected 1023 MB of RAM. This is an informational message; no user action is required.
2019-06-23 14:25:11.88 Server Using conventional memory in the memory manager.
2019-06-23 14:25:11.98 Server Default collation: SQL_Latin1_General_CP1_CI_AS (us_english 1033)
2019-06-23 14:25:12.03 Server Buffer pool extension is already disabled. No action is necessary.
2019-06-23 14:25:12.09 Server InitializeExternalUserGroupSid failed. Implied authentication will be disabled.
2019-06-23 14:25:12.09 Server Implied authentication manager initialization failed. Implied authentication will be disabled.
2019-06-23 14:25:12.12 Server The maximum number of dedicated administrator connections for this instance is '1'
2019-06-23 14:25:12.12 Server This instance of SQL Server last reported using a process ID of 1900 at 6/23/2019 2:22:33 PM (local) 6/23/2019 6:22:33 AM (UTC). This is an informational message only; no user action is required.
2019-06-23 14:25:12.13 Server Node configuration: node 0: CPU mask: 0x0000000000000001:0 Active CPU mask: 0x0000000000000001:0. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.
2019-06-23 14:25:12.13 Server Using dynamic lock allocation. Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node. This is an informational message only. No user action is required.
2019-06-23 14:25:12.13 Server Database Instant File Initialization: enabled. For security and performance considerations see the topic 'Database Instant File Initialization' in SQL Server Books Online. This is an informational message only. No user action is required.
2019-06-23 14:25:12.16 Server Query Store settings initialized with enabled = 1,
2019-06-23 14:25:12.17 spid5s [INFO] HkHostDbCtxt::Initialize(): Database ID: [1] 'master'. XTP Engine version is 0.0.
2019-06-23 14:25:12.17 spid5s Starting up database 'master'.
2019-06-23 14:25:12.18 spid5s [INFO] HkHostDbCtxt::Initialize(): Database ID: [1] 'master'. XTP Engine version is 0.0.
2019-06-23 14:25:12.19 spid5s [INFO] HkHostDbCtxt::Initialize(): Database ID: [1] 'master'. XTP Engine version is 0.0.
2019-06-23 14:25:12.28 Server CLR version v4.0.30319 loaded.
2019-06-23 14:25:12.31 spid5s Resource governor reconfiguration succeeded.
2019-06-23 14:25:12.31 spid5s SQL Server Audit is starting the audits. This is an informational message. No user action is required.
2019-06-23 14:25:12.32 spid5s SQL Server Audit has started the audits. This is an informational message. No user action is required.
2019-06-23 14:25:12.36 spid5s SQL Trace ID 1 was started by login "sa".
2019-06-23 14:25:12.36 spid5s Server name is 'WIN2K16SQL2K163'. This is an informational message only. No user action is required.
2019-06-23 14:25:12.53 spid11s A self-generated certificate was successfully loaded for encryption.
2019-06-23 14:25:12.54 spid11s Server is listening on [ 'any' <ipv6> 1433].
2019-06-23 14:25:12.54 spid11s Server is listening on [ 'any' <ipv4> 1433].
2019-06-23 14:25:12.55 spid11s Server local connection provider is ready to accept connection on [ \\.\pipe\SQLLocal\MSSQLSERVER ].
2019-06-23 14:25:12.55 spid5s [INFO] HkHostDbCtxt::Initialize(): Database ID: [4] 'msdb'. XTP Engine version is 0.0.
2019-06-23 14:25:12.55 spid6s [INFO] HkHostDbCtxt::Initialize(): Database ID: [32767] 'mssqlsystemresource'. XTP Engine version is 0.0.
2019-06-23 14:25:12.55 spid11s Server local connection provider is ready to accept connection on [ \\.\pipe\sql\query ].
2019-06-23 14:25:12.55 spid5s Starting up database 'msdb'.
2019-06-23 14:25:12.55 spid6s Starting up database 'mssqlsystemresource'.
2019-06-23 14:25:12.58 Server Server is listening on [ ::1 <ipv6> 1434].
2019-06-23 14:25:12.59 Server Server is listening on [ 127.0.0.1 <ipv4> 1434].
2019-06-23 14:25:12.59 Server Dedicated admin connection support was established for listening locally on port 1434.
2019-06-23 14:25:12.63 spid11s SQL Server is now ready for client connections. This is an informational message; no user action is required.
2019-06-23 14:25:12.63 Server SQL Server is attempting to register a Service Principal Name (SPN) for the SQL Server service. Kerberos authentication will not be possible until a SPN is registered for the SQL Server service. This is an informational message. No user action is required.
2019-06-23 14:25:12.70 spid6s The resource database build version is 13.00.1601. This is an informational message only. No user action is required.
2019-06-23 14:25:12.70 spid5s [INFO] HkHostDbCtxt::Initialize(): Database ID: [4] 'msdb'. XTP Engine version is 0.0.
2019-06-23 14:25:12.70 spid6s [INFO] HkHostDbCtxt::Initialize(): Database ID: [32767] 'mssqlsystemresource'. XTP Engine version is 0.0.
2019-06-23 14:25:12.79 spid6s [INFO] HkHostDbCtxt::Initialize(): Database ID: [32767] 'mssqlsystemresource'. XTP Engine version is 0.0.
2019-06-23 14:25:12.79 spid5s [INFO] HkHostDbCtxt::Initialize(): Database ID: [4] 'msdb'. XTP Engine version is 0.0.
2019-06-23 14:25:12.83 Server The SQL Server Network Interface library successfully registered the Service Principal Name (SPN) [ MSSQLSvc/Win2k16SQL2k163.dba.com ] for the SQL Server service.
2019-06-23 14:25:12.83 Server The SQL Server Network Interface library successfully registered the Service Principal Name (SPN) [ MSSQLSvc/Win2k16SQL2k163.dba.com:1433 ] for the SQL Server service.
2019-06-23 14:25:12.89 spid6s [INFO] HkHostDbCtxt::Initialize(): Database ID: [3] 'model'. XTP Engine version is 0.0.
2019-06-23 14:25:12.89 spid6s Starting up database 'model'.
2019-06-23 14:25:12.93 Server Common language runtime (CLR) functionality initialized using CLR version v4.0.30319 from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\.
2019-06-23 14:25:12.95 spid6s [INFO] HkHostDbCtxt::Initialize(): Database ID: [3] 'model'. XTP Engine version is 0.0.
2019-06-23 14:25:12.97 spid6s [INFO] HkHostDbCtxt::Initialize(): Database ID: [3] 'model'. XTP Engine version is 0.0.
2019-06-23 14:25:13.01 spid6s Polybase feature disabled.
2019-06-23 14:25:13.01 spid6s Clearing tempdb database.
2019-06-23 14:25:13.09 Server Software Usage Metrics is disabled.
2019-06-23 14:25:13.42 spid6s [INFO] HkHostDbCtxt::Initialize(): Database ID: [2] 'tempdb'. XTP Engine version is 0.0.
2019-06-23 14:25:13.42 spid6s Starting up database 'tempdb'.
2019-06-23 14:25:13.46 spid6s [INFO] HkHostDbCtxt::Initialize(): Database ID: [2] 'tempdb'. XTP Engine version is 0.0.
2019-06-23 14:25:13.52 spid6s [INFO] HkHostDbCtxt::Initialize(): Database ID: [2] 'tempdb'. XTP Engine version is 0.0.
2019-06-23 14:25:13.64 spid6s The tempdb database has 1 data file(s).
2019-06-23 14:25:13.65 spid19s The Service Broker endpoint is in disabled or stopped state.
2019-06-23 14:25:13.65 spid19s The Database Mirroring endpoint is in disabled or stopped state.
2019-06-23 14:25:13.69 spid19s Service Broker manager has started.
2019-06-23 14:25:13.70 spid5s Recovery is complete. This is an informational message only. No user action is required.
2019-06-23 14:25:48.54 spid53 Attempting to load library 'xpsqlbot.dll' into memory. This is an informational message only. No user action is required.
2019-06-23 14:25:48.55 spid53 Using 'xpsqlbot.dll' version '2015.130.1601' to execute extended stored procedure 'xp_qv'. This is an informational message only; no user action is required.
2019-06-23 14:25:49.02 spid55 Attempting to load library 'xpstar.dll' into memory. This is an informational message only. No user action is required.
2019-06-23 14:25:49.04 spid55 Using 'xpstar.dll' version '2015.130.1601' to execute extended stored procedure 'xp_instance_regread'. This is an informational message only; no user action is required.