PostgreSQLのDBA(39) - パーティションのPG 12個の機能

でPG 12の以前のバージョンは、そのようなあなたがpg_partition_treeとpg_partition_rootシステム機能にPG 12を追加し、直感的で扱いにくい、スクリプトを取得するには、再帰CTEクエリを使用する必要があるパーティションテーブルにパーティションおよびサブパーティションなどの情報を取得するためには、パーティションツリーを取得するために使用されていますそして、関係のルートパーティション。

ここでは簡単な例を説明します。

テストスクリプト

- ハッシュPartitiondropテーブルならt_hash1存在し、テーブルt_hash1(C1 INT nullでない、C2のvarchar(40)、C3 VARCHAR(40))ハッシュによってパーティション(C1)を作成する;  - (と値についてt_hash1のレベル1createテーブルt_hash1_1パーティションをハッシュ(C1によってモジュラス6、余り0)パーティション)、ハッシュ(C1)で持つ値(係数6、残り1)パーティションのt_hash1のテーブルt_hash1_2パーティションを作成し;(モジュラス6、残りの値に対するt_hash1のテーブルt_hash1_3パーティションを作成2);(モジュラス6、残り3)との値のt_hash1のテーブルt_hash1_4パーティションを作成し;(モジュラス6、残り4)との値のt_hash1のテーブルt_hash1_5パーティションを作成し;(モジュラス6と値についてt_hash1のテーブルt_hash1_6パーティションを作成し、残り5);  - (係数2、余り0)との値についてt_hash1_1のレベル2createテーブルt_hash1_1_1パーティション。(係数2、余り1)との値についてt_hash1_1のテーブルt_hash1_1_2パーティションを作成し;(モジュラス2、余り0)と値についてt_hash1_2のテーブルt_hash1_2_1パーティションを作成し;(モジュラス2、残り1)と値についてt_hash1_2のテーブルt_hash1_2_2パーティションを作成;

サブパーティションは、それぞれ、2つのパーティション、パーティションテーブルt_hash1_2のt_hash1_1あり、前記t_hash1ハッシュは、サブパーティション6があり、パーティションテーブルです。

鄭州不妊病院ます。http://byby.zztjyy.com/yiyuanzaixian/zztjyy//

PG 11では、パーティションの詳細については、再帰CTEクエリを使用する必要があります。

relispartition  - 分区表标记)SELECT * FROM partition_info。RELID | relname | relsize | relispartition | relkind ------- + ------------- + --------- + ---------------- + --------- 57457 | t_hash1 | 0 | F | p個の57466 | t_hash1_3 | 0 | トン| Rの57469 | t_hash1_4 | 0 | トン| Rの57472 | t_hash1_5 | 0 | トン| Rの57475 | t_hash1_6 | 0 | トン| Rの57460 | t_hash1_1 | 0 | トン| p個の57463 | t_hash1_2 | 0 | トン| p個の57487 | t_hash1_2_2 | 0 | トン| Rの57478 | t_hash1_1_1 | 0 | トン| Rの57481 | t_hash1_1_2 | 0 | トン| Rの57484 | t_hash1_2_1 | 0 | トン| R(11行)RELID | relname | relsize | relispartition | relkind ------- + ------------- + --------- + ---------------- + --------- 57457 | t_hash1 | 0 | F | p個の57466 | t_hash1_3 | 0 | トン| Rの57469 | t_hash1_4 | 0 | トン| Rの57472 | t_hash1_5 | 0 | トン| Rの57475 | t_hash1_6 | 0 | トン| Rの57460 | t_hash1_1 | 0 | トン| p個の57463 | t_hash1_2 | 0 | トン| p個の57487 | t_hash1_2_2 | 0 | トン| Rの57478 | t_hash1_1_1 | 0 | トン| Rの57481 | t_hash1_1_2 | 0 | トン| Rの57484 | t_hash1_2_1 | 0 | トン| R(11行)RELID | relname | relsize | relispartition | relkind ------- + ------------- + --------- + ---------------- + --------- 57457 | t_hash1 | 0 | F | p個の57466 | t_hash1_3 | 0 | トン| Rの57469 | t_hash1_4 | 0 | トン| Rの57472 | t_hash1_5 | 0 | トン| Rの57475 | t_hash1_6 | 0 | トン| Rの57460 | t_hash1_1 | 0 | トン| p個の57463 | t_hash1_2 | 0 | トン| p個の57487 | t_hash1_2_2 | 0 | トン| Rの57478 | t_hash1_1_1 | 0 | トン| Rの57481 | t_hash1_1_2 | 0 | トン| Rの57484 | t_hash1_2_1 | 0 | トン| R(11行)72 | t_hash1_5 | 0 | トン| Rの57475 | t_hash1_6 | 0 | トン| Rの57460 | t_hash1_1 | 0 | トン| p個の57463 | t_hash1_2 | 0 | トン| p個の57487 | t_hash1_2_2 | 0 | トン| Rの57478 | t_hash1_1_1 | 0 | トン| Rの57481 | t_hash1_1_2 | 0 | トン| Rの57484 | t_hash1_2_1 | 0 | トン| R(11行)72 | t_hash1_5 | 0 | トン| Rの57475 | t_hash1_6 | 0 | トン| Rの57460 | t_hash1_1 | 0 | トン| p個の57463 | t_hash1_2 | 0 | トン| p個の57487 | t_hash1_2_2 | 0 | トン| Rの57478 | t_hash1_1_1 | 0 | トン| Rの57481 | t_hash1_1_2 | 0 | トン| Rの57484 | t_hash1_2_1 | 0 | トン| R(11行)

PG 12において、システム機能は、情報を取得するために直接使用することができます。

ます。testdb =#\ SF pg_partition_treeCREATEまたは関数pg_catalog.pg_partition_tree(OUTブール、OUTレベルの整数のisLeaf rootrelid regclassデータ、OUT RELID regclassデータ、OUT parentrelid regclassデータを、)REPLACE SETOFレコードLANGUAGE内部PARALLEL SAFE STRICTAS $関数$ pg_partition_treeの$関数を返します$ます。testdb =#選択pg_partition_tree( 't_hash1'); pg_partition_tree -----------------------------(t_hash1、F、0)(t_hash1_1、t_hash1、F、1)(t_hash1_2、 t_hash1、F、1)(t_hash1_3、t_hash1、T、1)(t_hash1_4、t_hash1、T、1)(t_hash1_5、t_hash1、T、1)(t_hash1_6、t_hash1、T、1)(t_hash1_1_1、t_hash1_1、T、2 )(t_hash1_1_2、t_hash1_1、T、2)(t_hash1_2_1、t_hash1_2、T、2)(t_hash1_2_2、t_hash1_2、T、2)(11行)

情報が返されています 
RELID - >パーティションRELIDの 
parentrelid - >親パーティション 
のisLeaf - >リーフノードの場合は 
レベル- >レベル

通过pg_partition_root可以获取分区表的root节点

testdb=# \sf pg_partition_rootCREATE OR REPLACE FUNCTION pg_catalog.pg_partition_root(regclass) RETURNS regclass LANGUAGE internal IMMUTABLE PARALLEL SAFE STRICTAS $function$pg_partition_root$function$testdb=# select pg_partition_root('t_hash1_2_2'); pg_partition_root ------------------- t_hash1(1 row)

参考资料 
Postgres 12 highlight - Functions for partitions


おすすめ

転載: blog.51cto.com/14339005/2412111