CLR Stored Procedures - handling security on SQL Server side
24 July 08 01:52 AM | SQL Master | 2 Comments   
Ok this is not new to say you can write stored procedures in any language to manage them in SQL Server, as 2005 version has started this CLR integration functionality that is exposed in an assembly called system.data.dll, which is part of the .NET Framework. So think about code access security in addition to managing security privileges for the user on database side.
 
CLR supports the access security mechanism which is based on the assumption that the runtime can host both fully trusted and partially trusted code. This means CLR code security is wrapped by a managed API that require the corresponding permission before allowing access to the resource. BOL documentation refers that ....set of code access security permissions that are granted to managed code when running inside SQL Server is the intersection of the set of permissions granted by the above three policy levels. Even if SQL Server grants a set of permissions to an assembly loaded in SQL Server, the eventual set of permissions given to user code may be restricted further by the user and machine-level policies.
 
As the CLR security mechanism can be managed on granting permissions to assemblies by the SQL Server host policy level which is determined by the permission set specified when creating the assembly having 3 levels of permissions SAFE, EXTERNAL_ACCESS & UNSAFE. Reverting back to what SQL documentation states that:
 

Only internal computation and local data access are allowed. SAFE is the most restrictive permission set. Code executed by an assembly with SAFE permissions cannot access external system resources such as files, the network, environment variables, or the registry.

EXTERNAL_ACCESS assemblies have the same permissions as SAFE assemblies, with the additional ability to access external system resources such as files, networks, environmental variables, and the registry. 

UNSAFE allows assemblies unrestricted access to resources, both within and outside SQL Server. Code executing from within an UNSAFE assembly can also call unmanaged code.

 So what you need is another tool to verify the code execution on the security aspects, this is where the .NET Framework tool such as 'PEVerify Tool' (Peverify.exe)  comes into picture. This tool helps developers who generate Microsoft intermediate language (MSIL) to determine whether their MSIL code and associated metadata meet type safety requirements. You need to be aware about compilers and other script engine developrs that  may generate verifiably type-safe code only if you avoid using certain language constructs. If, as a developer, you are using such a compiler, you may want to verify that you have not compromised the type safety of your code. In this situation, you can run the PEVerify tool on your files to check the MSIL and metadata.

Technet has got further reference on this tool stating that this is a comprehensive tool where the DBAs can rely on security aspects having the privilege of verification checks based on dataflow analysis plus a list of several hundred rules on valid metadata. Further information on checks and detailed information can be found from Windows SDK by looking at the "Metadata Validation Specification" and the "MSIL Instruction Set Specification" sections.

The ITPROs should be aware of CLR integration when you want to develop SQL CLR solutions or to decide whether to use it or not. Moreover it is more important for a DBA to how to lock down security on other side of ranch and ensure the stored procedures development will not compromise the security or using other objects in .NET for SQL Server. So the Developers & DBAs must have following list of concepts in this regard:

  • The concepts and architecture of SQL CLR
  • Uses of .NET namespaces in SQL Server programming tasks
  • How to develop and benchmark routines in T-SQL and .NET to determine when CLR-based solutions are advantageous
  • How to replace extended stored procedures using SQL CLR stored procedures
  • How to use SQL CLR objects in external applications
  • How to restrict and secure SQL CLR object capabilities
  • Processes and procedures for deploying SQL CLR objects

Further references on the subject you can review to Choosing between TSQL and CLR, your choice in addition to Writing Verifiably Type-Safe Code
and Type Safety and Security 

Microsoft Security Bulletin Summary for July 2008 - what is it now?
09 July 08 01:07 AM | SQL Master | 2 Comments   

I believe it has been a while that we have seen the security hotfix from Microsoft Security team on SQL Server (alone). The latest security bulletin has announced important security patches that are related to SQL Server in addition to Windows operating system. They quote that "...With the release of the bulletins for July 2008, this bulletin summary replaces the bulletin advance notification originally issued July 3, 2008. For more information about the bulletin advance notification service, see Microsoft Security Bulletin Advance Notification....".

The Severity rating has been given as important which means you have to test the referred hotfix from this KBA Vulnerabilities in Microsoft SQL Server Could Allow Elevation of Privilege (941203) link. As that goes in specific to SQL Server the following are for Windows alone: Vulnerabilities in DNS Could Allow Spoofing (953230), Vulnerability in Windows Explorer Could Allow Remote Code Execution (950582) & Vulnerabilities in Outlook Web Access for Exchange Server Could Allow Elevation of Privilege (953747) links.

So what is your practice in deploying such security hotfixes within your environment?

Don't forget to test the patches before deploying them on to the production, that might cause unprecedented downtime and with prior testing you will be able to catch the issues in hand. Also it is recommended to deploy Baseline Security Analyzer tool MBSA that  allows administrators to scan local and remote systems for missing security updates as well as common security misconfigurations.

If you are new to this type of alerts or patches then you must visit the Security Guidance for Update Management link that provides additional information about Microsoft’s best-practice recommendations for applying security updates.

 

SQL Server: PERFMON counters to identify server utilization data
18 June 08 05:21 AM | satyaskj | 2 Comments   

Recently I have been involved to carry over an assesment of server utilization on the SQL estate farm (nearly 150+) instances, as it stands it is not an easy job to obtain the results when you have no influence on accessing required information on a shared platform. So in order to get the results quickly as you might guess using PERFMON *(SYSMON) tool is best to go with for initial assesment. As it defines within the SYSMON tool getting Collection of counter logs  with Performance Logs and Alerts option instantly we created set of jobs against business importance  servers that are having multiple SQL Server instances.

