Skip to content

Commit ef48b80

Browse files
authored
Merge pull request #23865 from PiJoCoder/error_3056_7908_7906_jopilov
adding 3056 error and updating 7908 and 7906
2 parents 35a116b + 22402c1 commit ef48b80

4 files changed

Lines changed: 127 additions & 31 deletions

File tree

docs/relational-databases/blob/filestream-sql-server.md

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ monikerRange: ">=sql-server-2016||=azuresqldb-mi-current"
2020
# FILESTREAM (SQL Server)
2121
[!INCLUDE [SQL Server Windows Only - ASDBMI ](../../includes/applies-to-version/sql-windows-only.md)]
2222

23-
FILESTREAM enables [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]-based applications to store unstructured data, such as documents and images, on the file system. Applications can leverage the rich streaming APIs and performance of the file system and at the same time maintain transactional consistency between the unstructured data and corresponding structured data.
23+
FILESTREAM enables [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]-based applications to store unstructured data, such as documents and images, on the file system. Applications can use the rich streaming APIs and performance of the file system and at the same time maintain transactional consistency between the unstructured data and corresponding structured data.
2424

2525
FILESTREAM integrates the [!INCLUDE[ssDEnoversion](../../includes/ssdenoversion-md.md)] with an NTFS or ReFS file systems by storing **varbinary(max)** binary large object (BLOB) data as files on the file system. [!INCLUDE[tsql](../../includes/tsql-md.md)] statements can insert, update, query, search, and back up FILESTREAM data. Win32 file system interfaces provide streaming access to the data.
2626

27-
FILESTREAM uses the NT system cache for caching file data. This helps reduce any effect that FILESTREAM data might have on [!INCLUDE[ssDE](../../includes/ssde-md.md)] performance. The [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] buffer pool is not used; therefore, this memory is available for query processing.
27+
FILESTREAM uses the NT system cache for caching file data. Caching files in the system cache helps reduce any impact that FILESTREAM data might have on [!INCLUDE[ssDE](../../includes/ssde-md.md)] performance. The [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] buffer pool isn't used; therefore, this memory is available for query processing.
2828

2929
FILESTREAM is not automatically enabled when you install or upgrade [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]. You must enable FILESTREAM by using SQL Server Configuration Manager and [!INCLUDE[ssManStudioFull](../../includes/ssmanstudiofull-md.md)]. To use FILESTREAM, you must create or modify a database to contain a special type of filegroup. Then, create or modify a table so that it contains a **varbinary(max)** column with the FILESTREAM attribute. After you complete these tasks, you can use [!INCLUDE[tsql](../../includes/tsql-md.md)] and Win32 to manage the FILESTREAM data.
3030

@@ -34,29 +34,29 @@ In [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], BLOBs can be stand
3434

3535
- Objects that are being stored are, on average, larger than 1 MB.
3636
- Fast read access is important.
37-
- You are developing applications that use a middle tier for application logic.
37+
- You're developing applications that use a middle tier for application logic.
3838

3939
For smaller objects, storing **varbinary(max)** BLOBs in the database often provides better streaming performance.
4040

4141
## FILESTREAM Storage
4242

43-
FILESTREAM storage is implemented as a **varbinary(max)** column in which the data is stored as BLOBs in the file system. The sizes of the BLOBs are limited only by the volume size of the file system. The standard **varbinary(max)** limitation of 2-GB file sizes does not apply to BLOBs that are stored in the file system.
43+
FILESTREAM storage is implemented as a **varbinary(max)** column in which the data is stored as BLOBs in the file system. The sizes of the BLOBs are limited only by the volume size of the file system. The standard **varbinary(max)** limitation of 2-GB file sizes doesn't apply to BLOBs that are stored in the file system.
4444

45-
To specify that a column should store data on the file system, specify the FILESTREAM attribute on a **varbinary(max)** column. This causes the [!INCLUDE[ssDE](../../includes/ssde-md.md)] to store all data for that column on the file system, but not in the database file.
45+
To specify that a column should store data on the file system, specify the FILESTREAM attribute on a **varbinary(max)** column. This attribute causes the [!INCLUDE[ssDE](../../includes/ssde-md.md)] to store all data for that column on the file system, but not in the database file.
4646

