Google Custom Search

Wednesday, January 14, 2009

Introduction to SQL Server Trace Flags

               This article takes you to describing about the Trace Flags and its usage in SQL Server.

Common Terms Used:

                DBCC TRACEON

                DBCC TRACEOFF

                DBCC TRACESTATUS

                Trace flags can be enabled at session level or global level.  Session level trace flags are available and active for that connection whereas Global Trace flags are available and active throughout the server.

                Global Trace flag is enabled at server level at startup with a –T parameter used in it.

                Session level Trace flags are enabled using DBCC TRACEON command, we can find the trace that are active using the DBCC TRACESTATUS command and can be disabled using DBCC TRACEOFF command.


Trace flag

Description

-1

Sets trace flags for all client connections, rather than for a single client connection. Because trace flags set using the -T command-line option automatically apply to all connections, this trace flag is used only when setting trace flags using DBCC TRACEON and DBCC TRACEOFF.

106

Disables line number information for syntax errors.

107

Interprets numbers with a decimal point as float instead of decimal.

205

Report when a statistics-dependent stored procedure is being recompiled as a result of AutoStat.

206

Provides backward compatibility for the setuser statement.

208

SET QUOTED IDENTIFIER ON.

242

Provides backward compatibility for correlated subqueries where non-ANSI-standard results are desired.

243

The behavior of SQL Server is now more consistent because nullability checks are made at run time and a nullability violation results in the command terminating and the batch or transaction process continuing.

244

Disables checking for allowed interim constraint violations. By default, SQL Server checks for and allows interim constraint violations. An interim constraint violation is caused by a change that removes the violation such that the constraint is met, all within a single statement and transaction. SQL Server checks for interim constraint violations for self-referencing DELETE statements, INSERT, and multirow UPDATE statements. This checking requires more work tables. With this trace flag you can disallow interim constraint violations, thus requiring fewer work tables.

257

Will invoke a print algorithm on the XML output before returning it to make the XML result more readable.

260

Prints the versioning information about extended stored procedure dlls.

302

Prints information about whether the statistics page is used, the actual selectivity (if available), and what SQL Server estimated the physical and logical I/O would be for the indexes. Trace flag 302 should be used with trace flag 310 to show the actual join ordering.

310

Prints information about join order. Index selection information is also available in a more readable format using SET SHOWPLAN_ALL, as described in the SET statement.

325

Prints information about the cost of using a nonclustered index or a sort to process an ORDER BY clause.

326

Prints information about the estimated and actual cost of sorts.

330

Enables full output when using the SET SHOWPLAN_ALL option, which gives detailed information about joins.

506

Enforces SQL-92 standards regarding null values for comparisons between variables and parameters. Any comparison of variables and parameters that contain a NULL always results in a NULL.

652

Disables read ahead for the server.

653

Disables read ahead for the current connection.

809

Limits the amount of Lazy Write activity in SQL Server 2000.

1180

Forces allocation to use free pages for text or image data and maintain efficiency of storage.

1200

Prints lock information (the process ID and type of lock requested).

1204

Returns the type of lock participating in the deadlock and the current command affect by the deadlock.

1205

Returns more detailed information about the command being executed at the time of a deadlock.

1206

Used to complement flag 1204 by displaying other locks held by deadlock parties

1609

Turns on the unpacking and checking of remote procedure call (RPC) information in Open Data Services. Used only when applications depend on the old behavior.

1704

Prints information when a temporary table is created or dropped.

1807

Allows you to configure SQL Server with network-based database files.

2505

Prevents DBCC TRACEON 208, SPID 10 errors from appearing in the error log.

2508

Disables parallel non-clustered index checking for DBCC CHECKTABLE.

2509

Used with DBCC CHECKTABLE.html to see the total count of ghost records in a table

2528

Disables parallel checking of objects by DBCC commands.

2701

Sets the @@ERROR system function to 50000 for RAISERROR messages with severity levels of 10 or less. When disabled, sets the @@ERROR system function to 0 for RAISERROR messages with severity levels of 10 or less.

3104

Causes SQL Server to bypass checking for free space.

3111

Cause LogMgr::ValidateBackedupBlock to be skipped during backup and restore operations.

3205

Disables hardware compression for tape drivers.

3222

Disables the read ahead that is used by the recovery operation during roll forward operations.

3502

Prints a message to the log at the start and end of each checkpoint.

3503

Indicates whether the checkpoint at the end of automatic recovery was skipped for a database (this applies only to read-only databases).

3602

Records all error and warning messages sent to the client.

3604

