背景
数据库默认安装在C盘,由于复制订阅或者大容量更新查询等导致tempdb系统库、distribution系统库容量过大,C盘容量不足,需要将部分系统库进行迁移,以distribution库为例进行系统库迁移,其他库类似操作即可。
查询当前系统库信息
use distribution go --查询逻辑名与当前路径 SELECT name, physical_name FROM sys.database_files
当前系统库路径为C:Program FilesMicrosoft SQL ServerMSSQL13.MSSQLSERVERMSSQLData,指定迁移到路径D:db
--修改到指定路径 ALTER DATABASE distribution MODIFY FILE (NAME = ‘distribution‘, FILENAME = ‘D:dbdistribution.mdf‘) ALTER DATABASE distribution MODIFY FILE (NAME = ‘distribution_log‘, FILENAME = ‘D:dbdistribution.LDF‘)
注意,如果是tempdb系统库迁移,可能会有多个ndf日志文件
--修改到指定路径 ALTER DATABASE tempdb MODIFY FILE (NAME = ‘tempdev‘, FILENAME = ‘D:dbtempdb.mdf‘) ALTER DATABASE tempdb MODIFY FILE (NAME = ‘templog‘, FILENAME = ‘D:dbtemplog.ldf‘) ALTER DATABASE tempdb MODIFY FILE (NAME = ‘temp2‘, FILENAME = ‘D:dbtempdb_mssql_2.ndf‘) ALTER DATABASE tempdb MODIFY FILE (NAME = ‘temp3‘, FILENAME = ‘D:dbtempdb_mssql_3.ndf‘) ALTER DATABASE tempdb MODIFY FILE (NAME = ‘temp4‘, FILENAME = ‘D:dbtempdb_mssql_4.ndf‘) ALTER DATABASE tempdb MODIFY FILE (NAME = ‘temp5‘, FILENAME = ‘D:dbtempdb_mssql_5.ndf‘) ALTER DATABASE tempdb MODIFY FILE (NAME = ‘temp6‘, FILENAME = ‘D:dbtempdb_mssql_6.ndf‘) ALTER DATABASE tempdb MODIFY FILE (NAME = ‘temp7‘, FILENAME = ‘D:dbtempdb_mssql_7.ndf‘) ALTER DATABASE tempdb MODIFY FILE (NAME = ‘temp8‘, FILENAME = ‘D:dbtempdb_mssql_8.ndf‘)
迁移
关闭MSSQLSERVER服务
将相关文件拷贝到新的地址
开启MSSQLSERVER服务
验证
use distribution go --查询逻辑名与当前路径 SELECT name, physical_name FROM sys.database_files
原C盘的文件可以正常删除了。