4747
FILESTREAM data must be stored in FILESTREAM filegroups. A FILESTREAM filegroup is a special filegroup that contains file system directories instead of the files themselves. These file system directories are called *data containers*. Data containers are the interface between [!INCLUDE[ssDE](../../includes/ssde-md.md)] storage and file system storage.
4848

4949
When you use FILESTREAM storage, consider the following:
5050

5151
- When a table contains a FILESTREAM column, each row must have a nonnull unique row ID.
5252
- Multiple data containers can be added to a FILESTREAM filegroup.
53-
- FILESTREAM data containers cannot be nested.
54-
- When you are using failover clustering, the FILESTREAM filegroups must be on shared disk resources.
53+
- FILESTREAM data containers can't be nested.
54+
- When you're using failover clustering, the FILESTREAM filegroups must be on shared disk resources.
5555
- FILESTREAM filegroups can be on compressed volumes.
5656

5757
### Integrated Management
5858

59-
Because FILESTREAM is implemented as a **varbinary(max)** column and integrated directly into the [!INCLUDE[ssDE](../../includes/ssde-md.md)], most [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] management tools and functions work without modification for FILESTREAM data. For example, you can use all backup and recovery models with FILESTREAM data, and the FILESTREAM data is backed up with the structured data in the database. If you do not want to back up FILESTREAM data with relational data, you can use a partial backup to exclude FILESTREAM filegroups.
59+
Because FILESTREAM is implemented as a **varbinary(max)** column and integrated directly into the [!INCLUDE[ssDE](../../includes/ssde-md.md)], most [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] management tools and functions work without modification for FILESTREAM data. For example, you can use all backup and recovery models with FILESTREAM data, and the FILESTREAM data is backed up with the structured data in the database. If you don't want to back up FILESTREAM data with relational data, you can use a partial backup to exclude FILESTREAM filegroups.
6060

6161
### Integrated Security
6262