I was told that there may be third party tools available from the vendor such as Quest or IDERA with a built-in data-collection model process that can configured for automated data collection against multiple servers across multiple domains, and also Systems Management Server (SMS) from Microsoft also helps to some extent. Neither of these tools were available at our end so the obvious choice is to go with manual precision of using PERFMON tool.

I would like to share the required collection of counters that will be useful to obtain server utilization information if you have similar exercise or process to obtain.

 

 

 

Object

Counter

Processor

%Processor Time

Processor Queue Length

Memory

Available Bytes

Page Faults/Sec

Physical disk

% Disk Time

Avg. Disk sec/Read

Avg. Disk sec/Write

Current Disk Queue Length

Disk Reads/sec

Disk Writes/sec

Avg. Disk Queue Length

Server

Server Sessions

SQL Server: cache manager

Cache Hit Ratio

SQL Server: databases

Transactions/Sec

SQL Server: general statistics

User Connections

System

File Read Operations/sec

File Write Operations/sec

Processor Queue Length

I hope this will help others too.

SQL Server - Precision Performance techniques using RML Utilities
09 June 08 05:50 AM | SQL Master | 2 Comments   

As a DBA, you probably often find yourself striving or struggling to improve the performance of SQL Server instance queries (might be smaller or complex ones). By default in order to get further analysis on the system's performance you need to perform server side trace along with SYSMON (PERFMON) trace collection, this is important in trying to discover the queries or batches that take too long to run, perform too many I/O requests, or use too many CPU cycles.

By default the users will find using PROFILER than running Script based trace on server side or even with  SQL Server traces in Profiler and sort them by different columns (e.g., duration, cpu, reads, writes), this process tends to be time-consuming and doesn't provide aggregated data. Alternatively, you could load the traces into SQL Server tables and run aggregate queries against these tables to analyze the worst-performing queries in the trace. The Read80Trace utility simplifies trace analysis by automatically creating an analysis database for the trace file(s) you provide. It also generates a graphical HTML output file that contains detailed information about the load captured in the trace files.  

In continuation with the blog SQL Server troubleshooting tools PSSDiag, SQLDiag, SQLNexus, RML Utilities and ReadTrace: which one to choose? here about Precision Performance objective driven by Microsoft CAT team about RML utilities I would like to refer this further explanation blog post from SQLCAT blogs.

More from this Precision Performance for Microsoft SQL Server using RML Utilities 9.0 post.

 

 

 

SQL Injection attacks - don't forget to visit guidance information from Microsoft
31 May 08 01:59 PM | SQL Master | 2 Comments   

One of the biggest threats in IT industry & Database world is unprecedented attacks aka most commonly termed as 'SQL injection'.

There is no doubt that biggest database vendors, one of them as Microsoft so far providing recommendations regarding security-related configuration settings since the good & bad times of SQL Server version 2000, not in particular to point DBA or Developer and whole as in Application database, remember 'Slammer Worm'!. Here it is best to refer the ignored 'best' practices (bad)  that are seen at most of the deployments by leaving the blank password for any application connectivity or very common used words such as 'password' or so. In this fashion any generic installation of SQL Server and can be relatively easily configured on the server, database, or database object level and obvious attempt on access to data is provided via client applications, which increases the range of potential vulnerabilities and places an equal share of responsibility for data security on software developers, where I feel most of users must be educated/trained on security aspects.  

So to know more about SQL injection attacks and vulnerabilities within your system I'm providing few best examples and explanation, such as SQL Injection attacks post by Buck Woody &  SQLInjection-Attachs-by-example blog posts.

To close the topic I would like to highlight the importance of monitoring the information (small or big) that might be revealed via error messages resulting from executing malformed SQL statements. It is like leaving your house key to the door lock when you are supposed to secure it when you are going away!

SQL Server 2005 Connectivity, Security policies & Network protocols: simple practice to follow, after installation?
23 May 08 01:44 AM | SQL Master | 2 Comments   

Secured by default, secured by design is the buzzword and catchy stuff for any Enterprise IT administrators. Then it comes about standards and policies to follow such as ISO , with the recent threats (last 10 years) and vulnerabilities within IT world it is most important factor you need to follow as per the compliance standards that are deemed as industry proven, Common Criteria. This 'international' standard has been ratified in the year 1999 that was designed by a group of nations to improve the availability of security-enhanced IT systems, not only standards documentation there is a process in place to evaluate your IT systems on periodic basis in terms of security.

 

On such terms SQL Server 2005 comes as 'trustworthy' whereby the general policy of 'off by default' or 'enable only when needed' has been implemented by design, that means connectivity-policies/services such as Service Broker, HTTP or Database Mirroring endpoints, XP_CMDSHELL on surface area are disabled by default. Also the network protocols such as TCP/IP, Named pipes are disabled too with an exception to Shared Memory is available/enabled by default. Also the VIA endpoint is disable in addition to discontinuation support for some network protocols that were available with earlier versions of SQL Server, including IPX/SPX, Appletalk, and Banyon Vines.  

 

Dedicated Administrator Connection (DAC) that is given secret key to DBAs to use when every other connectivity is locked out on SQL instance will also be availabile to use locally 'by default', that means you need to logon remotely to use it and anyhow you can enable it to use it remotely too. To know whether DAC is enabled or not you can refer to SQL Server 2005 detect DAC session with TSQL post here and use the feature responsibly! Be aware that DAC is not available to use in SQL Express edition unless you start that instance with a trace flag 7806.

 

