---------------------------------------------------------------------------------------------------------------------------
Interview question : How DIFFERENTIAL Backups works internally
---------------------------------------------------------------------------------------------------------------------------
Answer :
A differential backup is based on the most recent, previous full data backup. A differential backup captures only the data that has changed since that full backup. The full backup upon which a differential backup is based is known as the base of the differential
Internally when you run a differential database backup it will backup all extents which has changes since the time last full backup was run. SQL Server stored data in 8KB page and an extent comprises of 8 of such 8 KB pages equaling to 64KB of data. Whenever any data changes within a 8KB Page a flag is turned on to let SQL Server know that if at all a differential backup is initiated then it should include the data from this extent within the backup. Once a FULL backup is completed the flags are turned off. Therefore, every time you take a differential backup it will backup all the extends which has changed after the last successful FULL backup.
Overview of Differential Backups
A differential backup captures the state of any extents (collections of eight physically contiguous pages) that have changed between when the differential base was created and the when differential backup is created. This means that the size of a given differential backup depends on the amount of data that has changed since the base. Generally, the older a base is, the larger a new differential backup will be. In a series of differential backups, a frequently updated extent is likely to contain different data in each differential backup.
The following illustration shows how a differential backup works. The figure shows 24 data extents, 6 of which have changed. The differential backup contains only these 6 data extents. The differential backup operation relies on a bitmap page that contains a bit for every extent. For each extent updated since the base, the bit is set to 1 in the bitmap.
For more reference :https://msdn.microsoft.com/en-IN/library/ms175526.aspx
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SYNCHRONIZING
SYNCHRONIZED
SUSPENDED
PENDING FAILOVER
Execution Related
sys.dm_exec_connections
sys.dm_exec_sessions
sys.dm_exec_requests
sys.dm_exec_cached_plans
sys.dm_exec_query_plans
sys.dm_exec_sql_text
sys.dm_exec_query_stats
Index Related
sys.dm_db_index_physical_stats
sys.dm_db_index_usage_stats
SQL Server Operating System
sys.dm_os_performance_counters
sys.dm_os_schedulers
sys.dm_os_nodes
sys.dm_os_waiting_tasks
sys.dm_os_wait_stats
I/O Related
sys.dm_io_virtual_file_stats
The results returned after running the procedures include following information:
If the page is completely filled and new data is inserted in the table which belongs to completely filled page, the “page split” event happens to accommodate new data. When new data arrives, SQL Server has to accommodate the new data, and if it belongs to the page which is completely filled, SQL Server splits the page in two pages dividing the data in half. This means a completely filled page is now two half-filled pages. Once this page split process is over, the new data is inserted at its logical place. This page split process is expensive in terms of the resources. As there is a lock on the page for a brief period as well, more storage space is used to accommodate small amounts of data. The argument usually is that it does not matter as storage is cheaper now a day.
Interview question : How DIFFERENTIAL Backups works internally
---------------------------------------------------------------------------------------------------------------------------
Answer :
A differential backup is based on the most recent, previous full data backup. A differential backup captures only the data that has changed since that full backup. The full backup upon which a differential backup is based is known as the base of the differential
Internally when you run a differential database backup it will backup all extents which has changes since the time last full backup was run. SQL Server stored data in 8KB page and an extent comprises of 8 of such 8 KB pages equaling to 64KB of data. Whenever any data changes within a 8KB Page a flag is turned on to let SQL Server know that if at all a differential backup is initiated then it should include the data from this extent within the backup. Once a FULL backup is completed the flags are turned off. Therefore, every time you take a differential backup it will backup all the extends which has changed after the last successful FULL backup.
Overview of Differential Backups
The following illustration shows how a differential backup works. The figure shows 24 data extents, 6 of which have changed. The differential backup contains only these 6 data extents. The differential backup operation relies on a bitmap page that contains a bit for every extent. For each extent updated since the base, the bit is set to 1 in the bitmap.
For more reference :https://msdn.microsoft.com/en-IN/library/ms175526.aspx
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Interview question :What are different possible Mirroring Stats?
-------------------------------------------------------------------------------------------------------------------------
Answer :
Answer :
SYNCHRONIZING
SYNCHRONIZED
SUSPENDED
PENDING FAILOVER
DISCONNECTED.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Interview question: What are the few SQL Server DMV are used by DBA
--------------------------------------------------------------------------------------------------------------------------
Answer :
Execution Related
sys.dm_exec_connections
sys.dm_exec_sessions
sys.dm_exec_requests
sys.dm_exec_cached_plans
sys.dm_exec_query_plans
sys.dm_exec_sql_text
sys.dm_exec_query_stats
Index Related
sys.dm_db_index_physical_stats
sys.dm_db_index_usage_stats
SQL Server Operating System
sys.dm_os_performance_counters
sys.dm_os_schedulers
sys.dm_os_nodes
sys.dm_os_waiting_tasks
sys.dm_os_wait_stats
I/O Related
sys.dm_io_virtual_file_stats
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Interview question: What is Fragmentation ? How can you detect? If Fragmentation is too high what steps DBA can taken?
---------------------------------------------------------------------------------------------------------------------------
Answer :
The SQL Server Database Engine automatically maintains indexes whenever insert, update, or delete operations are made to the underlying data. Over time these modifications can cause the information in the index to become scattered in the database (fragmented). Fragmentation exists when indexes have pages in which the logical ordering, based on the key value, does not match the physical ordering inside the data file. Heavily fragmented indexes can degrade query performance and cause your application to respond slowly.
You can remedy index fragmentation by reorganizing or rebuilding an index.
Fragmentation can be easily detected by running the system function sys.dm_db_index_physical_stats which returns the size and the fragmentation information for the data and indexes of tables or views in SQL Server. It can be run only against a specific index in the table or view, all indexes in the specific table or view, or vs. all indexes in all databases:
The results returned after running the procedures include following information:
- avg_fragmentation_in_percent – average percent of incorrect pages in the index
- fragment_count – number of fragments in index
- avg_fragment_size_in_pages – average number of pages in one fragment in an index
| avg_fragmentation_in_percent value | Corrective statement |
|---|---|
| > 5% and < = 30% | ALTER INDEX REORGANIZE |
| > 30% |
ALTER INDEX REBUILD WITH (ONLINE = ON)*
|
Index Rebuild : This process drops the existing Index and Recreates the index.
Index Reorganize : This process physically reorganizes the leaf nodes of the index.
USE AdventureWorks;GOALTER INDEX ALL ON Production.Product REBUILD
GOIndex Reorganize : This process physically reorganizes the leaf nodes of the index.
USE AdventureWorks;GOALTER INDEX ALL ON Production.Product REORGANIZE.
GO For more reference :https://msdn.microsoft.com/en-us/library/ms189858.aspx
**By using this query we can identify the
fragmentation in SQL SERVER 2008 and above.
SELECT
DB_NAME(idxst.database_id) AS [database_name],
OBJECT_NAME(idxst.object_id, idxst.database_id) AS [object_name],
QUOTENAME(idxif.name) [index_name],
CASE
WHEN avg_fragmentation_in_percent < 10 THEN 'LOW'
WHEN avg_fragmentation_in_percent < 30 THEN 'MEDIUM'
WHEN avg_fragmentation_in_percent < 50 THEN 'HIGH'
ELSE 'EXTREME'
END as fragmentation_indicator,
idxst.*
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL , 'LIMITED') AS idxst -- not using DETAILED or SAMPLED
INNER JOIN sys.indexes idxif ON idxst.object_id = idxif.object_id AND idxst.index_id = idxif.index_id
ORDER BY [object_name], [index_name]
GO
DB_NAME(idxst.database_id) AS [database_name],
OBJECT_NAME(idxst.object_id, idxst.database_id) AS [object_name],
QUOTENAME(idxif.name) [index_name],
CASE
WHEN avg_fragmentation_in_percent < 10 THEN 'LOW'
WHEN avg_fragmentation_in_percent < 30 THEN 'MEDIUM'
WHEN avg_fragmentation_in_percent < 50 THEN 'HIGH'
ELSE 'EXTREME'
END as fragmentation_indicator,
idxst.*
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL , 'LIMITED') AS idxst -- not using DETAILED or SAMPLED
INNER JOIN sys.indexes idxif ON idxst.object_id = idxif.object_id AND idxst.index_id = idxif.index_id
ORDER BY [object_name], [index_name]
GO
------------------------------------------------------------------------------------------------------------------------------------------------------------------
What is Fill Factor ?
-------------------------------------------------------------------------------------------------------------------------
Answer :
Fill factor is the value that determines the percentage of space on each leaf-level page to be filled with data. In an SQL Server, the smallest unit is a page, which is made of Page with size 8K. Every page can store one or more rows based on the size of the row. The default value of the Fill Factor is 100, which is same as value 0. The default Fill Factor (100 or 0) will allow the SQL Server to fill the leaf-level pages of an index with the maximum numbers of the rows it can fit. There will be no or very little empty space left in the page, when the fill factor is 100.
If the page is completely filled and new data is inserted in the table which belongs to completely filled page, the “page split” event happens to accommodate new data. When new data arrives, SQL Server has to accommodate the new data, and if it belongs to the page which is completely filled, SQL Server splits the page in two pages dividing the data in half. This means a completely filled page is now two half-filled pages. Once this page split process is over, the new data is inserted at its logical place. This page split process is expensive in terms of the resources. As there is a lock on the page for a brief period as well, more storage space is used to accommodate small amounts of data. The argument usually is that it does not matter as storage is cheaper now a day.
Fill factor is usually measured at the server level as well as table level. Below we have the scripts for the same.
Here is the script to measure the Fill Factor at the server level:
And, here is the script to measure the Fill Factor at the table/index level:SELECT * FROM sys.configurations WHERE name ='fill factor (%)'
USE YourDatabaseName; SELECT OBJECT_NAME(OBJECT_ID) Name, type_desc, fill_factor FROM sys.indexes
I think this is good logical stop for this blog post today. Thank you!!






