HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

Postgres inherit indexes for partitioned tables

Submitted by: @import:stackexchange-dba··
0
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:

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 CONCURRENTLY


And have the whole thing turn out to have created all of the indexes on the sub-tables.

Solution

As explained before, 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.