There are considerations, restrictions and limitations to use FILESTREAM. They are listed below:
Works as it is or with some considerations
- SQL Server Integration Service (SSIS) – uses DT_IMAGE SSIS, can use import and export column transformation
- Log Shipping – supports – both primary and secondary servers must run MS SQL Server 2008 or above
- SQL Server Express – supports
- Full Text Indexing – works if there is an additional column in the table with filename extension for each BLOB
- Failover clustering – FILESTREAM filegroup must be on a shared disk, enable FILESTREAM on each node hosting FILESTREAM instance
- Replication – use NEWSEQUENTIALID(), Merge Replication synchronization over https using Web Synchronization has 50 MB limit
- Distributed Queries and Linked Server – can not use PathName() for four part name
- Contained Database – requires extra configuration outside database, hence not fully contained
Does not work
- Transparent Data Encryption (TDE) – does not work
- Database Snapshots – does not work with FILESTREAM filegroups
- Database Mirroring – does not support
To use FILESTREAM feature both Windows administrator and SQL Server administrator have to enable it. While enabling from Windows there are three options to choose from:
- Enable FILESTREAM for Transact-SQL Access check box.
- Enable FILESTREAM for file I/O streaming access. This is to read and write FILESTREAM data from Windows. Enter the name of the Windows share in the Windows Share Name box.
- Select Allow remote clients to have streaming access to FILESTREAM data. This is to let remote clients access the FILESTREAM data stored on this share.
For SQL Server instance there are three options to choose from:
- 0 – Disable FILESTREAM support for this instance
- 1 – enable FILESTREAM for Transact-SQL access only
- 2 – enable FILESTREAM for Transact-SQL and Win32 streaming access
Note that FILESTREAM would perform worse for 1MB+ size files for full read/write if Transact-SQL is chosen (and Win32 streaming is not chosen) than no FILESTREAM BLOB.
Now that FILESTREAM is enabled, we can go ahead to do the rest of the setups.
First, create a file group to keep the FILESTREAM data. There is a 1:1 mapping between data containers and file groups.
ALTER DATABASE MyDatabase ADD
FILEGROUP MyFileStreamGroup1 CONTAINS FILESTREAM;
Second, define data container. In the below example, “D:\Production” must exist already. “D:\Production\FileStreamDataContainerRoot” is going to be the root of the data container.
ALTER DATABASE MyDatabase ADD FILE (
NAME = FileStreamGroup1File,
FILENAME = 'D:\Production\FileStreamDataContainerRoot')
TO FILEGROUP MyFileStreamGroup1 ;
Third, create a table with a FILESTREAM column. All FILESTREAM columns of a table must go to a single FILESTREAM group that can be specified, defaulting to default FILESTREAM filegroup. Table must have a column of the non-null uniqueidentifier data type with ROWGUIDCOL attribute and either a UNIQUE or PRIMARY KEY single-column constraint. FILESTREAM data container will have a directory for a table with subdirectory corresponding to the FILESTREAM column of the table.
USE MyDatabase ;
CREATE TABLE TableWithFileStreamColumn (
DocumentID INT IDENTITY PRIMARY KEY,
Document VARBINARY (MAX) FILESTREAM NULL,
DocGUID UNIQUEIDENTIFIER NOT NULL ROWGUIDCOL UNIQUE DEFAULT NEWID ())
Now it is time to use FILESTREAM using standard Transact-SQL or Win32 APIs.
There should be some considerations regarding hardware selection/configuration and OS configuration like:
- Hard disk – SCSI is better for reliability and performance
- RAID level – RAID 10 is recommended even though at least 50% space is redundant depending on configuration
- Storage layout – all data in one volume may not be the right choice if load is high
- Cluster size – 64KB and above to reduce fragmentation, also defragment periodically
- Compression – cannot be enabled if cluster size is 4KB or less, may not be effective for all kinds of data, comes at the expense of CPU
- Anti-virus configuration – AV can need to be setup properly so that it does not delete FILESTREAM files
- Disable 8.3 naming for NTFS – if number of files are high then NTFS has to work harder to get a unique name
- Turn off last access time update – since files are not accessed by explorer rather SQL Server turning off this feature is OK and it saves a lot of time
- Security – SQL server need to be configured to use integrated security (Win32 file APIs to work that uses Windows token associated with the client’s thread accessing files)