Skip to content

Category: SQL Server Architecture

SQL Server 0

SQL Server ACID Properties

What is ACID Properties in SQL?

These Properties are important aspects of whole Database Management System.

Many application uses MS SQL server for their databases. Number of complex queries runs on the database, many a times multiple queries were running on the databases. But we never heard that, SQL server has any type of issue in the data due to this.

You know how SQL server is achieving this?

SQL Server ensures the transaction reliability by enforcing Atomicity, Consistency, Isolation, and Durability through the storage engines Transaction Manager.
These Properties of SQL server are called as ACID property.

Atomicity

Whenever we execute any transaction, it will execute fully or fails completely. If the transaction fails partially, SQL server triggers the ROLLBACK.

  • There is no partial execution
  • This property prevents partial data updates
  • Maintains data integrity
  • SQL servers uses below commands to achieve this
    BEGIN TRANSACTION,
    COMMIT,
    ROLLBACK

Technically SQL server uses Transaction Logs and Write-Ahead logging mechanisms to achieve Atomicity.

Example:-

Bank transfer from Account A to Account B:

  • Step 1: Debit 100 from A (UPDATE AccountA SET Balance = Balance – 100).
  • Step 2: Credit 100 to B (UPDATE AccountB SET Balance = Balance + 100).

With Atomicity, you never end up with A debited but B not credited.
Either both updates succeed, or both are undone.

Consistency

This property ensures that a transaction brings the database from one valid state to another. It preserves all defined rules like constraints, triggers, and relationships.

After a transaction

  • All rules, constraints, and relationships must be satisfied
  • Invalid data is not allowed

SQL server enforces consistency using following-

1. Constraints
Primary Key – no duplicates, no Nulls
Foreign key – valid relationship
UNIQE- No duplicate values
CHECK – validate conditions
Not Null – prevent missing value

2. Triggers
Automatically enforce business rule

3. Data Types
Ensures correct format

4. Indexes and relationships
Maintain logical integrity between tables

Atomicity handles completions, where consistency handles correctness.

Isolation

This property of SQL server controls how transactions interact with each other when running concurrently

It ensures that one transaction does not interfere with another transaction’s data

This prevents dirty reads, non-repeatable reads and phantom reads Default Isolation level in SQL server is READ COMMITTED.

Durability

This property ensures that once the transaction commits, its changes are permanently saved. These changes survive system failures like power outages, crashes, or restarts.

When you execute the transactions in SQL server, data is written to transaction logs.

When you Commit, SQL server forces transaction log records to disk.

Once the data flushes to the disk, it becomes durable

Please refer below Microsoft article for more information

ACID Properties

Check all related articles

SQL Server Architecture 0

Understanding SQL Server Buffer Cache: PLE & Hit Ratio Explained

SQL Server has excellent feature called Buffer cache or Buffer pool. The buffer manager copies data into memory whenever it is written to or read from the SQL Server database. Because of this, SQL server can read or write data very fast. You can also say that this improves the performance of the SQL server.
Page Life Expectancy (PLE) and Buffer Cache Hit Ratio are performance counters. They are related to the time spent by data pages in this buffer pool.

Page Life Expectancy (PLE) in SQL Server

Page Life Expectancy is the number of seconds a page will stay in the buffer pool without references.
In simple words, if your page stays longer in the buffer pool, your Page Life Expectancy is high. This leads to high performance. Every time a request comes, it is more common to find its data in the cache. This prevents going again and again to the hard drive to read the data.

  • Page Life Expectancy measures in seconds.
  • Page Life Expectancy is one of the important performance counter of SQL Server.
  • Higher the Page Life Expectancy, better the performance of SQL Server.
  • As per the Microsoft’s recommendation, value of Page Life Expectancy counter is around 300 seconds.

You can check the Page Life Expectancy value for your SQL server using below Dynamic Management View (DMV).

SELECT object_name, counter_name, cntr_value from sys.dm_os_performance_counters WHERE [object_name] LIKE '%Buffer Manger%' AND [counter_name] = 'page life expectancy'

