Sie sind auf Seite 1von 4

FILESTREAM

FILESTREAM was introduced in SQL Server 2008 for the storage and management of
unstructured data. The FILESTREAM feature allows storing BLOB data (example: word
documents, image files, music and videos etc) in the NT file system and ensures transactional
consistency between the unstructured data stored in the NT file system and the structured
data stored in the table.

FILESTREAM allows SQL Server to take advantage of the NTFS I/O streaming capabilities and at
the same time, maintain transactional consistency of the data.

When the FILESTREAM attribute of a VARBINARY (MAX) column is set, it becomes a ‘FILESTREAM
enabled’ column. A VARBINARY (MAX) column with FILESTREAM attribute is not restricted to
the 2 GB limit SQL Server imposes on Large Value Types. The size of the file is limited by the
size of the disk volume only.

FILESTREAM feature may be enabled with three different levels of access to the FILESTREAM
data, namely:
1. Enable FILESTREAM for Transact-SQL access
2. Enable FILESTREAM for file I/O streaming access
3. Allow remote clients to have streaming access to FILESTREAM data

Enabling FILESTREAM during an Unattended installation


If you are installing SQL Server 2008 in ‘Unattended mode’, you can use /FILESTREAMLEVEL and
/FILESTREAMSHARENAME configuration options to configure FILESTREAM features.

Enabling FILESTREAM after installation


To enable FILESTREAM feature, go to ‘SQL Server configuration Manager’ and right click on
instance of SQL Server Service and select ‘properties’. The property page will show an
additional tab labeled ‘FILESTREAM’, which looks exactly the same as the FILESTREAM
configuration page shown as part of the installation wizard. The FILESTREAM feature can be
enabled by setting the appropriate options on this page.

Once FILESTREAM feature is enabled, the next step is to configure FILESTREAM Access Level.
This is an additional step that is required only if you configure FILESTREAM after the
installation of SQL Server. Open SQL Server Management Studio and open the properties of the
SQL Server 2008 instance. Select the ‘Advanced’ tab and change the ‘FILESTREAM Access Level’
to ‘Transact-SQL Access enabled’ or ‘Full access enabled’.
EXEC sp_configure filestream_access_level, 2
GO
RECONFIGURE
GO
The last parameter to sp_configure specifies the Access Level, where 0 means ‘Disabled’, 1
means ‘Transact-SQL Access Enabled’ and 2 means ‘Full Access Enabled’

Creating a FILESTREAM enabled database


The script that creates a FILESTREAM enabled database is
CREATE DATABASE NorthPole
ON
PRIMARY (
NAME = NorthPoleDB,
FILENAME = 'C:\Temp\NP\NorthPoleDB.mdf'
), FILEGROUP NorthPoleFS CONTAINS FILESTREAM(
NAME = NorthPoleFS,
FILENAME = 'C:\Temp\NP\NorthPoleFS')
LOG ON (
NAME = NorthPoleLOG,
FILENAME = 'C:\Temp\NP\NorthPoleLOG.ldf')
GO

Reviewing the FILESTREAM Data Container:


When we created the database, we had specified the path to the location that we wanted to
have configured as the FILESTREAM Data Container for our database. Open windows explorer
and navigate to the folder you specified as FILESTREAM Data Container while creating the
database.

You will see a folder named “$FSLOG” and a file “filestream.hdr” there. The folder “$FSLOG”
is the FILESTREAM equivalent of the Database Transaction Log file. “filestream.hdr” contains
important metadata information used by SQL Server internally. Make sure that you do not
tamper with this file.

Creating a table with FILESTREAM columns:


A FILESTREAM column is a VARBINARY(MAX) column that has the FILESTREAM attribute enabled.
Remember, FILESTREAM is not a new DATA TYPE, it is a new attribute added to a
VARBINARY(MAX) column.
CREATE TABLE [dbo].[Items](
[ItemID] UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL UNIQUE,
[ItemNumber] VARCHAR(20),
[ItemDescription] VARCHAR(50),
[ItemImage] VARBINARY(MAX) FILESTREAM NULL
)
Note that every table that has a FILESTREAM column should have a UNIQUEIDENTIFIER column
with ROWGUIDCOL and UNIQUE attributes.

FILESTREAM Feature Summary

