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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 7: <strong>FILESTREAM</strong> Database Administrationcontains the record is still active, and will remain so until the log is backed up. Every<strong>FILESTREAM</strong> operation is mapped to a transaction LSN in the transaction log. UnderFULL and BULK_LOGGED recovery models, the garbage collector will remove a file onlyafter the transaction log VLF that contains the LSN associated with the <strong>FILESTREAM</strong>operation is not part <strong>of</strong> the active log.<strong>FILESTREAM</strong> garbage collection and tombstonetablesAs we have seen, <strong>SQL</strong> <strong>Server</strong> does not support in-place updates <strong>of</strong> <strong>FILESTREAM</strong> data. Ifwe modify a BLOB value stored in a <strong>FILESTREAM</strong> column, <strong>SQL</strong> <strong>Server</strong> will create a newdisk file with the modified value. <strong>The</strong> old file will stay around for some time until it is "nolonger needed" and the garbage collector steps in and deletes it.It is interesting to note how <strong>SQL</strong> <strong>Server</strong> keeps track <strong>of</strong> the garbage files. If we modify afew <strong>FILESTREAM</strong> data values and look into the <strong>FILESTREAM</strong> data folder, we'll find manymore files than the number <strong>of</strong> rows in the table. So the question is, "Which are garbagefiles and which are not?" <strong>SQL</strong> <strong>Server</strong> creates an internal table called the <strong>FILESTREAM</strong>tombstone table to hold the details <strong>of</strong> garbage files to be removed. <strong>The</strong> garbage collectorqueries this table to identify the garbage files and removes them when those files are nolonger needed.To see this in action, run the script in Listing 7-6 to create a sample database containing atable with two <strong>FILESTREAM</strong> columns.USE masterGOIF DB_ID('NorthPole') IS NOT NULLDROP DATABASE NorthPoleGO280

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

Saved successfully!

Ooh no, something went wrong!