WAITING TYPES

 > When if any query waiting for resources then relevant wait type comes into picture. Which cause high performance impact.

How to find wait type:

Select * from sys.sysprocesses

Column “last wait type”

Types of wait types:

1. LCK_M_S: Occurs when a task is waiting to acquire a shared lock. [Occurs mostly in blockings]

2. ASYNC_IO_COMPLETION: Occurs when a task is waiting for I/Os to finish.

3. ASYNC_NETWORK_IO: Occurs on network writes when the task is blocked behind the network. Verify that the client is processing data from the server.

CDC (CHANGE DATA CAPTURE)

 >>What is Change Data capture? [CDC]

1. Microsoft SQL Server 2008 has introduced a very exciting feature for logging DML changes.

2. Change data capture provides information about DML changes on a table and a database.

3.Change data capture records insert, update, and delete activity , that’s applied to a SQL Server table and makes a record available of what changed, where, and when, in simple relational 'change tables’.

4. Also stores historical data and COLUMN level changes in SQL Server by using CDC feature.

5. Change data capture is available only on the Enterprise, Developer, and Evaluation editions of SQL Server

>>How it works>

1. The source of change data for change data capture is the SQL Server transaction log.

2. As inserts, updates, and deletes are applied to tracked source tables, entries that describe those changes are added to the log.

3. The log serves as input to the change data capture process. This reads the log and adds information about changes to the tracked table’s associated change table.

>>Permissions required to configure CDC:

EITHER DB_OWNER OR SYSADMIN permissions

>>CDC Configuration steps:

1. Enable CDC on database by using

EXEC sys.sp_cdc_enable_db

@5 system tables gets created automatically.

[cdc].[captured_columns]

[cdc].[change_tables]

[cdc].[ddl_history]

[cdc].[index_columns]

[cdc].[lsn_time_mapping]

[dbo].[systranschemas]

2. Enable CDC on table by using

EXEC sys.sp_cdc_enable_table

@source_schema = N'dbo',

@source_name = N'MyTable',

@role_name = NULL

Note: Few CDC system table and 2 CDC jobs create automatically inside of the SQL Server databases

CDC Default Tables:

cdc.captured_columns: This table returns result for list of captured column.

cdc.change_tables: This table returns list of all the tables which are enabled for capture.

cdc.ddl_history: This table contains history of all the DDL changes since capture data enabled.

cdc.index_columns: This table contains indexes associated with change table.

cdc.lsn_time_mapping: This table maps LSN number (for which we will learn later) and time.

dbo.systranschemas:


After enabling CDC on table one more addition tracking table

Ex: CDC.DBO_STAB_CT

List of automatic jobs:

cdc.DBNAME_capture

cdc.DBNAME_cleanup

Findings:

Select * from CDC.DBO_STAB_CT

If the operation column shows value

1: Delete operation

2: Insert operation

3: Before update

4: After update

Along with this data gets captured into CDC defined table.

Note: Enable CDC only with confirmation from apps team or client... If you enable it consumes more hardware resource and additional storage is required.

Check list for before Migration?

 Migration from SQL Server 2008 to SQL Server 2014 Check list

1. Identify databases you would like to migrate

2. Backup all user databases

3. Script out all the existing login

4. Script out all the Server roles if applicable

5. Script out all the Audit and Audit Specifications if Applicable

6. Script out backup devices if Applicable

7. Script out Server level triggers if Applicable

8. Script out Replication along with Configuration if Applicable

9. Script out Mirroring if Applicable

10. Script out Data Collection if Applicable

11. Script out Resource Governor’s objects if Applicable

12. Script out Linked Server if Applicable

13. Script out Logshipping if Applicable

14. Script out SQL Server Agent jobs

15. Script out all DB Mail objects such as Profile and its settings

16. Script out all Proxy accounts and credentials if Applicable

17. Script out all Operators if Applicable

18. Script out all alerts if Applicable

19. Save SQL Server, Server configuration in a file

20. Data Encryption keys

Destination SQL Server Checklist

1. Required SQL Server is installed

2. DBA SQL Server Check List is Completed

3. Enough Space for storing Backup and source scripts

4. Applications compatibility is signed off

How applications generally connect to database?

 1. When application try to connect, uses Config file (Configuration file--Resides in application server). Config file (.txt) should contains SQL Server instance name + user name [service account name--DBA team should add the account into SQL Server under security] + Password [Strong]

Application use all these details from Config file and point connection to SQL server database

Real time points:

> Any business 2 data centers maintains called PRODUCTION and DR data center.

> Always distance between data centers should not be more than 50 KM.

> Few people always work inside the data centers.

sp who3 script to check processes in SQL server

 --who3 to check active sessions in SQL Server.


SELECT

    SPID                = er.session_id

    ,BlkBy              = er.blocking_session_id      

    ,ElapsedMS          = er.total_elapsed_time

    ,CPU                = er.cpu_time

    ,IOReads            = er.logical_reads + er.reads

    ,IOWrites           = er.writes     

    ,Executions         = ec.execution_count  

    ,CommandType        = er.command         

    ,ObjectName         = OBJECT_SCHEMA_NAME(qt.objectid,dbid) + '.' + OBJECT_NAME(qt.objectid, qt.dbid)  

    ,SQLStatement       =

        SUBSTRING

        (

            qt.text,

            er.statement_start_offset/2,

            (CASE WHEN er.statement_end_offset = -1

                THEN LEN(CONVERT(nvarchar(MAX), qt.text)) * 2

                ELSE er.statement_end_offset

                END - er.statement_start_offset)/2

        )        

    ,STATUS             = ses.STATUS

    ,[Login]            = ses.login_name

    ,Host               = ses.host_name

    ,DBName             = DB_Name(er.database_id)

    ,LastWaitType       = er.last_wait_type

    ,StartTime          = er.start_time

    ,Protocol           = con.net_transport

    ,transaction_isolation =

        CASE ses.transaction_isolation_level

            WHEN 0 THEN 'Unspecified'

            WHEN 1 THEN 'Read Uncommitted'

            WHEN 2 THEN 'Read Committed'

            WHEN 3 THEN 'Repeatable'

            WHEN 4 THEN 'Serializable'

            WHEN 5 THEN 'Snapshot'

        END

    ,ConnectionWrites   = con.num_writes

    ,ConnectionReads    = con.num_reads

    ,ClientAddress      = con.client_net_address

    ,Authentication     = con.auth_scheme

FROM sys.dm_exec_requests er

LEFT JOIN sys.dm_exec_sessions ses

ON ses.session_id = er.session_id

LEFT JOIN sys.dm_exec_connections con

ON con.session_id = ses.session_id

CROSS APPLY sys.dm_exec_sql_text(er.sql_handle) AS qt

OUTER APPLY 

(

    SELECT execution_count = MAX(cp.usecounts)

    FROM sys.dm_exec_cached_plans cp

    WHERE cp.plan_handle = er.plan_handle

) ec

ORDER BY

    er.blocking_session_id DESC,

    er.logical_reads + er.reads DESC,

    er.session_id