@@ -79,18 +79,22 @@ After you store data in a FILESTREAM column, you can access the files by using [
7979
By using [!INCLUDE[tsql](../../includes/tsql-md.md)], you can insert, update, and delete FILESTREAM data:
8080

8181
- You can use an insert operation to prepopulate a FILESTREAM field with a null value, empty value, or relatively short inline data. However, a large amount of data is more efficiently streamed into a file that uses Win32 interfaces.
82-
- When you update a FILESTREAM field, you modify the underlying BLOB data in the file system. When a FILESTREAM field is set to NULL, the BLOB data associated with the field is deleted. You cannot use a [!INCLUDE[tsql](../../includes/tsql-md.md)] chunked update, implemented as UPDATE**.**Write(), to perform partial updates to the data.
82+
- When you update a FILESTREAM field, you modify the underlying BLOB data in the file system. When a FILESTREAM field is set to NULL, the BLOB data associated with the field is deleted. You can't use a [!INCLUDE[tsql](../../includes/tsql-md.md)] chunked update, implemented as UPDATE**.**Write(), to perform partial updates to the data.
8383
- When you delete a row or delete or truncate a table that contains FILESTREAM data, you delete the underlying BLOB data in the file system.
8484

8585
### File System Streaming Access
8686

8787
The Win32 streaming support works in the context of a [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] transaction. Within a transaction, you can use FILESTREAM functions to obtain a logical UNC file system path of a file. You then use the OpenSqlFilestream API to obtain a file handle. This handle can then be used by Win32 file streaming interfaces, such as ReadFile() and WriteFile(), to access and update the file by way of the file system.
8888

89-
Because file operations are transactional, you cannot delete or rename FILESTREAM files through the file system.
89+
Because file operations are transactional, you can't delete or rename FILESTREAM files through the file system.
90+
91+
>[!WARNING]
92+
>The FILESTREAM container is a folder managed by SQL Server. Do not add or remove files in the FILESTREAM folder manually or through other applications. If you do, this will result in backup and inconsistency errors. For more information, see [MSSQLSERVER_3056](../errors-events/mssqlserver-3056-database-engine-error.md), [MSSQLSERVER_7908](../errors-events/mssqlserver-7908-database-engine-error.md), and [MSSQLSERVER_7906](../errors-events/mssqlserver-7906-database-engine-error.md).
93+
9094

9195
**Statement Model**
9296

93-
The FILESTREAM file system access models a [!INCLUDE[tsql](../../includes/tsql-md.md)] statement by using file open and close. The statement starts when a file handle is opened and ends when the handle is closed. For example, when a write handle is closed, any possible AFTER trigger that is registered on the table fires as if an UPDATE statement is completed.
97+
The FILESTREAM file system access models a [!INCLUDE[tsql](../../includes/tsql-md.md)] statement by using file open and close. The statement starts when a file handle is opened and ends when the handle is closed. For example, when a write handle is closed, any possible AFTER trigger that is registered on the table, fires as if an UPDATE statement is completed.
9498

9599
**Storage Namespace**
96100

@@ -100,25 +104,25 @@ In FILESTREAM, the [!INCLUDE[ssDE](../../includes/ssde-md.md)] controls the BLOB
100104

101105
A new intrinsic function, [GET_FILESTREAM_TRANSACTION_CONTEXT()](../../t-sql/functions/get-filestream-transaction-context-transact-sql.md), provides the token that represents the current transaction that the session is associated with. The transaction must have been started and not yet aborted or committed. By obtaining a token, the application binds the FILESTREAM file system streaming operations with a started transaction. The function returns NULL in case of no explicitly started transaction.
102106

103-
All file handles must be closed before the transaction commits or aborts. If a handle is left open beyond the transaction scope, additional reads against the handle will cause a failure; additional writes against the handle will succeed, but the actual data will not be written to disk. Similarly, if the database or instance of the [!INCLUDE[ssDE](../../includes/ssde-md.md)] shuts down, all open handles are invalidated.
107+
All file handles must be closed before the transaction commits or aborts. If a handle is left open beyond the transaction scope, additional reads against the handle will cause a failure; additional writes against the handle will succeed, but the actual data won't be written to disk. Similarly, if the database or instance of the [!INCLUDE[ssDE](../../includes/ssde-md.md)] shuts down, all open handles are invalidated.
104108

105109
**Transactional Durability**
106110

107111
With FILESTREAM, upon transaction commit, the [!INCLUDE[ssDE](../../includes/ssde-md.md)] ensures transaction durability for FILESTREAM BLOB data that is modified from the file system streaming access.
108112

109113
**Isolation Semantics**
110114

111-
The isolation semantics are governed by [!INCLUDE[ssDE](../../includes/ssde-md.md)] transaction isolation levels. Read-committed isolation level is supported for [!INCLUDE[tsql](../../includes/tsql-md.md)] and file system access. Repeatable read operations, and also serializable and snapshot isolations, are supported. Dirty read is not supported.
115+
The isolation semantics are governed by [!INCLUDE[ssDE](../../includes/ssde-md.md)] transaction isolation levels. Read-committed isolation level is supported for [!INCLUDE[tsql](../../includes/tsql-md.md)] and file system access. Repeatable read operations, serializable and snapshot isolation levels are supported. Dirty read isn't supported.
112116

113-
The file system access open operations do not wait for any locks. Instead, the open operations fail immediately if they cannot access the data because of transaction isolation. The streaming API calls fail with ERROR_SHARING_VIOLATION if the open operation cannot continue because of isolation violation.
117+
The file system access open operations do not wait for any locks. Instead, the open operations fail immediately if they can't access the data because of transaction isolation. The streaming API calls fail with ERROR_SHARING_VIOLATION if the open operation cannot continue because of isolation violation.
114118

115119
To allow for partial updates to be made, the application can issue a device FS control (FSCTL_SQL_FILESTREAM_FETCH_OLD_CONTENT) to fetch the old content into the file that the opened handle references. This will trigger a server-side old content copy. For better application performance and to avoid running into potential time-outs when you are working with very large files, we recommend that you use asynchronous I/O.
116120

117121
If the FSCTL is issued after the handle has been written to, the last write operation will persist, and prior writes that were made to the handle are lost.
118122

119123
**File System APIs and Supported Isolation Levels**
120124

121-
When a file system API cannot open a file because of an isolation violation, an ERROR_SHARING_VIOLATION exception is returned. This isolation violation occurs when two transactions try to access the same file. The outcome of the access operation depends on the mode the file was opened in and the version of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] that the transaction is running on. The following table outlines the possibly outcomes for two transactions that are accessing the same file.
125+
When a file system API cannot open a file because of an isolation violation, an ERROR_SHARING_VIOLATION exception is returned. This isolation violation occurs when two transactions try to access the same file. The outcome of the access operation depends on the mode the file was opened in and the version of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] that the transaction is running on. The following table outlines the possible outcomes for two transactions that are accessing the same file.
122126

