PostgreSQL 14新插件pg_surgery
Posted PostgreSQLChina
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PostgreSQL 14新插件pg_surgery相关的知识,希望对你有一定的参考价值。
作者:金涛
PostgreSQL新增extension pg_surgery, 提供了两个函数:
- heap_force_freeze - 强制要冻结tuple
- heap_force_kill - 强制删除tuple
jintao@jintao-ThinkPad-L490:~/personal/code/postgresql-master$ psql
psql (14devel)
Type 'help' for help.
mydb=# select version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 14devel on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit
(1 row)
mydb=# create extension pg_surgery ;
CREATE EXTENSION
mydb=#
mydb=# \\dx+ pg_surgery
Objects in extension 'pg_surgery'
Object description
--------------------------------------------
function heap_force_freeze(regclass,tid[])
function heap_force_kill(regclass,tid[])
(2 rows)
mydb=# create table test_surgery(id int);
CREATE TABLE
mydb=#
mydb=# insert into test_surgery select generate_series(1,5);
INSERT 0 5
mydb=#
mydb=# select xmin, ctid, id from test_surgery ;
xmin | ctid | id
------+-------+----
836 | (0,1) | 1
836 | (0,2) | 2
836 | (0,3) | 3
836 | (0,4) | 4
836 | (0,5) | 5
(5 rows)
mydb=# select heap_force_freeze('test_surgery'::regclass, array[ '(0,1)' ]::tid[]); /*freeze单个ctid*/
heap_force_freeze
-------------------
(1 row)
mydb=# select xmin, ctid, id from test_surgery ;
xmin | ctid | id
------+-------+----
2 | (0,1) | 1
836 | (0,2) | 2
836 | (0,3) | 3
836 | (0,4) | 4
836 | (0,5) | 5
(5 rows)
mydb=# select heap_force_freeze('test_surgery'::regclass, array[ '(0,2)', '(0,5)' ]::tid[]); /*freeze单个ctid*/
heap_force_freeze
-------------------
(1 row)
mydb=# select xmin, ctid, id from test_surgery ;
xmin | ctid | id
------+-------+----
2 | (0,1) | 1
2 | (0,2) | 2
836 | (0,3) | 3
836 | (0,4) | 4
2 | (0,5) | 5
(5 rows)
mydb=#
mydb=# select heap_force_kill('test_surgery'::regclass, array[ '(0,1)' ]::tid[]); /*删除单个ctid tuple */
heap_force_kill
-----------------
(1 row)
mydb=# select xmin, ctid, id from test_surgery ;
xmin | ctid | id
------+-------+----
2 | (0,2) | 2
836 | (0,3) | 3
836 | (0,4) | 4
2 | (0,5) | 5
(4 rows)
mydb=# select heap_force_kill('test_surgery'::regclass, array[ '(0,3)', '(0,5)' ]::tid[]); /*删除多个ctid tuple*/
heap_force_kill
-----------------
(1 row)
mydb=# select xmin, ctid, id from test_surgery ;
xmin | ctid | id
------+-------+----
2 | (0,2) | 2
836 | (0,4) | 4
(2 rows)
mydb=#
了解更多PostgreSQL热点资讯、新闻动态、精彩活动,请访问中国PostgreSQL官方网站:www.postgresqlchina.com
解决更多PostgreSQL相关知识、技术、工作问题,请访问中国PostgreSQL官方问答社区:www.pgfans.cn
下载更多PostgreSQL相关资料、工具、插件问题,请访问中国PostgreSQL官方下载网站:www.postgreshub.cn
以上是关于PostgreSQL 14新插件pg_surgery的主要内容,如果未能解决你的问题,请参考以下文章
PostgreSQL 14 版本发布,快来看看有哪些新特性!