Sends trace output to the client. Used only when setting trace flags with DBCC TRACEON and DBCC TRACEOFF.

3605

Sends trace output to the error log. (If you start SQL Server from the command prompt, the output also appears on the screen.)

3607

Skips automatic recovery (at startup) for all databases.

3608

Skips automatic recovery (at startup) for all databases except the master database.

3609

Skips the creation of the tempdb database at startup. Use this trace flag if the device or devices on which tempdb resides are problematic or problems exist in the model database.

3626

Turns on tracking of the CPU data for the sysprocesses table.

3640

Eliminates the sending of DONE_IN_PROC messages to the client for each statement in a stored procedure. This is similar to the session setting of SET NOCOUNT ON, but when set as a trace flag, every client session is handled this way.

4022

Bypasses automatically started procedures.

4030

Prints both a byte and ASCII representation of the receive buffer. Used when you want to see what queries a client is sending to SQL Server. You can use this trace flag if you experience a protection violation and want to determine which statement caused it. Typically, you can set this flag globally or use SQL Server Enterprise Manager. You can also use DBCC INPUTBUFFER.

4031

Prints both a byte and ASCII representation of the send buffers (what SQL Server sends back to the client). You can also use DBCC OUTPUTBUFFER.

4032

Traces the SQL commands coming in from the client. The output destination of the trace flag is controlled with the 3605/3604 trace flags.

7300

Retrieves extended information about any error you encounter when you execute a distributed query.

7501

Dynamic cursors are used by default on forward-only cursors. Dynamic cursors are faster than in earlier versions and no longer require unique indexes. This flag disables the dynamic cursor enhancements and reverts to version 6.0 behavior.

7502

Disables the caching of cursor plans for extended stored procedures.

7505

Enables version 6.x handling of return codes when calling dbcursorfetchex and the resulting cursor position follows the end of the cursor result set.

7525

Reverts to the SQL Server 7.0 behavior of closing nonstatic cursors regardless of the SET CURSOR_CLOSE_ON_COMMIT state in SQL Server 2000.

8202

Replicates all UPDATE commands as DELETE/INSERT pairs at the publisher.

8206

Supports stored procedure execution with a user specified owner name for SQL Server subscribers or without owner qualification for heterogeneous subscribers in SQL Server 2000.

8207

Enables singleton updates for Transactional Replication, released with SQL Server 2000 Service Pack 1.

8599

Allows you to use a savepoint within a distributed transaction.

8679

Prevents the SQL Server optimizer from using a Hash Match Team operator.

8687

Used to disable query parallelism.

8721

Dumps information into the error log when AutoStat has been run.

8783

Allows DELETE, INSERT, and UPDATE statements to honor the SET ROWCOUNT ON setting when enabled.

8816

Logs every two-digit year conversion to a four-digit year.

260

Prints versioning information about extended Stored procedured dynamic link libraries

1204

Returns the resources and types of locks participating in a deadlock and also the current command affected.

1211

Disables lock escalation based on memory pressure, or based on number of locks. The SQL Server Database Engine will not escalate row or page locks to table locks.Using this trace flag can generate excessive numbers of locks. This can slow the performance of the Database Engine, or cause 1204 errors (unable to allocate lock resource) because of insufficient memory. If both trace flag 1211 and 1224 are set, 1211 takes precedence over 1224. However, because trace flag 1211 prevents escalation in every case, even under memory pressure, we recommend that you use 1224. This helps avoid "out-of-locks" errors when many locks are being used.

1222

Returns the resources and types of locks that are participating in a deadlock and also the current command affected, in an XML format that does not comply with any XSD schema.

1224

Disables lock escalation based on the number of locks. However, memory pressure can still activate lock escalation. The Database Engine escalates row or page locks to table (or partition) locks if the amount of memory used by lock objects exceeds one of the following conditions:Forty percent of the memory that is used by Database Engine, exclusive of memory allocation using Address Windowing Extension (AWE). This is applicable only when the locks parameter of sp_configure is set to 0.Forty percent of the lock memory that is configured by using the locks parameter of sp_configure. If both trace flag 1211 and 1224 are set, 1211 takes precedence over 1224. However, because trace flag 1211 prevents escalation in every case, even under memory pressure, we recommend that you use 1224. This helps avoid "out-of-locks" errors when many locks are being used.Lock escalation to the table- or HoBT-level granularity can also be controlled by using the LOCK_ESCALATION option of the ALTER TABLEstatement.

2528

