Question

I have partitioned a table by a timestamp with timezone column. Then I added a partition and then added an index on that partition. Now it seems that Greenplum only uses that index after vacuum analyze TABLENAME. Otherwise it uses a sequential scan.

The drawback of vacuum analyze TABLENAME is that it takes quite long. It want to do a vacuum analyze PARTITIONTABLENAME because I know that the daily partitions for the last month have not changed anymore.

The question is: How do I get the partition table name for a specific value like current_timestamp? In other words: I would like access to the function that Greenplum uses to decide in which partition to put a new entry.

Was it helpful?

Solution

A partition in Greenplum is treated like any other table. If you have psql access you should be able to use the '\d' command to see all the tables you have have access to in your search_path. Each partiton of a larger table will display in that. Unless you explicity name the partitions, greenplum will just name them based on the parent table name with autoincrementing partition numbers:

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=#

To only vacuum the most recent partition, you could create a function that returns the table with the highest partition number:

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

And then pass that to vacuum analyze.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top