As referred above permission to database endpoints requires CONNECT permission, as it is also disable by default that will restrict access paths and blocks some known attack vectors. It is a best practice to enable only those protocols that are needed. For example, if TCP/IP is sufficient, there is no need to enable the Named Pipes protocol. As the documentation refers to use Surface Area Configuration which is introduced in SQL Server 2005 has been taken away in upcoming 2008 version (SQL Server 2008: Administer multiple servers by designating configuration servers), so you need to get used to perform such endpoint administration using DDL statements and using SQL Server Configuration Manager that will give you a simplified user interface for enabling or disabling client protocols for a SQL Server instance. This GUI provides more granular configuration of server protocols. With Configuration Manager, you can:

·         Choose a certificate for SSL encryption.

·         Allow only encryption connections from clients.

·         Hide an instance of SQL Server from the server enumeration APIs.

·         Enable and disable TCP/IP, Shared Memory, Named Pipes, and VIA protocols.

·         Configure the name of the pipe each instance of SQL Server will use.

·         Configure a TCP/IP port number that each instance listens on for TCP/IP connections.

·         Choose whether to use TCP/IP dynamic port assignment for named instances.

 

So to talk about simple and better practices you need to tighten the SQL Server environment with few policies, specific recommendation for relevant needs. In summary I have implemented the following tasks in order to ensure the maximum security practices are obtained when a new platform is designed and not leaving existing platforms too:

  • Implementing Service Packs & Hotfixes  for SQL Server and Windows operating system, in addition to this current flow of cumulative update packages for SQL Server has divided the implementation to granular level. Which means you need to apply only if a relevant bug is defined on those KB articles for CU packages.
  • Do not forget to test and implement upto date service packs (atleast) on both SQL & Windows, leaving behind the required Cumulative Update packages to roll on. WIthin a shared environment you have to be more careful to test/verify all the applications that are connected to such mulitple-database server instance.
  • By default it is best to use Windows Authentication, which is a more secure choice; however, if mixed mode authentication is required, leverage complex passwords and the new SQL Server 2005 password and lockout policies to further bolster security.
  • If possible disable or rename the SA account on SQL Server. As it is a general practice by the users to use even for a simple set of DDL actions, in this case it is better to use Windows logins that are mapped to SA schema for day-to-day administration, logging on to the server remotely, or having applications use it to connect to SQL.
  • Create a role-based security policy for all the databases (if possible), this way you can control the granular level of security to the databases.
  • Once SQL Server 2005 is installed, run the SQL Server Configuration Manager and SQL Server Surface Area Configuration tools to disable unnecessary features and services.
  • Install only required components when installing SQL Server. Do not select to install Analysis Services, Reporting Services or Notification Services if your application has no use of these services.
  • Better to install Integration Services (SSIS) that is a common service to deploy database ETL actions. 
  • Whenever possible it is better to deploy the Microsoft Baseline Security Analyzer (MBSA) to asses the server's security and SQL Server 2005 Best Practice Analyzer for SQL server instances.
  • Either hide the instance or disable the SQL Server Browser service for production SQL Servers running mission-critical databases.
  • Change the default ports associated with the SQL Server installation to put off hackers from port scanning the server.
  • Enable a firewall to filter unnecessary and unknown traffic, ensure to allow exceptions for the ports & programs used for SQL Server.
  • At the very least, set security auditing to failed login attempts; otherwise, both failed and successful logins should be captured and monitored.
  • Use the IIS Lockdown and URLScan tools to harden IIS.

Best practices for network connectivity

·         Limit the network protocols supported.

·         Do not enable network protocols unless they are needed.

·         Do not expose a server that is running  SQL Server to the public Internet.

·         Configure named instances of SQL Server to use specific port assignments for TCP/IP rather than dynamic ports.

·         If you must support SQL logins, install an SSL certificate from a trusted certificate authority rather than using SQL Server 2005 self-signed certificates.

·         Use "allow only encrypted connections" only if needed for end-to-end encryption of sensitive sessions.

·         Grant CONNECT permission only on endpoints to logins that need to use them. Explicitly deny CONNECT permission to endpoints that are not needed by users or groups.

 

By default it is better to visit the SQL Servers on Production environment with a periodical assesment of security policies and whenever a new hotfix or Service pack is released don't forget to test it thorougly to apply.

SQL Server Performance issues with Fragmentation and heavy usage of TEMPDB?
15 May 08 01:59 AM | SQL Master | 2 Comments   

Whenever a performance issue occurs on the SQL Server database best option for diagnosing and troubleshooting common problems by using publicly available tools such as Profiler, System Monitor (Perfmon), and Dynamic Management Views (DMVs) in SQL Server 2005 (onwards).

What to detect?

  • Use SYSMON to detect excessive compiles and recompiles. Technical documentation refers that for this kind of problem use SQL Statistics object that provides counters to monitor compilation and the type of requests that are sent to an instance of SQL Server. The general trend will be the ratio of SQL Recompilations/sec to Batch Requests/sec should be low unless users are submitting ad hoc queries.

