Greenplum 中的分区被视为与任何其他表一样。如果您有 psql 访问权限,您应该能够使用 '\d' 命令查看您在 search_path 中有权访问的所有表。较大表的每个分区都将显示在其中。除非你明确命名分区,greenplum 只会根据父表名和自动递增的分区号命名它们:
gpadmin=# create table testtab (testcol varchar(10),
gpadmin(# test_time timestamptz)
gpadmin-# distributed by (testcol)
gpadmin-# partition by range (test_time)
gpadmin-# ( START (date '2013-10-01') INCLUSIVE
gpadmin(# END (date '2013-11-25') EXCLUSIVE
gpadmin(# EVERY (INTERVAL '1 week'));
NOTICE: CREATE TABLE will create partition "testtab_1_prt_1" for table "testtab"
NOTICE: CREATE TABLE will create partition "testtab_1_prt_2" for table "testtab"
NOTICE: CREATE TABLE will create partition "testtab_1_prt_3" for table "testtab"
NOTICE: CREATE TABLE will create partition "testtab_1_prt_4" for table "testtab"
NOTICE: CREATE TABLE will create partition "testtab_1_prt_5" for table "testtab"
NOTICE: CREATE TABLE will create partition "testtab_1_prt_6" for table "testtab"
NOTICE: CREATE TABLE will create partition "testtab_1_prt_7" for table "testtab"
NOTICE: CREATE TABLE will create partition "testtab_1_prt_8" for table "testtab"
CREATE TABLE
Time: 252.080 ms
gpadmin=#
要仅清理最近的分区,您可以创建一个返回具有最高分区号的表的函数:
gpadmin=# select tablename from pg_tables
gpadmin-# where tablename like 'testtab_1_prt_%'
gpadmin-# order by tablename desc limit 1;
tablename
-----------------
testtab_1_prt_8
(1 row)
Time: 89.151 ms
然后将其传递给真空分析。