• FILESTREAM feature is available with all versions of SQL Server 2008, including SQL
Server Express.
• SQL Server Express database has a 4 GB limitation; however this limitation does not
apply to the FILESTREAM data stored in a SQL Server Express database.
• FILESTREAM Columns can be replicated.
• FILESTREAM enabled databases can be used with LOG Shipping
• FILESTREAM columns can be used in Full Text Indexes
• FILESTREAM works with all recovery models
• FILESTREAM File Groups can be placed on compressed disk volumes
• The maximum size of the file that can be stored into the FILESTREAM data storage is
limited by the size of the disk volume only.

Restrictions on existing features


Though the FILESTREAM feature smoothly integrates with many of the existing features of SQL
Server, it adds restrictions to or completely disables a few other important features of SQL
Server.

• A FILESTREAM enabled database cannot be used for mirroring. This is one of the key
restrictions that I dislike. Mirroring is a very interesting feature and it cannot be used
with FILESTREAM.
• FILESTREAM data is not available in database snapshots. If you create database
snapshots and run a “SELECT * FROM table” query on a table with FILESTREAM columns,
you will get an error. All queries that you run on a FILESTREAM enabled table of a
database snapshot should exclude FILESTREAM columns.

FILESTREAM Limitations

The FILESTREAM implementation in SQL Server 2008 comes with a few limitations. The
following limitations make complete sense to me and I have no complaints on them.

• FILESTREAM columns cannot be used in Index Keys.


• FILESTREAM columns cannot be used in the INCLUDED columns of a Non Clustered Index
• FILESTREAM columns cannot be used in a Table Valued Parameter
• FILESTREAM columns cannot be used in a memory table
• FILESTREAM columns cannot be used in a global or local temp table
• Statistics cannot be created on FILESTREAM columns
• Computed columns having reference to FILESTREAM columns cannot be indexed
• When FILESTREAM Data is accessed through Win 32 APIs, only READ COMMITTED
ISOLATION level is supported.
• FILESTREAM data can be stored only on local disk volumes

However the following limitations are little restrictive and I really wish to have them removed
in the future versions of SQL Server.

• FILESTREAM data is not supported on Database Snapshots. Well, that is acceptable,


however what is the real pain is the error that we get if we run a “SELECT * FROM
table” query on a FILESTREAM enabled table in a database snapshot. SQL Server should
ideally return NULL values for FILESTREAM enabled columns, if it cannot create
snapshots of FILESTREAM data. At present, it is a real pain to exclude all FILESTREAM
enabled columns from all queries that runs on a Database Snapshot.
• Transparent Data Encryption (TDE) does not encrypt FILESTREAM data. It would be
interesting to have this restriction removed in the future.

FILESTREAM Feature - Points to Remember

Take note of the following points if you intend to use FILESTREAM in your application.

• You cannot do database mirroring if you use FILESTREAM features


• If you replicate FILESTREAM enabled columns, make sure that all subscribers are
running on SQL Server 2008 or later versions.
• If you intend to use LOG shipping, make sure that both primary and secondary servers
are running on SQL Server 2008 or later versions.
• If you are on a FAILOVER CLULSTERING environment, make sure that you place the
FILESTREAM file groups in a shared disk and FILESTREAM should be enabled on each
node.
• You cannot access FILESTREAM data if you create database snapshots. If you try to
access a FILESTREAM enabled column, SQL Server will raise an error.
• SQL Server Instance should be configured with Integrated Security if Win 32 access to
the FILESTREAM data is required

FILESTREAM Best Practices

• Place each FILESTREAM data container in a separate volume


• Use the correct RAID level depending upon the nature of the application (read
intensive, write intensive), expected work load etc
• Do periodical disk defragmentation
• Decide diligently on whether or not to use a compressed disk volume
• Disable 8.3 names in NTFS
• Disable last access time tracking in NTFS
• FILESTREAM data container should not be on a fragmented volume
• Make sure that the data being stored is appropriate for FILESTREAM storage.
FILESTREAM storage is only good if the size of the data is more than 1 MB (approx)
• Avoid multiple small appends to the FILESTREAM file
• If FILESTREAM files are large, avoid using TSQL access to the FILESTREAM data.
• If reads require only the first few bytes, then consider using TSQL access using
substring() function
• If the entire file is needed Win 32 access is desirable

Das könnte Ihnen auch gefallen