15.4. Transactional Model #

This section describes the transactional model used in Postgres Pro AXE.

Working with analytical tables involves two databases: the current database and the metadata catalog database. For this reason, the transactional model differs from the one used in standard Postgres Pro.

15.4.1. Transactions and Analytical Tables #

A transaction in the metadata catalog database is created when the transaction in the current database first accesses an analytical table (not at the BEGIN command). The created transaction uses the catalog state recorded at the start, so all metadata reads until the end of the transaction come exactly from this state, even if other transactions modify the catalog in the meantime. This is not affected by the isolation level specified for the transaction in the current database.

Committing a transaction in the metadata catalog database uses the optimistic conflict resolution model. Each transaction that modifies metadata creates a new snapshot and assigns it the next number in sequence. Two transactions that start simultaneously can result in snapshots with the same number. At commit, the snapshot number is checked for uniqueness in the metadata catalog database. Therefore, the transaction that commits first always takes precedence.

The conflict resolution mechanism is triggered if two transactions in the metadata catalog database are assigned the same snapshot number: it compares the changes of the transaction that commits second with those already committed to the metadata catalog database. If the conflict is resolved successfully, the transaction repeats the commit with an increased snapshot number.

For more information on the two-phase commit, refer to Section 15.4.2.

15.4.2. Two-Phase Commit of Transactions #

A transaction that modifies both heap tables and analytical tables is committed in two phases automatically to ensure the atomicity of changes made to analytical tables and the metadata catalog. The same applies to transactions that execute DDL commands on analytical tables, since in this case system tables of Postgres Pro are also modified. Read-only transactions and transactions that modify only one type of the tables are committed in the usual way.

The two-phase commit proceeds as follows:

  1. The transaction is prepared in the metadata catalog database using the standard PREPARE TRANSACTION command. The prepared transaction itself is not visible to other transactions.

  2. The transaction is committed in the current database. If the commit is successful, the previously prepared transaction is also committed using the COMMIT PREPARED command. Otherwise, it is rolled back using the ROLLBACK PREPARED command.

As a result, all changes are either committed or rolled back.

Important

  • Two-phase commit requires the max_prepared_transactions configuration parameter to be set to a value greater than 0 on the server with the metadata catalog. With the default value of 0, the commit fails with an error.

  • Manually executing the PREPARE TRANSACTION command in transactions that modify analytical tables is not supported.

If the Postgres Pro AXE server fails between the preparation and the commit of the transaction, the transaction remains in the prepared state and keeps holding locks in the metadata catalog database. You can resolve such transactions using the axe.resolve_prepared_transactions stored procedure.

15.4.3. Resolving Prepared Transactions (axe.resolve_prepared_transactions) #

The axe.resolve_prepared_transactions stored procedure resolves transactions that remain in the prepared state in the metadata catalog database after a Postgres Pro AXE server failure. For more information, refer to Section 15.4.2.

For each prepared transaction, this procedure uses the status of the corresponding transaction in the current database to determine whether to commit or roll back the prepared transaction. Transactions associated with other Postgres Pro AXE clusters that share the same metadata catalog are skipped.

Important

Execute this stored procedure outside a transaction block, in the database where the failed transaction was executed.

Required privileges: Superuser or the Postgres Pro AXE administrator.

Execute the following command on the Postgres Pro AXE server after recovery:

  SELECT axe.resolve_prepared_transactions();

15.4.4. Data Visibility in Mixed Transactions #

Whether data is visible to a mixed transaction depends on the following factors:

  • Mixed transactions read the metadata catalog state recorded when they first access an analytical table, not the state from the start of the transaction in the current database.

    For more information, refer to Section 15.4.1.

  • During a two-phase commit, changes are committed to the current database first, and then to the metadata catalog database.

    For more information, refer to Section 15.4.2.

For this reason, data visibility can be inconsistent between the metadata catalog database and the current database when mixed transactions run in parallel.

15.4.5. Configuring the Transaction Horizon #

Although Postgres Pro AXE has its own snapshots, Postgres Pro snapshots are still used even for analytical queries that read data only from Parquet files and hold the transaction horizon. As a result, VACUUM cannot delete dead tuples from heap tables, which over time leads to table bloat and performance degradation.

To avoid holding the transaction horizon, Postgres Pro AXE provides the axe.use_postgres_snapshot configuration parameter. By default, the parameter is set to true, and a Postgres Pro snapshot is used for each query. When the parameter is set to false, any query that works with heap tables fails with an error. This ensures that only queries that do not work with heap tables are executed, and Postgres Pro snapshots are not used.

Important

With the axe.use_postgres_snapshot configuration parameter set to false, all queries, including analytical queries, fail with an error if none of the following conditions are met:

  • Queries are executed in transaction blocks with the READ COMMITTED isolation level.

  • Queries are executed in the autocommit mode, which implicitly wraps each statement in a transaction without explicit BEGIN and COMMIT commands.

These conditions ensure that queries can be safely executed without using Postgres Pro snapshots and holding the transaction horizon.

You can set the axe.use_postgres_snapshot configuration parameter for the current session or globally:

    -- For the current session --
    SET axe.use_postgres_snapshot TO false;

    -- Globally --
    ALTER SYSTEM SET axe.use_postgres_snapshot TO false;
  
FAQ