What if high value of compiles & recompiles are found?

  • If the PerfMon counters indicate a high number of recompiles, then the problem is due to recompilation of stored procedures and also underlying defragmentation of indexes (this will be discussed below). It is obvious that you have seen the recompiles are contributing to the high CPU consumed by SQL Server. So using Profiler trace to find the stored procedures that were being recompiled, this helps to obtain information along with the reason for the recompilation.
  • Further one of the Microsoft technical document gives the following TSQL to see all recompile events that were capture in the trace:

select 
    spid,
    StartTime,
    Textdata,
    EventSubclass,
    ObjectID,
    DatabaseID,
    SQLHandle 
from 
    fn_trace_gettable ( 'e:\recompiletrace.trc' , 1)
where 
    EventClass in(37,75,166)

Going forward you can take help of other counters in SYSMOn such as Access Methods object counters that will to monitor how the logical data within the database is accessed. Additionally you could also find the physical access to the database pages on disk is monitored using the Buffer Manager counters. With this monitoring methods in place can help you to determine whether query performance can be improved by adding or modifying indexes, adding or moving partitions, adding files or file groups, defragmenting indexes, or by rewriting queries. So to find out the overall usage of amount of data, indexes and free space within the database you could make use of Access Methods counters. This is where the data volume and fragmentation information can be obtained to see whether they are contributing to the performance issues in addition to excessive recompilations above, by default excessive index fragmentation can impair performance.  

So on the subject to find out the performance issues with a quick execution of steps you could make use of DMVs and for more detailed information about the data volume usage, index fragmentation you can execute the following ones:

  • sys.dm_db_index_operational_stats
  • sys.dm_db_index_physical_stats
  • sys.dm_db_partition_stats
  • sys.dm_db_index_usage_stats

Also the usage of TEMPDB is high from SQL Server 2005 onwards, that is explained more from these Working with tempdb in SQL Server 2005 & Optimizing tempdb Performance Technet articles in addition to viewing the following DMVs results:

  • sys.dm_db_file_space_usage
  • sys.dm_db_task_space_usage
  • sys.dm_db_session_space_usage

That will be starting point for you to analyze the performance issue for further assessment.

 

SQL Server - Kill a KILLED/ROLLBACK status process without restarting Server or SQL services?
06 May 08 01:02 AM | SQL Master | 2 Comments   

This may be the typical situation within your database environment where the you might have killed a SPID (Process) that has been running  for long time, without knowing the ROLLBACK operations for such processes.

Say if you are executing a stored procedure which is built with a transactional based statements, by default the relational engine has the ability to control transactions mainly when you have specified a transaction starts and ends. In addition to that it must also be able to correctly handle errors that terminate a transaction before it completes, as in this case the transactions are managed at the connection level. Going back to the basics, say when a transaction is started on a connection all TSQL statements executed on that connection are part of the transaction until the transaction ends. But when you have multiple active results set such as MARS sessions, then that TSQL explicit or implicit transaction becomes a batch-scoped transaction that is managed at the batch level. Once the batch execution is completed and if that batch-scope transaction is not committed or rolled back, then it is automatically rolled back by SQL Server.

Also these transaction modes are managed at the connection level. If one connection changes from one transaction mode to another, it has no effect on the transaction modes of any other connection. For further error handling within that nested transactions level you can effectively include the TSQL TRY…CATCH construct, in this case Error Handling in SQL Server – a Background is the favourite among the SQL world, refer to it to solve your relevant issues. By default within those TSQL statements or stored procedure execution if you haven't specified the savepoint_name or transaction_name  within your ROLLBACK statement then it will roll back all the statements that were executed within the outermost BEGIN TRANSACTIOn statement.

Coming to the subject of killing a long running process, before doing that ensure to check what that process is executing by uisng DBCC INPUTBUFFER and if you don't get complete information of that process, then refer to Dig-Further_DBCC_INPUTBUFFER  process here. Also ensure to check whether any changes happening on CPU & IO against that SPID when you execute SP_WHO2 to get information. If it is compulsory to kill that SPID then ensure to execute KILL spid WITH STATUSONLY to see the rollback progress. Say if you have execute the above specified statement then you will see the information as follows :

SPID xx: transaction rollback in progress. Estimated rollback completion: 100%. Estimated time remaining: 0 seconds.

So are you sure it will finish within seconds, well it will not be. You should consider the factors such as hardware, contention, locks, application/database design etc  and it is not possible to say straightly about the time it will take to complete the ROLLBACK. Further to that the only way to get rough timings for deletions is to benchmark your system. Due to the fact that there are no 'behind the door' command to stop the long running rollback unless you restart the SQL Server services or rebooting the server itself (which is a common attempt by the users) it will only cause the more time to recover when the services come back to online, based on the rolled back transactions to recover. As by default the rollback time will minimally be equal or more than to the length of time spent on the insert/update activity that occurred. In the most cases the restart of services or server will get the solution to the problem, but in case if you have killed a process that is running DBCC DBREINDEX or CHECKDB then you will be at risk to lose the consistency for that database.

Bear in mind that as the rollback process will also take same time as that query execution or even more than that due to the underlying transaction log process that needs to be completed. It is a general assumption by the users that if you use SIMPLE recovery model on database it will take care the log sizes, well it is not. It will truncate the log at every checkpoint but it will not when the rollback transaction has to fillup 60% of the current log size then it will wait to increase the Transaction log file for that database which will have slow process affect to get this process complete in addition to the current processes that are executing, hence the ROLLBACK process is not changing or you might see the blocking too.

So in order to kill the ROLLBACK status process without restarting SQL Server services or reboot the server the only way is to find the kill the KPID of that SPID by running :

