Determining Blocking Queries in SQL Query Performance Tuning

Publié le par Tosska Technologies

Database objects are often locked by processes, leaving other processes to get blocked. Locking is important as it forces every single transaction in SQL Server to undergo the ACID test, enforcing integrity in the process.

Here, we will uncover some useful methods to find which queries are behind such blockages and help with SQL query performance tuning. But before that, let us take a look at what the ACID test means. 

What is the ACID Test?

The ACID test is essentially a trial to ensure each transaction meets the following standards:

Atomicity - Transactions will only execute if it is complete, otherwise, they won’t be carried out.

Consistency - It is important for transactions to return all the information to the initial state in case of failure or create a valid new state.

Isolation - If a transaction hasn’t been committed until now but its execution process is underway, it will have to be isolated from the rest of the transactions.

Durability - Information that has been committed is required to be saved in such a manner that ensures proper maintenance of information. This helps in case the system fails and must be restarted.

More on isolation: This is part of the ACID test that works when objects are locked. Due to this, it can cause an impact on multiple rows until the transaction is committed (the one that is carried out against that object.

SQL Server T-SQL Performance Best Practices Tips - Part 1

In other words, the database management system will keep the rest of the processes from affecting the data in any way as they lock the object beforehand. The processes cannot make changes until the lock is taken off, slowing down performance and requiring Oracle database performance tuning. The lock may be removed by rolling back or committing the change.

How Locking an Object Affects Oracle Database Performance Tuning

Enforcing locks over objects can make other processes that are requesting the locked object wait. This delays the progress of those processes until the lock is released. This state in which the transaction is halted while queued to use the object that is locked is called a block.

The database is made to operate in this manner which means that blocks don’t usually cause issues. The potential problem only occurs when there are too many blocks that require SQL performance tuning or certain blocks that take too long to unblock.

Let us consider an instance of SQL Server blocking that involves two transactions. The first transaction makes an attempt to refresh a table’s information. Although this transaction is not yet over and is still going on, the second transaction attempts to put its lock on the same table. In case the row needing to be removed is the very same row the next transaction has to update; the next transaction will face a block. The reason behind this is that the first transaction has already placed an exclusive lock as the transaction is in progress.

Determining Blocking Instances in Databases

There are a few methods to identify when blocks are occurring in a database and whether you will require Oracle database performance tuning:

  • DMVs
  • Activity Monitor

These are tools that allow users to analyse the details of current connections. They also assist by displaying data regarding the open processes and the resources with locks on them.

 

Publicité
Pour être informé des derniers articles, inscrivez vous :
Commenter cet article