Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 61 additions & 70 deletions docs/guide/10-pg_clean.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,61 @@
# V2.3.0升级特性pg_clean使用说明

## 1. 安装 pg_clean 工具:
连接任意主CN:

```
CREATE EXTENSION pg_clean;
```

## 2. 构造两阶段事务残留用例:
session1—cn1

```
begin;
create table a (id int);
prepare transaction 'create_a';
set xc_maintenance_mode = on;
execute direct on (dn002) 'rollback prepared ''create_a''';
set xc_maintenance_mode = off;
\q
```

该用例中我们创建了一个gid为 'create\_a' 的两阶段事务,然后将 xc\_maintenance\_mode 打开,使得该事务仅在dn002中执行rollback。

## 3. 查找集群中两阶段事务残留:
session2—cn2

```
select * from pg_clean_check_txn();
```
![pg_clean_check_txn](images/v.2.3.0_pg_clean_check_txn.png)

上图打印出了集群中残留的两阶段事务。其中gid表示该事务的全局标识,global\_transaction\_status表示该事务在全局的状态,transaction\_status\_on\_allnodes表示该事务在所有节点中的状态。

## 4. 查看2PC残留文件名

查询节点cn1中数据目录pg_2pc下所有的2PC残留文件名

session1—cn1

```
postgres=# select * from pgxc_get_record_list();
pgxc_get_record_list
----------------------
create_a
(1 row)
```

## 5. 清理集群中两阶段事务残留:
session2—cn2

```
select * from pg_clean_execute();
```
![pg_clean_execute](images/v2.3.0_pg_clean_execute.png)

上图打印了所有残留的两阶段事务,以及对它们执行的操作。其中operation表示对事务在每个节点执行的操作,operation\_status表示该操作是否执行成功。由于该事务的全局事务状态为ABORT因此,我们去到每个状态为prepare的节点中对该事务执行rollback操作。

## 6. 检查已清理的两阶段事务是否残留文件记录:
session1—cn1

```
postgres=# select * from pgxc_get_record_list();
pgxc_get_record_list
----------------------

(1 row)
```

由于在上个步骤pg\_clean\_execute执行成功,因此已经回滚的事务'create_a'在所有节点的文件记录均已删除,这里我们在cn1查看所有2pc文件记录,显示为空,结果正确。
**Upgrade Features of pg_clean V2.3.0 Usage Guide**

1. Install the pg_clean tool:
Connect to any primary coordinator (CN):

```sql
CREATE EXTENSION pg_clean;
```

2. Create a two-phase transaction residue case:
Session 1—cn1

```sql
begin;
create table a (id int);
prepare transaction 'create_a';
set xc_maintenance_mode = on;
execute direct on (dn002) 'rollback prepared ''create_a''';
set xc_maintenance_mode = off;
\q
```

In this case, a two-phase transaction with a GID of 'create_a' is created. The `xc_maintenance_mode` is then turned on, allowing the transaction to execute a rollback only on dn002.

3. Find residual two-phase transactions in the cluster:
Session 2—cn2

```sql
select * from pg_clean_check_txn();
```

The output displays residual two-phase transactions in the cluster. GID represents the global identifier of the transaction, global_transaction_status indicates the global status of the transaction, and transaction_status_on_allnodes indicates the status of the transaction on all nodes.

4. View 2PC residue file names:
Query all 2PC residue file names in the data directory pg_2pc on node cn1:

Session 1—cn1

```sql
select * from pgxc_get_record_list();
```

The result will show the 'create_a' transaction.

5. Clean up residual two-phase transactions in the cluster:
Session 2—cn2

```sql
select * from pg_clean_execute();
```

The output displays all residual two-phase transactions and the operations performed on them. The operation column indicates the operation performed on the transaction on each node, and operation_status indicates whether the operation was successful. Since the global transaction status is ABORT, a rollback operation is performed on each node with a prepare status.

6. Check if the cleaned two-phase transactions still have residual file records:
Session 1—cn1

```sql
select * from pgxc_get_record_list();
```

After the successful execution of pg_clean_execute in the previous step, the 'create_a' transaction, which has been rolled back, should have no file records on all nodes. The result should be empty, confirming the correct outcome.