--SQL 2005 

select * from sys.sysprocesses

or

--SQL 2000

select * from sysprocesses

Within the results pane you will see the KPID number, logon to the server remotly then open Task Manager to find this KPID number. Once you are satisifed then you can proceed to kill process from Task Manager. Unless you are sure about that SPID and ROLLBACK process  do not attempt to do this procedure within your production SQL Server instance as it may have further problems to the SQL Server availability.

 

SQL Server 2005 Login Security - CHECK_POLICY and CHECK_EXPIRATION setting, how it affects the password policy?
30 April 08 01:53 AM | SQL Master | 2 Comments   

Adding password complexity and password expiration to SQL Server logins is one of best feature I quote for SQL Server version 2005 onwards, similarly such password complexity policies are designed to deter brute force attacks by increasing the number of possible passwords. When password complexity policy is enforced and password expiration policies are used to manage the lifespan of a password.

In any of the above cases the SQL Server engine runs the check to enforce password expiration policy and check in order to ensure the users are reminded to change old passwords, and accounts that have expired passwords are disabled. Similar to this you may get the error mentioned below:

Property IsLocked is not available for Login '[x]'. This property may not exist for this object, or may not be retrievable due to insufficient access rights. (Microsoft.SqlServer.Smo) 
 

Previously I blogged here to solve this problem over here -  LoginPropertyLocked and this issue occured on our side when a SQL instance is  installed with Windows Authentication and then switch to SQL Server Authentication, sometimes it  may not come into affect unless the SQL Server services are restarted. Further questions can arise such as will this happen on the instances which is installed with SQL Server Authentication or any chance in performing SQL Server installer to have any settings to turn off the check password policy, the answer is not quite easy. Say if you need to disable the check password policy on that SQL instance then you have to use below TSQL:

alter login sa [X] with password = 'yourpwd' unlock, check_policy = off, check_expiration = off

Further you have to ensure to disable password policy when using sp_addlogin, as this is deprecated from SQL 2005 onwards and you should continue to use CREATE LOGIN instead, as sp_addlogin statement. Also the Policy Enforcement can  be configured separately for each SQL Server login. Use ALTER LOGIN to configure the password policy options of a SQL Server login. When they are ON then relational engine sets the CHECK_EXPIRATION is also set to ON unless it is explicitly set to OFF, and to the  password history is initialized with the value of the current password hash. Whereas when the  CHECK_POLICY is changed to OFF, then CHECK_EXPIRATION is also set to OFF having the password history is cleared too! So ensure to use this sensibly within your Production server instance.

In few cases when SQL Server is running on Windows 2000, setting CHECK_POLICY = ON will prevent the creation of passwords when used NULL or empty. Also affects if you try to create a SQL login with the same as name of computer or login. So in the case of using the hashed password when creating the login, the password policy cannot be checked for complexity on such password, as the system cannot get the original password from the system and only this is available in hash, but the gain is you this will come into affect since that point of creation, that means when the user triesto change the password during next attempt or time. I recommend to refer to http://blogs.msdn.com/lcris/archive/2007/04/30/sql-server-2005-about-login-password-hashes.aspx blog post for such information.

Further Books online confirms that within  Windows Server 2003 a known issue that might prevent the bad password count from being reset after LockoutThreshold has been reached. This might cause an immediate lockout on subsequent failed login attempts. You can manually reset the bad password count by briefly setting CHECK_POLICY = OFF, followed by CHECK_POLICY = ON. During the recent usergroup meeting one user asked that is there a method in SQL 2005 to globally disable the CHECK_POLICY option? The answer is CHECK_POLICY cannot be disabled globally. You will have to do it at the login-level only that means when a single CREATE LOGIN statement is used, as you cannot use that in a transaction. Also I have seen such issues when you are using a web based application within ASP.NET stating the sql login is failed though it has relevant permissions set,  and in this case I suggest to refer the notes from BOL (again):

MUST_CHANGE
Applies to SQL Server logins only. If this option is included, SQL Server will prompt the user for a new password the first time the new login is used.

CHECK_EXPIRATION = { ON | OFF }
Applies to SQL Server logins only. Specifies whether password expiration policy should be enforced on this login. The default value is OFF.

If MUST_CHANGE is specified, CHECK_EXPIRATION and CHECK_POLICY must be set to ON. Otherwise, the statement will fail.

A combination of CHECK_POLICY = OFF and CHECK_EXPIRATION = ON is not supported.

When CHECK_POLICY is set to OFF, lockout_time is reset and CHECK_EXPIRATION is set to OFF.


CHECK_POLICY = { ON | OFF }
Applies to SQL Server logins only. Specifies that the Windows password policies of the computer on which SQL Server is running should be enforced on this login. The default value is ON.

 

SQL Server - Have you observed DBCC SHRINKFILE operation performance, on huge databases?
25 April 08 01:30 AM | SQL Master | 2 Comments   

In general it is not a best practice to perform SHRINK database operation on a production server, atleast regularly!

Sometimes it may be compulsory to keep them sized in order to ensure the disk storage is not compromised for any sudden changes to databases ETL processes, coming to the point by design the DBCC SHRINKFILE operation is a single-threaded operation that means you cannot define or configure the server to use multiple CPUs or a dedicated CPU. So troubleshooting the performance problems on a database system is very tricky, more important is where to look for a problem and for instance it is frustating to see why system reacts in such a bad way even for a simple query execution and this is where you need to look at how CPU, Memory & disks are performing during this operation

