Transactions - what is it? Database transaction

A transaction is a set of specific actions that are performed by a user or program to access or modify a database. Before you understand the transaction - what it is, you need to understand the essence of this process. The main point of the process is that actions must be either completely completed or canceled.

Each database transaction must translate it from one state that is consistent to another. It is assumed that in the process, consistency may be violated.

Many people wonder, transactions - what is it. This is a unit of work that is performed in the database. It can be part of a general algorithm, a separate command, or a program as a whole.

unable to complete transaction

How should the transaction end?

There are two ways to complete it:

  • In the event that the transaction completes successfully, the results are committed and the database goes into a new consistent state (commit).
  • If the execution failed, a transaction error has occurred, it is canceled. In this case, the database must be restored to the state that was originally. This situation is called roll back. However, if a transaction has been committed, then it cannot be canceled. If the actions were found to be erroneous, you need to perform another transaction, which will return the database to a consistent state.
    transactions what is it

Transaction Properties

To indicate the boundaries of transactions, it is customary to use the operators begin transaction, commit, roll back.

ACIDs, or transaction properties, can be as follows:

  • Atomic, or atomicity. A transaction is an indivisible unit that must be either executed or canceled.
  • Coordination, or coherence. The meaning of the transaction is for the database to transition from one consistent state to another.
  • Insulativity, or isolation. Each transaction that is executed is independent of the rest. All the results of one process, available in between, should not be visible to other transactions.
  • Duration, or duration. All the results that were achieved during a successful transaction should not be lost as a result of subsequent failures. They are stored in the database permanently.

Transactions are used to make changes or updates to the database. Each process is regulated and controlled by a transaction manager, and resources are controlled by a resource manager. The interaction of the two dispatchers determines the outcome of the operation. If necessary, block transactions.

database transaction

Transaction Phases

The following phases are distinguished:

  • Active. In this phase, a transaction is created, and resource managers are involved in the process.
  • Preparatory. During this period, each resource manager has the ability to determine the outcome of the operation. The start of the phase occurs when the initiator creates a request to complete the transaction. If some resource manager does not have time to prepare, it requires the transaction manager to send a rollback. Resource managers keep logs in which they record all data about the state of readiness. This is necessary so that in case of deviations it is possible to continue work from a certain place.
  • Fixation. The beginning of this phase occurs at the moment when all resource managers are ready for operation. If necessary, the transaction manager can complete the operation.

Each transaction must comply with certain requirements. As a result of the operation, the system must be brought into the correct state. This condition is necessary when a power failure occurs.

Transaction logs

During the operation, a transaction log is maintained, where all changes are recorded. It must be truncated regularly, such a measure will help to avoid overflow. However, there are a number of reasons why truncation may be delayed; during this period, it is especially important to monitor the filling. To reduce the size of the log, you can perform operations with minimal logging.

In the event of a failure, the log acts as a critical component, which will help bring the database into a consistent state. The journal is forbidden to modify or delete.

cancel transaction

Benefits of Using a Transaction Log

This allows you to support the following operations:

  • restore individual actions;
  • Recover transactions that were not completed
  • roll forward actions to failure;
  • make transactional replication.
    transaction error

How does log truncation happen?

The truncation process frees up space in the file, which is used for further recordings. If you neglect this process, all the disk space will be occupied, and many problems will arise. To avoid such situations, truncation is carried out automatically, except for cases when, for independent reasons, it is delayed.

Credit card transaction

transaction lock
When calculating in stores on a means of payment, customers think: transactions - what is it and what are they for? Operations with a bank card, such as cash withdrawals, deposits or transfers, are called a transaction. This concept is also used in payment card transactions at retail outlets.

Making a payment by credit card, not every client thinks about what processes are happening at this time. Although this knowledge is quite important, since it is about money and its security.

So, transactions - what is it when calculating in a store? This operation consists of several stages that are interconnected.

The main participants in the process are the bank (issuer) that issued the payment card, and the bank (acquirer) serving the outlet. The essence of the operation is that the acquirer wants to obtain permission from the issuer to conduct the transaction. Passing the card through the terminal, the cashier sends an encrypted request with the necessary data for the operation. All information is contained in a magnetic strip.

This request is sent to the processing center, the task of which is to process the data and then send the information to the issuing bank. He analyzes the information and compares it with his data. If no disagreement arises, the issuer issues a permit for the transaction. The essence of the process is to assign a personal authorization code.

Only after this, the acquirer can conduct the operation, as a result of which the transfer of funds from the client’s account to the outlet’s account will occur. In case of failures, the device will report that the transaction cannot be completed.

Such a database transaction is carried out online. Another type of offline operations is also possible, which are carried out by means of an imprinter that imprints the map.

Many users are interested in: is there an opportunity to cancel a transaction? If necessary, the bank can carry out certain manipulations to enable this.

Source: https://habr.com/ru/post/C44376/


All Articles