123127
|Transaction 1|Transaction 2|Outcome on SQL Server 2008|Outcome on SQL Server 2008 R2 and later versions|
124128
|-------------------|-------------------|--------------------------------|------------------------------------------------------|
@@ -139,15 +143,15 @@ When a file system API cannot open a file because of an isolation violation, an
139143

140144
**Write-Through from Remote Clients**
141145

142-
Remote file system access to FILESTREAM data is enabled over the Server Message Block (SMB) protocol. If the client is remote, no write operations are cached by the client side. The write operations will always be sent to the server. The data can be cached on the server side. We recommend that applications that are running on remote clients consolidate small write operations to make fewer write operations using larger data size.
146+
Remote file system access to FILESTREAM data is enabled over the Server Message Block (SMB) protocol. If the client is remote, no write operations are cached by the client side. The write operations will always be sent to the server. The data can be cached on the server side. We recommend that applications that are running on remote clients consolidate small write operations into larger size operations. The goal is to perform fewer writes.
143147

144148
Creating memory mapped views (memory mapped I/O) by using a FILESTREAM handle is not supported. If memory mapping is used for FILESTREAM data, the [!INCLUDE[ssDE](../../includes/ssde-md.md)] cannot guarantee consistency and durability of the data or the integrity of the database.
145149

146150
## Recommendations and guidelines for improving FILESTREAM performance
147151

148-
The SQL Server FILESTREAM feature allow you to store varbinary(max) binary large object data as files in the file system. When you have a large number of rows in FILESTREAM containers, which are the underlying storage for both FILESTREAM columns and FileTables, you can end up with a file system volume that contains large number of files. To achieve best performance when processing the integrated data from the database as well as the file system, it is important to ensure the file system is tuned optimally. The following are some of the tuning options that are available from a file system perspective:
152+
The SQL Server FILESTREAM feature allows you to store varbinary(max) binary large object data as files in the file system. When you have a large number of rows in FILESTREAM containers, which are the underlying storage for both FILESTREAM columns and FileTables, you can end up with a file system volume that contains large number of files. To achieve best performance when processing the integrated data from the database and the file system, it is important to ensure the file system is tuned optimally. The following are some of the tuning options that are available from a file system perspective:
149153

150-
- Altitude check for the SQL Server FILESTREAM filter driver [e.g. rsfx0100.sys]. Evaluate all the filter drivers loaded for the storage stack associated with a volume where the FILESTREAM feature stores files and make sure that rsfx driver is located at the bottom of the stack. You can use the FLTMC.EXE control program to enumerate the filter drivers for a specific volume. Here is a sample output from the FLTMC utility: `C:\Windows\System32>fltMC.exe` filters
154+
- Altitude check for the SQL Server FILESTREAM filter driver [for example, rsfx0100.sys]. Evaluate all the filter drivers loaded for the storage stack associated with a volume where the FILESTREAM feature stores files and make sure that rsfx driver is located at the bottom of the stack. You can use the FLTMC.EXE control program to enumerate the filter drivers for a specific volume. Here's a sample output from the FLTMC utility: `C:\Windows\System32>fltMC.exe` filters
151155

152156
|Filter Name|Num Instances|Altitude|Frame|
153157
|---|---|---|---|
@@ -186,7 +190,8 @@ Value: 1
186190

187191
SQL Server 2012 supports multiple containers per filegroup and can make things much easier. No complicated partitioning schemes may be needed to manage larger number of files.
188192

189-
- When there are very large number of FILESTREAM containers in a SQL instance, starting the databases which have many FILESTREAM containers might take a long time to register them in the FILESTREAM filter driver. Spreading them in multiple different volumes will help with improving database startup time.
193+
- When there are a very large number of FILESTREAM containers in a SQL instance, starting the databases with many FILESTREAM containers might take a long time to register them in the FILESTREAM filter driver. Spreading them in multiple different volumes will help with improving database startup time.
194+
190195

191196
- The NTFS MFT may become fragmented, and that can cause performance issues. The MFT reserved size does depend on volume size, so you may or may not encounter this.
192197

0 commit comments

Comments
 (0)