If a system interruption such as a server failure occurs while high-speed data load is being performed, transactions prepared using this feature may be changed to the in-doubt state. At that point, resources occupied by the transaction will be locked, and access to the relevant resources from other transactions will be blocked, rendering them unusable.
In such cases, check transactions that are in an in-doubt state, and resolve them.
Checking for in-doubt transactions
This section describes how to check for in-doubt transactions.
Refer to the pgx_loader_state table in the pgx_loader schema.
Retrieve the global transaction identifier (gid column) of in-doubt transactions. In-doubt transactions will contain "rollback" in the column "state".
Example
The example below retrieves the global transaction identifier (gid) of in-doubt transactions performed by the database role myrole and that used table tbl. The retrieved global transaction identifiers pgx_loader:9589 and pgx_loader:9590 identify in-doubt transactions.
postgres=# SELECT gid, state FROM pgx_loader.pgx_loader_state WHERE postgres-# role_oid IN (SELECT oid FROM pg_roles WHERE rolname = 'myrole') AND postgres-# relation_oid IN (SELECT relid FROM pg_stat_all_tables WHERE postgres-# relname = 'tbl'); gid | state -----------------+------------- pgx_loader:9590 | rollback pgx_loader:9591 | commit pgx_loader:9589 | rollback (3 rows)
Refer to the pg_prepared_xacts system view.
Check if the in-doubt transactions retrieved above exist.
Example
The example below checks if in-doubt transactions with the global transaction identifiers pgx_loader:9589 and pgx_loader:9590 exist.
postgres=# SELECT gid FROM pg_prepared_xacts WHERE gid IN ('pgx_loader:9589','pgx_loader:9590'); gid ------------------ pgx_loader:9590 pgx_loader:9589 (2 rows)
See
Refer to "H.1 pgx_loader_state" for information on the pgx_loader_state table.
Resolving in-doubt transactions
Execute the pgx_loader command in recovery mode to resolve in-doubt transactions.
After executing the pgx_loader command in recovery mode, perform the procedure described in "Checking for in-doubt transactions" to check if the in-doubt transactions have been resolved.
Example
The example below completes the in-doubt transactions prepared for table tbl.
$ pgx_loader recovery -t tbl
Point
The recovery mode of the pgx_loader command only resolves transactions prepared by high-speed data load. For transactions prepared by an application using distributed transactions other than this feature, follow the procedure described in "17.13 Actions in Response to Error in a Distributed Transaction".