Re: SQL command : ALTER DATABASE OWNER TO

From: gparc(at)free(dot)fr
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Daniel Gustafsson <daniel(at)yesql(dot)se>, pgsql-docs <pgsql-docs(at)lists(dot)postgresql(dot)org>
Subject: Re: SQL command : ALTER DATABASE OWNER TO
Date: 2024-01-24 16:41:29
Message-ID: 1318833190.214290217.1706114489204.JavaMail.zimbra@free.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs


De: "David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
À: "Laurenz Albe" <laurenz(dot)albe(at)cybertec(dot)at>
Cc: "gparc" <gparc(at)free(dot)fr>, "Daniel Gustafsson" <daniel(at)yesql(dot)se>, "pgsql-docs" <pgsql-docs(at)lists(dot)postgresql(dot)org>
Envoyé: Mercredi 24 Janvier 2024 17:36:43
Objet: Re: SQL command : ALTER DATABASE OWNER TO

On Wed, Jan 24, 2024 at 9:13 AM Laurenz Albe < [ mailto:laurenz(dot)albe(at)cybertec(dot)at | laurenz(dot)albe(at)cybertec(dot)at ] > wrote:

On Wed, 2024-01-24 at 08:47 -0700, David G. Johnston wrote:
> I dislike this change, ownership of an object is completely independent of
> the grant system of privileges. The granted privileges of the old row do
> not transfer to the new owner when alter ... owner to is executed.

CREATE TABLE mytab ();

REVOKE ALL ON mytab FROM PUBLIC;

\z mytab
Access privileges
Schema │ Name │ Type │ Access privileges │ Column privileges │ Policies
════════╪═══════╪═══════╪═══════════════════════════╪═══════════════════╪══════════
public │ mytab │ table │ postgres=arwdDxt/postgres │ │
(1 row)

ALTER TABLE mytab OWNER TO laurenz;

\z mytab
Access privileges
Schema │ Name │ Type │ Access privileges │ Column privileges │ Policies
════════╪═══════╪═══════╪═════════════════════════╪═══════════════════╪══════════
public │ mytab │ table │ laurenz=arwdDxt/laurenz │ │
(1 row)

You need to actually revoke something to make the point stand out.

postgres=# \z tt1
Access privileges
Schema | Name | Type | Access privileges | Column privileges | Policies
--------+------+-------+-----------------------+-------------------+----------
public | tt1 | table | davidj=arwdDxt/davidj | |
(1 row)
postgres=# revoke update on tt1 from davidj;
REVOKE
postgres=# \z tt1
Access privileges
Schema | Name | Type | Access privileges | Column privileges | Policies
--------+------+-------+----------------------+-------------------+----------
public | tt1 | table | davidj=ardDxt/davidj | |
(1 row)

postgres=# alter table tt1 owner to testowner;
ALTER TABLE
postgres=# \z tt1
Access privileges
Schema | Name | Type | Access privileges | Column privileges | Policies
--------+------+-------+----------------------------+-------------------+----------
public | tt1 | table | testowner=ardDxt/testowner | |
(1 row)

The new owner, testowner, is missing the same update privilege that davidj removed from himself. In short, setting owner does indeed cause explicit grants to appear in the system, grants that can be revoked. And so, yes, transferring ownership transfers the set of grants currently in effect for the existing owner.

I can see making this detail more clear in the DDL chapter. It is unrelated to the confusion behind the topic of this thread though.

David J.

Hello again,
note that my point concerns "alter database" not "alter table".
See my last reply for an example

Regards

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message David G. Johnston 2024-01-24 16:50:17 Re: SQL command : ALTER DATABASE OWNER TO
Previous Message David G. Johnston 2024-01-24 16:36:43 Re: SQL command : ALTER DATABASE OWNER TO