Coming to the subject the referred DBCC operation needs to perform the exercise of moving database pages from tail of the file to the beginning in order on the data file, with one page at a time though. SO you need to be careful to select this operation on a huge database as it will tend get the server down to its knees for a single simple-query execution, also the SHRINKFILE operation often make it defragmentation from bad to worse and in many situations I have seen this increases the file logical fragmentation whereby you will see huge difference in performance to produce few hundreds of rows result set.

If you see such performance issue then look at from a high level, there are two paths to identifying CPU performance problems. The first is reviewing the system's hardware performance, an exercise that helps determine where to look when you head down the second path, reviewing the server's query efficiency. This second path is usually more effective in identifying SQL Server performance issues. Unless you know exactly where your query performance issues lie, however, you should always start with a system performance evaluation that will lead to go on both of these routes. On such SQL Server instances where the relational engine actually handles its own extremely efficient queuing and threading to the Operating Sysstem and having CPUs with hyper-threading is a common scenario, this will have the affect to overload the physical CPUs on systems with already high CPU utilization. This is where the threads operation converted as queues from SQL Server with multiple requests to perform work on multiple schedulers. This is where the Operating System struggles to cope up to switch the context of the threads back and forth on the physical processors to satisfy the requests that are being made even if the two logical processors are sitting on top of the same physical processor.

Taking back to the SHRINKFILE operation on the database table(s) with a clustered index(es) on a huge table (rows) then you will see much degraded performance because of the heaps and those heaps have many non-clustered indexes, where it is different to the  clustered index situation. In this case the SHRINK operation of moving the pages having with IMAGE data or Large Object Blob will be too slow, as it has to read the data from each page to arrange. Further the most content of an index/table resides at the end of the file, you can rebuild the indexes to move them to the front end of the file. Also bear in mind to keep a close watch of Transaction log space on the databases in addition to the TEMPDB which is used extensively in SQL Server 2005 version.

So by the end you should ensure to schedule the SHRINK operation during the less traffic hours and when server consists with multipe CPUs to take advantage of performance to finish the operation in timely manner.

SQL Server latch waits - index contention & performance issues how DMVs can help you to get information?
17 April 08 03:06 AM | SQL Master | 2 Comments   

What kind of performance issues you see on day-to-day basis within your environment?

The following elements are important factors that can add fuel to the fire (problem):

Faulty hardware

Hardware that is not configured correctly

Firmware settings

Filter drivers

Compression

Bugs

Other conditions in the I/O path

I/O is important factor to consider when it comes to the performance issues, such as blocking, locking and slow response time that will cause stretching of resources on the server. In this case using SYSMON and other monitoring tools will get you the latch contention and timeouts to the application. So what are these latches and why they are important when it comes to performance, also important for indexes.

A latch is a lightweight version of a lock, in generate they do not hinder performance or concurrency and in any case if you are having performance issues then using SYSMON for latch wait timeouts to determine is inital stage to monitor. By default the latch wait time is a good indication for your hardware disks performance, as it will tell about a process that is taking how long to access data, read and write from the disk. For instance if a latch wait time of 1.3 seconds is telling you that your disk subsystem is a bottleneck or it could be a poor design of the disk subsystem, or from table scans or from choosing the improper RAID type or from just a lack of spindles to achive the IO that SQL is asking for.

Using SQL Server 2005 the DMVs can be handy to get more information on system internals behaviour, so for the Latch Wait Times these relevant DMVs are as follows, such as dm_exec_requests that will get you wait type and wait resources, dm_os_latch_stats for wait counts on BUF and nonbuf latches. Also the dm_wait_stats will get you granular information on latches, further if you have disk related issues then using dm_io_pending_io_requests DMV can get you how the snapshot IO requests are performing with additional information by using dm_io_virtual_file_stats to get per file.

Within SQL Server 2000 (SP4) latch waits are more often visible within blocking column of sysprocesses table, where in IO related issues you will see more on EX_LATCH and SH_LATCH for acquired & waiting stats of blocking. But for SQL Server 2005 (using DMVs) or get blocking information for the wait PAGEIOLATCH_SH will not get your blocking information when it occurs. Similarly for EX_LATCH & SH_LATCH wait types the contents of memory buffer that holds the database is trying to read a page in memory that hasn't been pulled the complete information yet. Also the latching issues occurs when your TEMPDB is not located within proper RAID configuration, as it is a special database in the sense that it often the target of frequent drop/create tables. This requires frequent allocation/deallocation which results in hot spots on pages like SGAM and PFS. Splitting tempdb into multiple files is common technique to minimize this contention and also avoid (whereever necessary) using the caching of tempdb objects in 2005 to help in reducing  contention on system table pages.

So how to reduce the contention, using the methods of creating multiple data files and avoiding AUTOGROW and SHRINK the TEMPDB data file. Not only the latching issues there are other wait types you need to monitor when you have a problem with slow response, they are: WRITELOG, CXPACKET, RESOURCE_SEMAPHORE_QUERY_COMPILE & RUNNABLE status that are occuring frequently or showing for longer time when you are monitoring the user connections against a database.  Not only that when you observer the high average row lock or latch waits, then what it says is the average row lock or latch waits are computed by dividing lock and latch wait milliseconds (ms) by lock and latch waits. The average lock wait ms computed from sys.dm_db_index_operational_stats represents the average time for each block. So when you see high number of deadlock occurrence then use the  Profiler “Graphical Deadlock” under Locks event to identify the statements involved in the deadlock (SQL 2005). Not only hardware related sometimes network latching also causes the issues, such as high network latency coupled with an application that incurs many round trips to the database

