17.07.2015 Views

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 7: <strong>FILESTREAM</strong> Database AdministrationUPDATE TOP (1) Items SETItemImage = CAST(REPLICATE('A', 2048) AS VARBINARY(MAX))Listing 7-17:Updating a <strong>FILESTREAM</strong> data value to create a garbage file.After the update, you will see that there are two files in the <strong>FILESTREAM</strong> data container.A new file has been generated with the modified value, and the previous file (whose nameyou noted) is now garbage.My tests show that deleting this garbage file manually, without waiting for the garbagecollector, does not corrupt the database in present versions <strong>of</strong> <strong>SQL</strong> <strong>Server</strong>. After deletingthe garbage files, I ran DBCC CHECKDB and no error was reported. This was surprising tome, because the garbage files are tracked internally through the <strong>FILESTREAM</strong> tombstonetable and I would expect <strong>SQL</strong> <strong>Server</strong> to report an error if one goes missing.As has been stressed several times already, it is not a good idea to touch the <strong>FILESTREAM</strong>data container directly. All access to the <strong>FILESTREAM</strong> data should be done through <strong>SQL</strong><strong>Server</strong> – either using T-<strong>SQL</strong> or through the Win32 API calls. Do not ever attempt to clean<strong>FILESTREAM</strong> garbage by yourself, unless there is an emergency where you are runningout <strong>of</strong> storage space and you badly need some <strong>of</strong> those garbage files to be removed (and,<strong>of</strong> course, you fully understand the risks <strong>of</strong> touching <strong>FILESTREAM</strong> data directly).Querying <strong>FILESTREAM</strong> Databases<strong>SQL</strong> <strong>Server</strong> has a number <strong>of</strong> <strong>FILESTREAM</strong>-related system views that you can use to queryadditional information about the <strong>FILESTREAM</strong> storage and activities. <strong>The</strong>y are listed inChapter 9: Investigating <strong>FILESTREAM</strong> Databases, along with coverage <strong>of</strong> a few new systemwait types to deal with the various <strong>FILESTREAM</strong>-related operations and some <strong>of</strong> thecommon <strong>FILESTREAM</strong> metadata queries that you might find very helpful while workingwith <strong>FILESTREAM</strong>-enabled databases.293

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!