1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-07 00:36:50 +03:00

psql \dP: list partitioned tables and indexes

The new command lists partitioned relations (tables and/or indexes),
possibly with their sizes, possibly including partitioned partitions;
their parents (if not top-level); if indexes show the tables they belong
to; and their descriptions.

While there are various possible improvements to this, having it in this
form is already a great improvement over not having any way to obtain
this report.

Author: Pavel Stěhule, with help from Mathias Brossard, Amit Langote and
	Justin Pryzby.
Reviewed-by: Amit Langote, Mathias Brossard, Melanie Plageman,
	Michaël Paquier, Álvaro Herrera
This commit is contained in:
Alvaro Herrera
2019-04-07 07:59:12 -04:00
parent 159970bcad
commit 1c5d9270e3
8 changed files with 495 additions and 2 deletions

View File

@ -4598,3 +4598,134 @@ last error message: division by zero
\echo 'last error code:' :LAST_ERROR_SQLSTATE
last error code: 22012
\unset FETCH_COUNT
create schema testpart;
create role testrole_partitioning;
alter schema testpart owner to testrole_partitioning;
set role to testrole_partitioning;
-- run test inside own schema and hide other partitions
set search_path to testpart;
create table testtable_apple(logdate date);
create table testtable_orange(logdate date);
create index testtable_apple_index on testtable_apple(logdate);
create index testtable_orange_index on testtable_orange(logdate);
create table testpart_apple(logdate date) partition by range(logdate);
create table testpart_orange(logdate date) partition by range(logdate);
create index testpart_apple_index on testpart_apple(logdate);
create index testpart_orange_index on testpart_orange(logdate);
-- only partition related object should be displayed
\dP test*apple*
List of partitioned relations
Schema | Name | Owner | Type | Parent name | On table
----------+----------------------+-----------------------+-------------------+-------------+----------------
testpart | testpart_apple | testrole_partitioning | partitioned table | |
testpart | testpart_apple_index | testrole_partitioning | partitioned index | | testpart_apple
(2 rows)
\dPt test*apple*
List of partitioned tables
Schema | Name | Owner | Parent name
----------+----------------+-----------------------+-------------
testpart | testpart_apple | testrole_partitioning |
(1 row)
\dPi test*apple*
List of partitioned indexes
Schema | Name | Owner | Parent name | On table
----------+----------------------+-----------------------+-------------+----------------
testpart | testpart_apple_index | testrole_partitioning | | testpart_apple
(1 row)
drop table testtable_apple;
drop table testtable_orange;
drop table testpart_apple;
drop table testpart_orange;
create table parent_tab (id int) partition by range (id);
create index parent_index on parent_tab (id);
create table child_0_10 partition of parent_tab
for values from (0) to (10);
create table child_10_20 partition of parent_tab
for values from (10) to (20);
create table child_20_30 partition of parent_tab
for values from (20) to (30);
insert into parent_tab values (generate_series(0,29));
create table child_30_40 partition of parent_tab
for values from (30) to (40)
partition by range(id);
create table child_30_35 partition of child_30_40
for values from (30) to (35);
create table child_35_40 partition of child_30_40
for values from (35) to (40);
insert into parent_tab values (generate_series(30,39));
\dPt
List of partitioned tables
Schema | Name | Owner
----------+------------+-----------------------
testpart | parent_tab | testrole_partitioning
(1 row)
\dPi
List of partitioned indexes
Schema | Name | Owner | On table
----------+--------------+-----------------------+------------
testpart | parent_index | testrole_partitioning | parent_tab
(1 row)
\dP testpart.*
List of partitioned relations
Schema | Name | Owner | Type | Parent name | On table
----------+--------------------+-----------------------+-------------------+--------------+-------------
testpart | parent_tab | testrole_partitioning | partitioned table | |
testpart | child_30_40 | testrole_partitioning | partitioned table | parent_tab |
testpart | parent_index | testrole_partitioning | partitioned index | | parent_tab
testpart | child_30_40_id_idx | testrole_partitioning | partitioned index | parent_index | child_30_40
(4 rows)
\dP
List of partitioned relations
Schema | Name | Owner | Type | On table
----------+--------------+-----------------------+-------------------+------------
testpart | parent_tab | testrole_partitioning | partitioned table |
testpart | parent_index | testrole_partitioning | partitioned index | parent_tab
(2 rows)
\dPtn
List of partitioned tables
Schema | Name | Owner | Parent name
----------+-------------+-----------------------+-------------
testpart | parent_tab | testrole_partitioning |
testpart | child_30_40 | testrole_partitioning | parent_tab
(2 rows)
\dPin
List of partitioned indexes
Schema | Name | Owner | Parent name | On table
----------+--------------------+-----------------------+--------------+-------------
testpart | parent_index | testrole_partitioning | | parent_tab
testpart | child_30_40_id_idx | testrole_partitioning | parent_index | child_30_40
(2 rows)
\dPn
List of partitioned relations
Schema | Name | Owner | Type | Parent name | On table
----------+--------------------+-----------------------+-------------------+--------------+-------------
testpart | parent_tab | testrole_partitioning | partitioned table | |
testpart | child_30_40 | testrole_partitioning | partitioned table | parent_tab |
testpart | parent_index | testrole_partitioning | partitioned index | | parent_tab
testpart | child_30_40_id_idx | testrole_partitioning | partitioned index | parent_index | child_30_40
(4 rows)
\dPn testpart.*
List of partitioned relations
Schema | Name | Owner | Type | Parent name | On table
----------+--------------------+-----------------------+-------------------+--------------+-------------
testpart | parent_tab | testrole_partitioning | partitioned table | |
testpart | child_30_40 | testrole_partitioning | partitioned table | parent_tab |
testpart | parent_index | testrole_partitioning | partitioned index | | parent_tab
testpart | child_30_40_id_idx | testrole_partitioning | partitioned index | parent_index | child_30_40
(4 rows)
drop table parent_tab cascade;
drop schema testpart;
set search_path to default;
set role to default;
drop role testrole_partitioning;

