Re: unlogged sequences

From: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
To: Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: unlogged sequences
Date: 2022-04-01 16:22:38
Message-ID: c1813175-f2dd-ef01-a59e-2e940b1fbb9e@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 01.04.22 00:43, Tomas Vondra wrote:
> Hmm, so what about doing a little bit different thing:
>
> 1) owned sequences inherit persistence of the table by default
>
> 2) allow ALTER SEQUENCE to change persistence for all sequences (no
> restriction for owned sequences)
>
> 3) ALTER TABLE ... SET [UN]LOGGED changes persistence for sequences
> matching the initial table persistence

Consider that an identity sequence creates an "internal" dependency and
a serial sequence creates an "auto" dependency.

An "internal" dependency means that the internal object shouldn't really
be operated on directly. (In some cases it's allowed for convenience.)
So I think in that case the sequence must follow the table's persistence
in all cases. This is accomplished by setting the initial persistence
to the table's, making ALTER TABLE propagate persistence changes, and
prohibiting direct ALTER SEQUENCE SET.

An "auto" dependency is looser, so manipulating both objects
independently can be allowed. In that case, I would do (1), (2), and (3).

(I think your (3) is already the behavior in the patch, since there are
only two persistence levels in play at that point.)

I wanted to check if you can have a persistent sequence owned by a temp
table, but that is rejected because both sequence and table must be in
the same schema. So the sequence owned-by schema does insist on some
tight coupling. So for example, once a sequence is owned by a table,
you can't move it around or change the ownership.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2022-04-01 16:31:26 Re: unlogged sequences
Previous Message Julien Rouhaud 2022-04-01 16:13:21 Re: [PATCH] Tracking statements entry timestamp in pg_stat_statements