patternsqlModerate
Postgres inherit indexes for partitioned tables
Viewed 0 times
tablespostgresindexesforinheritpartitioned
Problem
I have a table with approximately 60 million rows that I have partitioned by state into 53 sub-tables. These tables "inherit" the big table like so:
My question is this: if I do not build the indexes on b2b8 until after the copy statement completes, do the sub-tables inherit the indexes? In other words I want to do this:
And have the whole thing turn out to have created all of the indexes on the sub-tables.
CREATE TABLE b2b_ak (LIKE b2b including indexes, CHECK ( state = 'AK') ) INHERITS (b2b8) TABLESPACE B2B;My question is this: if I do not build the indexes on b2b8 until after the copy statement completes, do the sub-tables inherit the indexes? In other words I want to do this:
Create b2b8
Create b2b8_ak inherits b2b8
COPY b2b8 FROM bigcsvfile.csv
CREATE INDEX CONCURRENTLYAnd have the whole thing turn out to have created all of the indexes on the sub-tables.
Solution
As explained before,
Therefore, you need to state both inheritance and index copying.
Thank you, @dezso, for your remark.
INHERITS does not copy index definitions.Therefore, you need to state both inheritance and index copying.
CREATE TABLE sub_tab (LIKE tab INCLUDING ALL) INHERITS (tab);Thank you, @dezso, for your remark.
Code Snippets
CREATE TABLE sub_tab (LIKE tab INCLUDING ALL) INHERITS (tab);Context
StackExchange Database Administrators Q#80147, answer score: 12
Revisions (0)
No revisions yet.