View File

@ -1046,3 +1046,72 @@ select 1/(15-unique2) from tenk1 order by unique2 limit 19;
\echo 'last error code:' :LAST_ERROR_SQLSTATE
\unset FETCH_COUNT
create schema testpart;
create role testrole_partitioning;
alter schema testpart owner to testrole_partitioning;
set role to testrole_partitioning;
-- run test inside own schema and hide other partitions
set search_path to testpart;
create table testtable_apple(logdate date);
create table testtable_orange(logdate date);
create index testtable_apple_index on testtable_apple(logdate);
create index testtable_orange_index on testtable_orange(logdate);
create table testpart_apple(logdate date) partition by range(logdate);
create table testpart_orange(logdate date) partition by range(logdate);
create index testpart_apple_index on testpart_apple(logdate);
create index testpart_orange_index on testpart_orange(logdate);
-- only partition related object should be displayed
\dP test*apple*
\dPt test*apple*
\dPi test*apple*
drop table testtable_apple;
drop table testtable_orange;
drop table testpart_apple;
drop table testpart_orange;
create table parent_tab (id int) partition by range (id);
create index parent_index on parent_tab (id);
create table child_0_10 partition of parent_tab
for values from (0) to (10);
create table child_10_20 partition of parent_tab
for values from (10) to (20);
create table child_20_30 partition of parent_tab
for values from (20) to (30);
insert into parent_tab values (generate_series(0,29));
create table child_30_40 partition of parent_tab
for values from (30) to (40)
partition by range(id);
create table child_30_35 partition of child_30_40
for values from (30) to (35);
create table child_35_40 partition of child_30_40
for values from (35) to (40);
insert into parent_tab values (generate_series(30,39));
\dPt
\dPi
\dP testpart.*
\dP
\dPtn
\dPin
\dPn
\dPn testpart.*
drop table parent_tab cascade;
drop schema testpart;
set search_path to default;
set role to default;
drop role testrole_partitioning;