Disables parallel checking of objects by DBCC CHECKDB, DBCC CHECKFILEGROUP, and DBCC CHECKTABLE. By default, the degree of parallelism is automatically determined by the query processor. The maximum degree of parallelism is configured just like that of parallel queries. For more information, see max degree of parallelism Option.Parallel DBCC should typically be left enabled. For DBCC CHECKDB, the query processor reevaluates and automatically adjusts parallelism with each table or batch of tables checked. Sometimes, checking may start when the server is almost idle. An administrator who knows that the load will increase before checking is complete may want to manually decrease or disable parallelism.Disabling parallel checking of DBCC can cause DBCC to take much longer to complete and if DBCC is run with the TABLOCK feature enabled and parallelism set off, tables may be locked for longer periods of time.

3205

By default, if a tape drive supports hardware compression, either the DUMP or BACKUP statement uses it. With this trace flag, you can disable hardware compression for tape drivers. This is useful when you want to exchange tapes with other sites or tape drives that do not support compression.

3226

By default, every successful backup operation adds an entry in the SQL Server error log and in the system event log. If you create very frequent log backups, these success messages accumulate quickly, resulting in huge error logs in which finding other messages is problematic.With this trace flag, you can suppress these log entries. This is useful if you are running frequent log backups and if none of your scripts depend on those entries.

3608

Prevents SQL Server from automatically starting and recovering any database except the master database. Databases will be started and recovered when accessed. Some features, such as snapshot isolation and read committed snapshot, might not work. Use for Moving System Databases and Moving User Databases. Do not use during normal operation.

3625

Limits the amount of information returned in error messages. For more information, see Metadata Visibility Configuration.

4616

Makes server-level metadata visible to application roles. In SQL Server, an application role cannot access metadata outside its own database because application roles are not associated with a server-level principal. This is a change of behavior from earlier versions of SQL Server. Setting this global flag disables the new restrictions, and allows for application roles to access server-level metadata.

6527

Disables generation of a memory dump on the first occurrence of an out-of-memory exception in CLR integration. By default, SQL Server generates a small memory dump on the first occurrence of an out-of-memory exception in the CLR. The behavior of the trace flag is as follows:If this is used as a startup trace flag, a memory dump is never generated. However, a memory dump may be generated if other trace flags are used.If this trace flag is enabled on a running server, a memory dump will not be automatically generated from that point on. However, if a memory dump has already been generated due to an out-of-memory exception in the CLR, this trace flag will have no effect.

7806

Enables a dedicated administrator connection (DAC) on SQL Server Express. By default, no DAC resources are reserved on SQL Server Express. For more information, see Using a Dedicated Administrator Connection.

 

Sunday, January 4, 2009

Policy Based Management in SQL Server 2008

This article discusses the new feature named Policy Based Management in SQL Server 2008. Policy Based Management is an extensive management configuration that can be used to manage servers, databases and objects. Policy Based framework provides a way to define policies that apply to servers, databases and objects. With Policy based Management framework, you can enforce consistent policies across all servers.

Terms used in Policy Based Framework:

Facet: Is a management area within policy based environment.

Condition: Defines the permitted state of one or more properties in a defined facet.

Policy: Contains a single condition that is to be enforced.

Category: Contains one or more policies that you want to enforce.

Target: Defines the servers, databases or other database objects for which the polices are to be enforced.

Listed below is the evaluation modes that are available in Policy Based Management in SQL Server 2008.

On Demand - Evaluates the policy only when you directly execute the policy.(Manual)

On Change: Prevent - When nested triggers are enabled, uses data definition language (DDL) triggers to prevent policy violations by detecting changes that violate policy and rolling them back.(Automatic)

On Change: Log Only - Evaluates a policy when a relevant change is made and logs policy violations in the event logs.(Automatic)

On Schedule - Uses SQL Server Agent jobs to periodically evaluate policies. Logs policy violations in the event logs and generates a report.(Automatic)

Policies that are executed automatically are executed under the member of a sysadmin role and hence are written to the event logs. Policies that are executed manually are executed under the context of the current user. This user needs permission of ALTER TRACE to write to event logs.

Permission Needed to Configure Policy Based Management: You need PolicyAdministratorRole role in msdb database to configure Policy Based Management Settings.

SQL Server stores policy related data in msdb database. You must backup this database after changes to conditions, policies and categories.

SQL Server 2008 has predefined policies and they are listed below.

Asymmetric Key Encryption Algorithm :
Checks whether asymmetric keys were created by using 1024-bit or stronger encryption. As a best practice, you should use RSA 1024-bit or stronger encryption to create asymmetric keys for data encryption.