Buffer Cache Hit Ratio

Buffer Cache Hit Ratio shows the percentage of pages found in the buffer cache. These pages are found in the memory and there is no need to read it from the disk.
The ratio is calculated by dividing the total number of cache hits by the total number of cache lookups. This calculation is based on the last few thousand page accesses.

  • Buffer Cache Hit Ratio is one of the important performance counter of SQL server.
  • You can increase the buffer cache hit ratio in two ways.
    1. One is by increasing the amount of memory available to SQL Server.
    2. The other is by using the buffer pool extension feature.

You can check the Buffer Cache Hit Ration value for your SQL server using below Dynamic Management View(DMV).

SELECT object_name, counter_name, cntr_value from sys.dm_os_performance_counters WHERE [object_name] LIKE '%Buffer Manger%' AND [counter_name] = 'Buffer cache hit ratio'

Check all related articles

SQL Server Architecture 1

Page, Extent in SQL Server

Page in SQL Server

Page is fundamental unit of data storage in SQL Server.
The disk space allocated to data files in database is logically divided into pages. Disk I/O operations are performed at the page level. Which means SQL server read or writes the whole data page.
All the pages are same physical size i.e. 8 KB.
Some pages includes data, metadata or both.
Each Page begins with the 96-byte header which includes system information about the page. It includes the page number and page type. It also covers the amount of free space on the page. Additionally, it includes the allocation unit ID of the object that owns the page.

Note – Log files do not contain pages, they contain a series of log records.

Types of Pages

  1. Data Pages
  2. Index Pages
  3. Text/Image Pages
  4. Global Allocation Map(GAM)
  5. Shared Global Allocation Map(SGAM)
  6. Page Free Space(PFS)
  7. Index Allocation Map(IAM)
  8. Bulk Changed Map(BCM)
  9. Differential Changed Map(DCM)

1. Data Pages
Data pages contain data rows with all the data. This excludes text, ntext, image, nvarchar(max), varchar(max), varbinary(max), and xml data when text in row is set to ON.

2. Index Pages
Index pages includes index entries.

3. Text/Image pages
It includes data with large object types. These include text, ntext, and image. Other types are nvarchar(max), varchar(max), varbinary(max), and xml data.

4. Global Allocation Map (GAM)
GAM page includes information related to Extent allocation.
GAM has a bit for every extent. If the bit is 1, the corresponding extent is free. If the bit is 0, the corresponding extent is in use as uniform or mixed extent.
A GAM can hold information of 64000 extents.

5. Shared Global Allocation Map (SGAM)
SGAM pages record which extents are currently being used as mixed extent. They also have at least one unused page.
If the bit is 1, the corresponding extent is used as mixed extent. It also has at least one page free to allocate. If the bit is 0, the corresponding extent is not used as mixed extent. Alternatively, it is a mixed extent with all its pages being used.
A SGAM page also holds information of 64000 extents.

6. Page Free Space (PFS)
PFS pages includes information about page allocation and free space available on pages.

7. Index Allocation Maps (IAP)
IAP pages includes information about extents used by a table or index per allocation unit.

8. Bulk Changed Map (BCM)
BCM pages contain information about extents. These extents are modified by bulk operations after the last BACKUP LOG statement.

9. Differential Changed Map (DCM)
DCM pages contain information about extents. These extents have been changed since the last BACKUP database statement.

Extent in SQL Server

Extent is a collection of eight physically contiguous pages, which means size of extent is 64 KB.
Extent helps to manage pages efficiently.
SQL Server uses GAM and SGAM pages to manage extent allocation.
BCM and DCM pages are used by SQL server to track the modifications in extents.

Types of Extents

1. Uniform Extent
Uniform extents are owned by a single object. Means all the eight pages in the extent are used by same object.

2. Mixed Extent
Mixed extents are owned by different objects. Each of the eight pages can be used by different objects.

Types of Extent
Types of Extent

Check all related articles