Greenplum partition table to view the Occupied Space

Source: Internet
Author: User

When using the greenplum database, the following two functions are used to check the space occupied by the table: pg_relation_size and pg_size_pretty.

The former is used to view the data size, and the latter is the adjustment of human readable. The method is as follows:

Select pg_size_pretty (pg_relation_size ('relation _ name '));

Select pg_size_pretty (pg_relation_size (OID ));

However, this method is useless for partitioned tables, and the table size is 0 bytes. the reason is that the main table of the GP partition table is only a table definition, and the actual data content is stored in the partition sub-table that inherits the parent table. I checked it online and did not find the corresponding function. I simply wrote a function to implement it.

 

-- Function: calc_partition_table (character varying, character varying)

-- Drop function calc_partition_table (character varying, character varying );

Create Or Replace Function Calc_partition_table (v_schemaname Character Varying , V_tablename Character Varying )
Returns Bigint As
$ Body $
Declare
V_calc Bigint : = 0 ;
V_total Bigint : = 0 ;
V_tbname Varchar ( 200 );
Cur_tbname Cursor For Select Schemaname | ' . ' | Partitiontablename As TB From Pg_partitions
Where Schemaname = V_schemaname And Tablename = V_tablename;
Begin
Open Cur_tbname;
Loop
Fetch Cur_tbname Into V_tbname;
If Not Found Then
Exit ;
End If ;
Execute ' Select pg_relation_size ( ''' | V_tbname | ''' ) ' Into V_calc;
V_total: = V_total + V_calc;
End Loop;
Close Cur_tbname;
Return V_total;
End ;
$ Body $
Language plpgsql volatile;
Alter Function Calc_partition_table ( Character Varying , Character Varying ) Owner To Gpadmin;

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.