Fwd: Re: handle tablespaces for partitioned tables during ALTER DATABASE

From: postgres(at)jasonk(dot)me
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Fwd: Re: handle tablespaces for partitioned tables during ALTER DATABASE
Date: 2020-03-25 03:31:32
Message-ID: 20200325033132.qxynad5prj7pw4ml@jasonk.me
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

(Forgot to CC pgsql-bugs.)

Jason

----- Forwarded message from postgres(at)jasonk(dot)me -----

Date: Tue, 24 Mar 2020 14:24:33 -0700
From: postgres(at)jasonk(dot)me
To: Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: handle tablespaces for partitioned tables during ALTER DATABASE
Message-ID: <20200324212433(dot)3knuzvcpc3idjm2b(at)jasonk(dot)me>
References: <20200324062608(dot)dstxvn7zmnpmplxr(at)jasonk(dot)me>
<20200324192359(dot)yw7q5rlfqqxoktl6(at)alap3(dot)anarazel(dot)de>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20200324192359(dot)yw7q5rlfqqxoktl6(at)alap3(dot)anarazel(dot)de>

Hi, Andres.

On 2020-03-24T12:23:59-0700, Andres Freund wrote:
> I don't immediately see what problem this could cause? There's no
> physical file associated with a partitioned table, it's "just" a
> template for new partitions of that partitioned table.

I had illustrated a plausible scenario where this could be _unexpected_. The
state that you can get into after the first `ALTER DATABASE` is strange because
the tablespace of `scores_rank_0_to_100` is not `InvalidOid` yet equal to the
database's tablespace.

You can't get into this state normally: try

```sql
CREATE DATABASE f TABLESPACE fast;
\c f
CREATE TABLE t (i int, j int) PARTITION BY RANGE (i);
CREATE TABLE t0 PARTITION OF t FOR VALUES FROM (0) TO (100) TABLESPACE fast;
SELECT relname, reltablespace FROM pg_class WHERE relname LIKE 't0';
```

```
relname | reltablespace
---------+---------------
t0 | 0
(1 row)
```

Notice that it's `InvalidOid`, not the explicit database's tablespace. But you
can get into that state with some work, like I illustrated in my example in the
first message.

For less confusion, I think it makes sense to prohibit this or seamlessly
convert the appropriate `reltablespace` values to `InvalidOid`. Enforcing this
may also give me less things to worry about for my own work.

Jason

----- End forwarded message -----

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Sandeep Thakkar 2020-03-25 05:06:24 Re: BUG #16310: Database Cluster Initialization failed while installing postgres
Previous Message Andres Freund 2020-03-24 19:23:59 Re: handle tablespaces for partitioned tables during ALTER DATABASE