|
|
### 1.在数据库中开启了2PC事务,但不去管它,会有什么危害?
|
|
|
### 在数据库中开启了2PC事务,但不去管它,会有什么危害?
|
|
|
|
|
|
**①数据库使用预备事务**
|
|
|
|
... | ... | @@ -7,3 +7,27 @@ |
|
|

|
|
|
- 然后重启数据库,systemctl restart postgresql-11
|
|
|
|
|
|
**②实际测试**
|
|
|
```
|
|
|
create table t1(id int)
|
|
|
begin;
|
|
|
insert into t1 values (1);
|
|
|
prepare transaction 'a';
|
|
|
```
|
|
|
|
|
|
**③检查服务器状态**
|
|
|
```
|
|
|
select * from txid_current_snapshot();
|
|
|
select * from pg_prepared_xacts ;
|
|
|
```
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
**④危害**
|
|
|
- 膨胀,在vacuum时,这个事务不能被回收;即使vacuum full也无法回收。
|
|
|
- 年龄,年龄同样会受到威胁,最多只能降低到最早未提交的事务。
|
|
|
- 持锁,DDL不能进行
|
|
|
|
|
|
另外,基于流复制的备库,2PC事务也会复制过去。即使停库,切换到备机仍然存在。
|
|
|
必须监控起来,对于长时间不提交的prepared transaction,及时警告。 |
|
|
\ No newline at end of file |