So to know more about these contention and information on I/O that will need to fine tune, refer to SQL2005-IOBasics whitepaper, SQL Server performance monitoring requirement and specifications, heard about baseline and benchmarking?  and methods of Identify and troubleshoot slow running queries in SQL Server blog posts here.


 

SQL Server problem: Excessive paging and memory bottlenecks
16 April 08 12:02 AM | SQL Master | 2 Comments   

Paging and Memory bottlenecks are quite common when a performance problem strikes on your SQL Server. As we discussed here previously and relevant blog posts below talks about them:

Paging and Available Memory for Operating sysem, what you need to know? 

SQL Server Memory - what's your method on Configuration and Troubleshooting Issues

Using PERFMON to get memory counters, what you need to check?

By default, SQL Server changes its memory requirements dynamically, on the basis of available system resources. If SQL Server needs more memory, it queries the operating system to determine whether free physical memory is available and uses the available memory. If SQL Server does not need the memory currently allocated to it, it releases the memory to the operating system. These are few common memory issues that occurs and need to troubleshoot them, page file is more important as it links with RAM to prevent excessive paging, the aim should not be to try to prevent paging activity completely.  In this case page faults will add more fuel to the problem, soft and hard page faults occurs on the server. A page fault occurs when a process requests a page in memory and the system cannot find the page at the requested location.  If the requested page is actually elsewhere in memory, then the fault is a soft page fault.  If the page has to be retrieved from the disk, then a hard fault occurs.  Most systems can handle soft page faults with no issues. 

However, if there are lots of hard page faults you may experience delays.  The additional disk I/O resulting from constantly paging to disk can interfere with applications that are trying to access data stored on the same disk as the page file.  Although high page faults on a system is a fairly straightforward issue, it requires some extensive data gathering and analysis in SYSMON, the important counters are Memory: pages/sec, Page Reads /sec & Available Bytes and let us see each of them :

If the Pages / sec multiplied by 4,000 (the 4k page size) is greater than 70% of the total number of Logical Disk Bytes / sec to the disk(s) where the page file is located on a consistent basis then you should investigate.  Then for Page Reads/sec which should be for for sustained values, so if the value is consistently greater than 50% of the total number of Logical Disk operations to the disk where the page file resides, then there is an inordinate amount of paging taking place to resolve hard faults. Then it comes to Available Bytes and when you see if it falls below 5 % of RAM that is installed then you should consider the type of service & application running at that time.

Such issues with paging talks more to the disk where the changes are written to the disk, that there will be page write operations occurring.  As the value of Available Bytes decreases, the number of hard Page Faults will normally increase.  The total number of Pages /sec that can be sustained by the system is a function of the disk bandwidth.  This does however mean that there is no simple number to determine whether or not the disks are saturated.  Instead you have to identify how much of the overall disk traffic is being caused by paging activity.

So whenever you see any memory issues then keep an eye on above SYSMON counters and monitoring should get you better information.

 

SQL Server 2005 Scalability and Performance - recommended limit on number of instances on a clustered environment?
04 April 08 02:48 AM | SQL Master | 3 Comments   

This is a very tricky question and hard to stick to 1 or few solutions as answer, it depends!

Overall the say is if  there isn’t any resource contention (from your pre-installation testing & analysis) and there is enough of each resource to go around, then there is usually no reason to set any restrictions on the server resource. The Operating System and SQL Server will share the available resources without any problems. However, if there is any resource contention, then depending on the resource and what you want to happen, the way that SQL Server and the Server Resource manage the contention might not give you the result you want. In this situation you should consider more testing (real-time or like-to-like configuration) on your pre-production environment to see whether any setting of restriction on the resources will do any better.
 
As it speaks the main contention you will see is memory usage on that server, by default each SQL Server instance configuration (dynamic memory settings) will take what memory it thinks it needs, up to the available physical memory. When there is memory contention, then sometimes one SQL Server instance won’t release memory as quickly as you might like. So in this case changing or considering the memory setting to MIN & MAX should have thorough testing of your application during busy times, where the slow performance issue is reported. After such testing you may need to configure maximum and minimum server memory settings to manually control this. As these are dynamic settings in SQL Server 2005, you can change them without a reboot and see an immediate effect. With the latest enhancement with Windows 2003 (even with 2008 version) and each SQL Server (version 2005 for discussion sake, even can consider the SQL Server 2008) instance does a great job of sharing the CPU between all threads. You feel this is great you see and may this is what you want, but what it does is allow all instances to have an equal share of the CPU, not a share based on how much work they have to get done. For discussin sake if you have both DSS & OLTP based applications within your environment then this is unacceptable and you may need set the configuration to OLTP system to hike the performance.
 
A short discussion leads to the disk I/O after the memory configuration, to check the contention. With recommended practices or based on your own configuration you can choose I/O system, from similar blog posts such as :
  • Memory & I/O related:
  • For Database maintenance related:
 
Then it comes to the configuration of setting up the layout of data and log files on to different physical disks with each on different I/O path. When it comes to a Clustered environment having multiple instance this is more complex. You need to consider the additional concerns such as instance failover, what do do and how resources are coping up to provide scalability & performance and this also highlights the resource requirements of the instances that may fail over to this node. As it complexes the topic I recommend to review the whitepapers such as "SQL Server 32bit Consolidation using a Clustered Environment" and "SQL Server Consolidation on the 64-Bit Platform".
 
