pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Euler Taveira <euler@eulerto.com>
To: gatekeeper.mail@gmail.com
To: pgsql-bugs@lists.postgresql.org
Subject:  Re: BUG #17211: Partitioned index partition does not inherit table partition tablespace
Date: Sat, 02 Oct 2021 11:33:00 -0300
Message-ID: <e517dd32-1892-41f0-8071-be663ffd6f05@www.fastmail.com> (raw)
In-Reply-To: <17211-838c26a1bc30a9db@postgresql.org>
References: <17211-838c26a1bc30a9db@postgresql.org>

On Fri, Oct 1, 2021, at 3:07 PM, PG Bug reporting form wrote:
> Suppose we have 2 tablespaces:
> pg_default (which is slow)
> fast
> 
> We also have a partitioned table:
> create table a (id serial not null, b int not null primary key, c int not
> null, d int) partition by hash (b);
> 
> and 2 partitions:
> create table a_1 partition of a for values with (modulus 2, remainder 0);
> create table a_2 partition of a for values with (modulus 2, remainder 1)
> tablespace fast;
> 
> This successfully allocates table a_2 pages within the 'fast' tablespace;
> but this fails to allocate a_2_pkey primary key index there too and the
> result is the index is allocated on tablespace oid(0) which means pg_default
> I guess, at least the corresponding relfilenode is allocated within the
> pg_default tablespace.
That's how it was designed. TABLESPACE clause at the end of CREATE TABLE set
the tablespace only for the table. The index is stored based on the
default_tablespace [1] value.

Since there is no way to specify USING INDEX TABLESPACE for partitions, you
should set default_tablespace to achieve what you want.

CREATE TABLE a (
  id serial NOT NULL,
  b int NOT NULL PRIMARY KEY,
  c int NOT NULL,
  d int
) PARTITION BY hash (b);

CREATE TABLE a_1 PARTITION OF a
FOR VALUES WITH (MODULUS 3, REMAINDER 0);

SET default_tablespace TO 'fast';

-- the TABLESPACE clause is not required
-- table -> fast ; index -> fast
CREATE TABLE a_2 PARTITION OF a
FOR VALUES WITH (MODULUS 3, REMAINDER 1) TABLESPACE fast;

-- table -> tablespace slow ; index -> tablespace fast
CREATE TABLE a_3 PARTITION OF a
FOR VALUES WITH (MODULUS 3, REMAINDER 2) TABLESPACE slow;

RESET default_tablespace;

[1] https://www.postgresql.org/docs/14/runtime-config-client.html#RUNTIME-CONFIG-CLIENT-STATEMENT


--
Euler Taveira
EDB   https://www.enterprisedb.com/

view thread (2+ messages)

Message-ID: <e517dd32-1892-41f0-8071-be663ffd6f05@www.fastmail.com>
Permalink:  ../e517dd32-1892-41f0-8071-be663ffd6f05@www.fastmail.com/
Also on:    postgresql.org/message-id/e517dd32-1892-41f0-8071-be663ffd6f05@www.fastmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: euler@eulerto.com, gatekeeper.mail@gmail.com
  Subject: Re: BUG #17211: Partitioned index partition does not inherit table partition tablespace
  In-Reply-To: <e517dd32-1892-41f0-8071-be663ffd6f05@www.fastmail.com>
  References: <17211-838c26a1bc30a9db@postgresql.org> <e517dd32-1892-41f0-8071-be663ffd6f05@www.fastmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox