Saturday, December 15, 2012

Points to Check when SQL Server Log File Full or SQL Server 9002 Error.

Following are the Points to Check.... 

 1. First check columns log_reuse_wait and log_reuse_wait_desc in sys.dtabases system table.

 2. Then following are the options to mange log file when SQL server is showing 9002 or Log file full error:
      Backing up the log Increase Disk Size Remove unnecessary files from Disk/ freeing disk space
      Kill long Running Unnecessary Transactions
      Add additional Disk
      Attach and Detach Log File
      Shrink Log file with truncate only
      Check for unnecessary transaction or long running queries

Increase the size of the log file Move the log file on different disk space we need to follow above steps as per the Requirement and scenarios...

 Thanks, DB

Saturday, December 8, 2012

Top Most Used Sql Server DMV's

TOP MOST USED SQL SERVER DMV’s(Dynamic Management Views) What are DMVs Dynamic Management Views are views and functions introduced in sql server 2005 for monitoring and tuning sql server performance. Dynamic Management Objects (DMOs) Dynamic Management Views (DMVs) -- can select like a view Dynamic Management Functions(DMFs) --Requires input parameters like a function When and Why use them • Provides information that was not available in previous version of sql server • Provides a simpler way to query the data just like any other view versus using DBCC commands or system stored procedures Types of DMVs • change data capture • common language runtime • database mirroring • database • execution • full-text search • I/O • Index • Object • Query notifications • Replication • Resource governor • SQL Operating System Get a list of all DMOs Permissions 1 select name, type_desc from sys.all_objects where name like 'dm%' order by name Server scoped -- view server state database scoped --view database state Deny takes prescedence deny state or deny select on an object People should have sys admin privileges Grant permissions grant view server state to loginname grant view database state to user deny view server state to loginname deny view database state must create user in master first Specific types of DMVs • database • execution • IO • Index • SQL operatng system Database for page and row count select object_name(object_id) as objname, * from sys.dm_db_partition_stats order by 1 T Execution--- (when sql server is restart everything is reset) sys.dm_exec_sessions -- info about all active user connections and internal tasks sys.dm_exec_connections -- info about connections established sys.dm_exec_requests -- info about each request that is executing (including all system processes) Execution--- Query plans sys.dm_exec_sql_text --returns text of sql batch sys.dm_exec_query_plan --returns showplan in xml select * from sys.dm_exec_query_stats -- returns stats for cached query plans sys.dm_exec_cached_plans --each query plan that is cached Exection -- example select * from dm_exec_connections cross apply sys.dm_exec_sql_text(most_recent_sql_handle) select * from dm_exec_requests cross apply sys.dm_exec_sql_text(sql_handle) Select T.[text],p.[query_plan], s.[program_name],s.host_name, s.client_interface_name, s.login_name, r.* from sys_dm_exec_requests r inner join sys.dm_exec_sessions S ONs.session_id = r.session_id cross apply sql_text cross apply sys.dm_execsql_query_plan select usecounts, cacheobjype, objtype, text from sys.dm_exec_cached_plans cross apply dm_exec_sql_text(plan_handle) where usecounts > 1 order by use cuonts desc IO select * sys.dm_io_pending_io_requests can be run when you think that io can be a bottleneck select * from sys.dm_io_virtual_file_stats (null,null) select db_name(database_id), * from sys.dm_io_virtual_file_stats(null,null) shows io stats for data and log files -- database id and file id -- null returns all data db_name is a funtion to return the name of the actual database rather than database id Index (when sql server is restart everything is reset) sys.dm_dm_db_index_operational_stats (DMF) -- shows io, locking and access information such as inserts, deletes, updates sys.dm_dm_db_index_physical_stats (DMF) -- shows index storage and fragmaentation info, sys.dm_dm_db_index_usage_stats (DMV) -- shows how often indexes are used and for what type of SQL operation Index examples select db_name(dtabase_id), object_name(), * from operation_stats(5,null,null,null) parameters databaseid, objectid, indexid, partition number select db_name(dtabase_id), object_name(), * from physical_stats(DB_ID(N'Northwind'),5,null,null,null, detaled) parameters databaseid, objectid, indexid, partition number, mode Missing indexes sys.dm_db_missing_index_details sys.dm_db_missing_index_groups sys.dm_db_missing_index_group_stats sys.dm_db_missing_index_columns SQL Operating system sys.dm_os_schedulers -- information abt processors sys.dm_os_sys_info -- info abt computer and abt resources available to and consumed by sql server sys.dm_os_sys_memory -- how memory is used overall on the server, and how much memory is available. sys.dm_os_wait_stats -- info abt all waits DBCC SQLPERF('sys.dm_os_wait_stats', CLEAR) sys.dm_os_buffer_descriptors -- info abt all data pages that are currently in the sql server buffer pool

Top 12 Features of SQL Server 2012

Top 12 Features of SQL Server 2012 1. AlwaysOn Availability Groups -- This feature takes database mirroring to a whole new level. With AlwaysOn, users will be able to fail over multiple databases in groups instead of individually. Also, secondary copies will be readable, and can be used for database backups. The big win is that your DR environment no longer needs to sit idle. 2. Windows Server Core Support -- If you don't know what Windows Server Core is, you may want to come up to speed before Windows 8 (MS is making a push back to the command line for server products). Core is the GUI-less version of Windows that uses DOS and PowerShell for user interaction. It has a much lower footprint (50% less memory and disk space utilization), requires fewer patches, and is more secure than the full install. Starting with SQL 2012, it is supported for SQL Server. 3. Columnstore Indexes -- This a cool new feature that is completely unique to SQL Server. They are special type of read-only index designed to be use with Data Warehouse queries. Basically, data is grouped and stored in a flat, compressed column index, greatly reducing I/O and memory utilization on large queries. 4. User-Defined Server Roles -- DBAs have always had the ability to create custom database role, but never server wide. For example, if the DBA wanted to give a development team read/write access to every database on a shared server, traditionally the only ways to do it were either manually, or using undocumented procedures. Neither of which were good solutions. Now, the DBA can create a role, which has read/write access on every DB on the server, or any other custom server wide role. 5. Enhanced Auditing Features -- Audit is now available in all editions of SQL Server. Additionally, users can define custom audit specifications to write custom events into the audit log. New filtering features give greater flexibility in choosing which events to write to the log. 6. BI Semantic Model -- This is replacing the Analysis Services Unified Dimensional Model (or cubes most people referred to them). It's a hybrid model that allows one data model will support all BI experiences in SQL Server. Additionally, this will allow for some really neat text infographics 7. Sequence Objects -- For those folks who have worked with Oracle, this has been a long requested feature. A sequence is just an object that is a counter -- a good example of it's use would be to increment values in a table, based a trigger. SQL has always had similar functionality with identity columns, but now this is a discrete object. 8. Enhanced PowerShell Support -- Windows and SQL Server admins should definitely start brushing up on their PowerShell scripting skills. Microsoft is driving a lot of development effort into instrumenting all of their server-based products with PowerShell. SQL 2008 gave DBAs some exposure to it, but there are many more in cmdlets in SQL 2012. 9. Distributed Replay -- Once again this is answer to a feature that Oracle released (Real Application Testing). However, and in my opinion where the real value proposition of SQL Server is, in Oracle it is a (very expensive) cost option to Enterprise Edition. With SQL, when you buy your licenses for Enterprise Edition, you get everything. Distributed replay allows you to capture a workload on a production server, and replay it on another machine. This way changes in underlying schemas, support packs, or hardware changes can be tested under production conditions. 10. PowerView -- You may have heard of this under the name "Project Crescent" it is a fairly powerful self-service BI toolkit that allows users to create mash ups of BI reports from all over the Enterprise. 11. SQL Azure Enhancements -- These don't really go directly with the release of SQL 2012, but Microsoft is making some key enhancements to SQL Azure. Reporting Services for Azure will be available, along with backup to the Windows Azure data store, which is a huge enhancement. The maximum size of an Azure database is now up to 150G. Also Azure data sync allows a better hybrid model of cloud and on-premise solutions 12. Big Data Support -- I saved the biggest for last, introduced at the PASS (Professional Association for SQL Server) conference last year, Microsoft announced a partnership with Hadoop provider Cloudera. One part of this involves MS releasing a ODBC driver for SQL Server that will run on a Linux platform. Additionally, Microsoft is building connectors for Hadoop, which is an extremely popular NoSQL platform. With this announcement, Microsoft has made a clear move into this very rapidly growing space. SQL 2012 is a big step forward for Microsoft -- the company is positioning itself to be a leader in availability and in the growing area of big data. As a database professional, I look forward to using SQL 2012 to bring new solutions to my clients