Lastly, it comes to the number of instances that are supported by SQL Server, it is 50 (default + 49 named) when the environment is not a clustered. When SQL Server is clustered then you can have 25 as maximum number of instances, this is not a definitive or recommended value but it has to be or can be further restricted by additional limitations imposed by clustering. Again this circles around the same old saying, that is going to depend on the resources available on your server and the resources that each instance requires. You need to sumup the resource requirements such as CPU, Memory, I/O and load (number of users & number of times data is retrieved). Recently I was involved with one of the SQL 2005 Cluster configuration project and we have easily setup multiple instances by taking the mount point support, for the sake of scalability of resource usage. Still the availability needs to be considered such as if you get down to one node, one plus one still must equal two. If one plus one equals three, then your totaled-up instances have greater capacity than the node itself. By taking the points from above resources and links we were able to reduce the contention the allocated a particular instance (as dedicated one) for the busiest application, in order to avoid any confusion of resource allocation by the hardware itself.
 
 
SQL Server Memory - what's your method on Configuration and Troubleshooting Issues
01 April 08 02:49 AM | SQL Master | 5 Comments   

Memory - an important aspect of system performance within a RDBMS platform, not specific to a database product or application.

Coming to Microsoft related products such as Windows Server and SQL Server so on, various resources available on web such as MSDN blogs, Books Online and articles, frequently viewed concept for memory is such as /3GB switch and optimum memory settings. In any case the performance will be sufferred if there is a memory shortage, adding fule to the situation with insufficient resources. So to dig further into this issue always consider 2 aspects of troubleshooting, available physical memory and usage of available virtual memory by any process on the server. Taking the first one into consideration say when a system has little RAM (physical) available the system will switch to get resources from the virtual memory manager with an increased workload to give recently accessed virtual memory pages for that process, this is where you see lots of paging activity to the disk on the server. IN this case when you get statistics with SYSMON (PERFMON) the behaviour can be retrieved that will confirm the downtrend of application availability on the resources. The second one talked about virtual memory occupation, which will lead to memory leak throwing lots of exception errors & warnings having another load to paging until the system excperience the shortage, completely.

So how you can take the configuration and troubleshooting of such an important aspect, take this into SQL Server coding aspect within the usage of cursors or retrieving large result set with queries that will occupy the memory location and will be removed only when new request for physical memory addresses, this also because of the manner in which virtual memory address space is mapped to physical memory on demand. The slow performance investigation should continue from memory usage by identifying whether excessive paging is occurring or not. However, remember that excessive paging may occur even if there is plenty of available memory - for example if an application is leaking memory.  As referred above  it is important to have a baseline of your system's performance and SQLMemoryConfiguration_Gotchas to compare to any new performance statistics that you gather.  So the next question will arise what kind of PERFMON counters you should consider in gathering such data, that we talk as follows (typical to Windows Server setup):

(These are gathered from the web resources such as Technet blogs & SQL Server performance website websites and not to mention my own experience)

PERFMON Counter - Memory:

  • Pages / sec - important to identify the rate at which pages are read from disk to resolve hard page faults. This means the disk usage will be very high and when a fault is occurred then the system tries to read multiple contiguous pages into memory to maximize the benefit of the read operation. In this case make sure to capture the 'Pages Input/Sec' & 'Page Reads/Sec' counters too that will give better idea on average number of pages read into memory during this operation.

Bear in mind if the disk hardware is not efficient then you will see spikes even for smaller operations, in general on a SQL Server installation during the backup operations (such as transaction log & database) you will observe a spike which is a common behaviour and better RAID configuration will do much better. A reference on relevant disk blog posts here:

Utilizing RAID is beneficial to both the security of your data and the performance of your shop

Is RAID5 better for performance when SQL Server Clustering and SAN is involved?

Best way to deploy SQL Server 2005 with SAN

How to gain Disk related performance with few simple steps

What's your practice on Disk Defragmentation methods - specific to data file and indexes drives?

Determining the required capacity of an I/O subsystem before deploying the database

  • Pool Nonpaged Bytes - as referred they show the values in bytes that relates to area of system memory (physical) by the operating system for objects (threads) that cannot be written to disk. The life of these processes will be in memory only as long as they are allocated. So if you see the value more than 85% (constantly) then refer to this NonPaged-Depletion-issue blog post.

 

  •  %Committed Bytes in Use - is the space that has been reserved in paging file, to be written to disk. AskPerf team given much insight on this information here - "What is the Page File for anyway?".

 

  • Available Bytes - this is required to calculate the immediate availability of memory allocation to a process and make sure to monitor this constantly, as any value lower than 10% of installed memory (physical) then it indicates the system is sufferring a lot.

Based on above counters if you see a high spikes on page file then consider to resize the pagefile.sys on your system. Also one of the best practices is to keep the page file on a seperate drive to avoid any excessively busy & overall system performance may be impacted.  Memory leak is another point to raise here that means an application will show up as a gradual increase in the value of the Private Bytes counter listed above.  So going further to address the issues is to gather the data & perform  a baseline analysis as per above blog posts.

First and foremost solution is to add more RAM (physical) by checking the compatibility such as SQL Server editions & memory configuraiton (such as More than 3GB memory is not used even though boot.ini has these switches on /3GB /PAE /AWE.