Re: SQL command : ALTER DATABASE OWNER TO

From: gparc(at)free(dot)fr
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: 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:23:04
Message-ID: 176777248.214045315.1706113384094.JavaMail.zimbra@free.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

----- Mail original -----
De: "Laurenz Albe" <laurenz(dot)albe(at)cybertec(dot)at>
À: "gparc" <gparc(at)free(dot)fr>, "Daniel Gustafsson" <daniel(at)yesql(dot)se>
Cc: "pgsql-docs" <pgsql-docs(at)lists(dot)postgresql(dot)org>
Envoyé: Mercredi 24 Janvier 2024 16:35:10
Objet: Re: SQL command : ALTER DATABASE OWNER TO

On Wed, 2024-01-24 at 15:40 +0100, gparc(at)free(dot)fr wrote:
> maybe a misunderstanding of my part, but your proposed modification doesn't matched
> with the current behaviour of the command as precisely the object privileges of the old owner are **NOT** transferred
> to the new owner along with the ownership

But that is what happens.

The permissions are transferred to the new owner, so the old owner doesn't
have any privileges on the object (and, in your case, cannot connect to
the database any more).

Yours,
Laurenz Albe

Laurenz,
may be better with an example to explain what I mean with "the old database owner loses all his privileges on it (even connection) although it might
still owns schemas or objects (tables, index,...) inside it"

[postgres] $ psql
psql (14.10)

[postgres(at)PGDEV14] postgres=# create user tst password 'tst';
CREATE ROLE
[postgres(at)PGDEV14] postgres=# create database tst owner = tst;
CREATE DATABASE
[postgres(at)PGDEV14] postgres=# grant all on database tst to tst;
GRANT
[postgres(at)PGDEV14] postgres=# \l+ tst
Liste des bases de données
Nom | Propriétaire | Encodage | Collationnement | Type caract. | Droits d'accès | Taille | Tablespace | Description
-----+--------------+----------+-----------------+--------------+----------------+---------+------------+-------------
tst | tst | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 | =Tc/tst +| 9809 kB | pg_default |
| | | | | tst=CTc/tst | | |
(1 ligne)

[postgres(at)PGDEV14] postgres=# \c tst tst
Mot de passe pour l'utilisateur tst :
Vous êtes maintenant connecté à la base de données « tst » en tant qu'utilisateur « tst ».
[tst(at)PGDEV14] tst=> create schema tst;
CREATE SCHEMA
[tst(at)PGDEV14] tst=> create table t1 (x int);
CREATE TABLE
[tst(at)PGDEV14] tst=> \dn+ tst
Liste des schémas
Nom | Propriétaire | Droits d'accès | Description
-----+--------------+----------------+-------------
tst | tst | |
(1 ligne)

[tst(at)PGDEV14] tst=> \dt+ t1
Liste des relations
Schéma | Nom | Type | Propriétaire | Persistence | Méthode d'accès | Taille | Description
--------+-----+-------+--------------+-------------+-----------------+---------+-------------
tst | t1 | table | tst | permanent | heap | 0 bytes |
(1 ligne)

[tst(at)PGDEV14] tst=> \c - postgres
Vous êtes maintenant connecté à la base de données « tst » en tant qu'utilisateur « postgres ».
[postgres(at)PGDEV14] tst=# alter database tst owner to postgres;
ALTER DATABASE
[postgres(at)PGDEV14] tst=# \l+ tst
Liste des bases de données
Nom | Propriétaire | Encodage | Collationnement | Type caract. | Droits d'accès | Taille | Tablespace | Description
-----+--------------+----------+-----------------+--------------+-----------------------+---------+------------+-------------
tst | postgres | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 | =Tc/postgres +| 9809 kB | pg_default |
| | | | | postgres=CTc/postgres | | |
(1 ligne)

[postgres(at)PGDEV14] tst=# \dn+ tst
Liste des schémas
Nom | Propriétaire | Droits d'accès | Description
-----+--------------+----------------+-------------
tst | tst | |
(1 ligne)

[postgres(at)PGDEV14] tst=# \dt tst.t1
Liste des relations
Schéma | Nom | Type | Propriétaire
--------+-----+-------+--------------
tst | t1 | table | tst
(1 ligne)

Regards
Gilles

In response to

Responses

Browse pgsql-docs by date

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