Backup And Data File Location:
Checks whether database files are on devices separate from the backup files. As a best practice, you should put the database and backups on separate backup devices.

CmdExec Rights Secured
Checks an instance of SQL Server 2000 to determine whether only members of the sysadmin server role can run CmdExec and ActiveX Script job steps, which is a recommended best practice.

Data And Log File Location
Checks whether data and log files are placed on separate logical drives. As a best practice, placing the files on separate drives allows the I/O activity to occur at the same time for both the data and log files.

Database Auto Close
Checks whether the AUTO_CLOSE option is set to OFF. When AUTO_CLOSE is set to ON, this option can cause performance degradation on frequently accessed databases because of the increased overhead of opening and closing the database after each connection. AUTO_CLOSE also flushes the procedure cache after each connection.

Database Auto Shrink
Checks whether the AUTO_SHRINK database option is set to OFF. Because frequently shrinking and expanding a database can lead to fragmentation on the storage device.

Database Collation
Checks whether user-defined databases are defined by using a database collation that is the same as the collation for the master and model databases, which is a recommended best practice. Otherwise, collation conflicts can occur that might prevent code from executing.

Database Page Status
Checks for user databases that have the database status set to Suspect. The Database Engine marks a database as Suspect when it reads a database page that contains an 824 error. Error 824 indicates that a logical consistency error was detected during a read operation, and it frequently indicates data corruption caused by a faulty I/O subsystem component.

Database Page Verification
Checks whether the PAGE_VERIFY database option is set to CHECKSUM. This recommended best practice helps provide a high level of data-file integrity by forcing the Database Engine to calculate a checksum over the contents of the whole page and store the value in the page header when a page is written to disk. When the page is read from disk, the checksum is recomputed and compared to the checksum value that is stored in the page header.

File Growth For SQL Server 2000
Checks an instance of SQL Server 2000 for data files that are 1 gigabyte or larger and are set to autogrow by a percentage instead of a fixed size. As a recommended best practice, large databases should class=SpellE>autogrow by a fixed size. Otherwise, growing a data file by a percentage can cause performance problems with SQL Server because of progressively larger growth increments.

Guest Permissions
Checks whether the guest user has permission to access a user database. As a best practice, you should revoke the guest user permission to access a database if it is not required.

Last Successful Backup Date
Checks to ensure that a database has recent backups. Scheduling regular backups protects a database against data loss.

Public Not Granted Server Permissions
Checks whether the public server role has server permissions. Every login that is created on the server is a member of the public server role and will have server permissions.

Read-Only Database Recovery Model
Checks for read-only user databases that have recovery set to Full. As a best practice, these databases should use the Simple recovery model because they aren’t frequently updated.

SQL Server 32-Bit Affinity Mask Overlap
Checks whether the 32-bit instance of SQL Server has one or more processors that are assigned to be used with both the Affinity Mask and Affinity I/O Mask options. Enabling a CPU with both the affinity mask and the affinity I/O mask can slow performance by forcing the processor to be overused.

SQL Server 64-Bit Affinity Mask Overlap
Checks whether the 64-bit instance of SQL Server has one or more processors that are assigned to be used with both the Affinity Mask and Affinity I/O Mask options. Enabling a CPU with both the affinity mask and the affinity I/O mask can slow performance by forcing the processor to be overused.

SQL Server Affinity Mask
Checks whether the Affinity Mask option is set to 0. This is the default value, which dynamically controls CPU affinity. Using the default value is a recommended best practice.

SQL Server Blocked Process Threshold
Checks the Blocked Process Threshold option, and ensures it is set to 0 (disabled) or to a value higher than or equal to 5 (seconds). Setting the Blocked Process Threshold option to a value from 1 through 4 can cause the deadlock monitor to run constantly, and this state is desirable only when you are troubleshooting.

SQL Server Default Trace
Determine whether the Default Trace option is disabled. When this option is enabled, default tracing provides information about configuration and DDL changes to the SQL Server Database Engine.

SQL Server Dynamic Locks
Checks whether the Locks option is set to 0. This is the default value, which dynamically controls locks. Using the default value is a recommended best practice.

SQL Server Lightweight Pooling
Checks whether the Lightweight Pooling option is set to 0. This is the default value, which prevents SQL Server from using lightweight pooling. Using the default value is a recommended best practice.

SQL Server Login Mode
Checks the login security configuration to ensure Windows authentication is being used. Using Windows authentication is a recommended best practice because this mode uses the Kerberos security protocol, provides support for account lockout, and supports password expiration. For Windows Server 2003 and Windows Server 2008, Windows authentication also provides password policy enforcement in terms of complexity validation for strong passwords.

