[英]What happens when a file on a remote disk is not reachable while inserting records?
假設我有兩個filegroups
A
和B
database
。 filegroup B
包含遠程服務器上的單個文件。
當我在filegroup B
上定義的table
插入記錄而遠程服務器處於脫機狀態時會發生什么?
數據庫引擎會在遠程服務器再次可用之前將所有內容存儲在 RAM 中嗎? 會超時嗎? 它會寫入本地磁盤上的臨時文件嗎?
需要明確的是:數據庫引擎在本地運行,但表存儲在遠程服務器上。
對於不涉及訪問文件存儲的任何操作,該表將是“可訪問的”。 您可以通過在 USB 驅動器上創建輔助文件組並在 USB 驅動器斷開連接時執行操作來輕松測試。
use [master]
go
create database [mysplitdb] on primary
(name = N'FileA', filename = N'C:\SQLData\mysplitdbA.mdf'),
filegroup B
(name = 'FileB', filename = 'E:\FileB.ndf') --<-- file on usb drive
log on
(name = N'mysplitdb_log', filename = N'C:\SQLData\mysplitdb_log.LDF')
go
use [mysplitdb]
go
create table dbo.OnSecFileGroup
(
id int identity primary key clustered,
col1 int,
col2 varchar(100)
) on [B];
insert into dbo.OnSecFileGroup(col1, col2)
select top (10000) row_number() over(order by (select null)), a.name
from master.dbo.spt_values as a
cross join master.dbo.spt_values as b;
checkpoint;
select *
from dbo.OnSecFileGroup;
--remove the usb drive(abruptly)
--works, from cache
select top 500 *
from dbo.OnSecFileGroup
where id between 5000 and 6000
--works
select top 500 *
from dbo.OnSecFileGroup
where id > 9000
--insert new rows
--works (log file available, dirty pages in cache)
insert into dbo.OnSecFileGroup(col1, col2)
select top (1000) row_number() over(order by (select null)), a.name
from master.dbo.spt_values as a
cross join master.dbo.spt_values as b;
--works (log file available, table read from cache)
insert into dbo.OnSecFileGroup(col1, col2)
select top (2000) col1, col2
from dbo.OnSecFileGroup;
--works
update top(500) s
set col1 = col1+100
from dbo.OnSecFileGroup as s;
--force flush to disk
--error:
--The operating system returned error ....
--Additional messages in the SQL Server error log and system event log may provide more detail.
--This is a severe system-level error condition that threatens database integrity and must be corrected immediately...
checkpoint;
use master
go
--db still online
select state_desc --ONLINE
from sys.databases
where name = 'mysplitdb'
--write more rows
use mysplitdb
go
--works
insert into dbo.OnSecFileGroup(col1, col2)
select top (12000) col1, col2
from dbo.OnSecFileGroup;
--error:
--Could not allocate space for object 'dbo.OnSecFileGroup'.'PK__OnSecFil__3213E83F0425A276' in database 'mysplitdb' because the 'B' filegroup is full.
--Create disk space by deleting unneeded files, dropping objects in the filegroup ...
insert into dbo.OnSecFileGroup(col1, col2)
select top (12000) col1, col2
from dbo.OnSecFileGroup;
--connection still open
--table accessible
select top (120) col1, col2
from dbo.OnSecFileGroup
order by newid();
--stop & start sql server
use master
go
--db not online
select state_desc --RECOVERY_PENDING
from sys.databases
where name = 'mysplitdb'
--stop sql server and connect usb
--start sql server
--mysplitdb online
use master
go
--db online
select state_desc --ONLINE
from sys.databases
where name = 'mysplitdb'
--remove usb
use mysplitdb
go
--needs access to file storage, after restart, nothing in cache
select top (120) col1, col2
from dbo.OnSecFileGroup
order by newid();
--db still online
--error..
dbcc checkdb('mysplitdb')
--cleanup
drop database mysplitdb
go
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.