SQL Server Max Degree Of Parallelism
Checks whether the Max Degree Of Parallelism (MAXDOP) option is set to a value greater than 8. Because setting this option to a value larger than 8 often causes unwanted resource consumption and performance degradation, you’ll usually want to reduce the value to 8 or less.

SQL Server Max Worker Threads For SQL Server 2005 And Above
Checks the Max Worker Threads Server option for potentially incorrect settings. Setting the Max Worker Threads option to a small value might prevent enough threads from servicing incoming client requests in a timely manner. Setting the option to a large value can waste address space, because each active thread consumes 512 KB on 32-bit servers and up to 4 MB on 64-bit servers. For instances of SQL Server 2005 and SQL Server 2008, you should set this option to 0, which allows SQL Server to automatically determine the correct number of active worker threads based on user requests.

SQL Server Network Packet Size
Determines whether the network packet size of any logged-in user is more than 8060 bytes. As a best practice, the network packet size should not exceed 8060 bytes. Otherwise, SQL Server performs different memory allocation operations, and this can cause an increase in the virtual address space that is not reserved for the buffer pool.

SQL Server Password Expiration
Checks whether password expiration is enabled for each SQL Server login. As a best practice, you should enable password expiration for all SQL Server logins using ALTER LOGIN. Additionally, if SQL Server authentication is not required in your environment, you should enable only Windows authentication.

SQL Server Password Policy
Checks whether the Enforce Password policy is enabled for each SQL Server login. As a best practice, you should enable the Enforce Password policy for all the SQL Server logins by using ALTER LOGIN.

SQL Server System Tables Updatable
Checks whether system tables for SQL Server 2000 can be updated. As a best practice, you shouldn’t allow updates to system tables.

Symmetric Key Encryption For User Databases
Checks whether encryption keys that have a length of less than 128 bytes do not use the RC2 or RC4 encryption algorithm. As a best practice, you should use AES 128 bit or larger to create symmetric keys for data encryption. If AES is not supported by your operating system, you should use 3DES encryption.

Symmetric Key For master Database
Checks for user-created symmetric keys in the master database.

Symmetric Key For System Databases
Checks for user-created symmetric keys in the msdb, model, and tempdb databases. As a best practice, you should not create symmetric keys in the system databases.

Trustworthy Database
Checks whether the dbo role for a database is assigned to the sysadmin fixed server role and the database has its trustworthy bit set to ON. As a best practice, you should turn off the trustworthy bit or revoke sysadmin permissions from the dbo database role. Otherwise, a privileged database user can elevate privileges to the sysadmin role and then create and run unsafe assemblies that could compromise the system.

Windows Event Log Cluster Disk Resource Corruption Error
Checks the system event log for EventId 1066. This error can occur when a device is malfunctioning and also as a result of SCSI host adapter configuration issues.

Windows Event Log Device Driver Control Error
Checks the system event log for EventId 11. This error can be caused by a corrupt device driver, a hardware problem, faulty cabling, or connectivity issues.

Windows Event Log Device Not Ready Error
Checks the system event log for EventId 15. This error can be caused by SCSI host adapter configuration issues or related problems.

Windows Event Log Disk Defragmentation
Checks the system event log for EventId 55. This error occurs when the Disk Defragmenter tool cannot move a particular data element and as a result Chkdsk.exe is scheduled to run.

Windows Event Log Failed I_O Request Error
Checks the system event log for EventId 50. This error is caused by a failed I/O request.

Windows Event Log I_O Delay Warning
Checks the event log for error message 833. This message indicates that SQL Server has issued a read or write request from disk, and that the request has taken longer than 15 seconds to return. You can troubleshoot this error by examining the system event log for hardware-related error messages. Look also for hardware-specific logs.

Windows Event Log I_O Error During Hard Page Fault Error
Checks the system event log for EventId 51. This error is caused by an error during a hard page fault.

Windows Event Log Read Retry Error
Checks the event log for SQL Server error message 825. This message indicates that SQL Server was unable to read data from the disk on the first try. You’ll need to check the disks, disk controllers, array cards, and disk drivers.

Windows Event Log Storage System I_O Timeout Error
Checks the system event log for EventId 9. This message indicates that an I/O time-out has occurred in the storage system.

Windows Event Log System Failure Error
Checks for the system event log for EventId 6008. This event indicates an unexpected system shutdown.

Next topic will be How to configure Policay Based management in SQL Server 2008 with illustration.