Re: SQL command : ALTER DATABASE OWNER TO - Mailing list pgsql-docs

From gparc@free.fr
Subject Re: SQL command : ALTER DATABASE OWNER TO
Date
Msg-id 176777248.214045315.1706113384094.JavaMail.zimbra@free.fr
Whole thread Raw
In response to Re: SQL command : ALTER DATABASE OWNER TO  (Laurenz Albe <laurenz.albe@cybertec.at>)
Responses Re: SQL command : ALTER DATABASE OWNER TO
List pgsql-docs
----- Mail original -----
De: "Laurenz Albe" <laurenz.albe@cybertec.at>
À: "gparc" <gparc@free.fr>, "Daniel Gustafsson" <daniel@yesql.se>
Cc: "pgsql-docs" <pgsql-docs@lists.postgresql.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@free.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@PGDEV14] postgres=# create user tst password 'tst';
CREATE ROLE
[postgres@PGDEV14] postgres=# create database tst owner = tst;
CREATE DATABASE
[postgres@PGDEV14] postgres=# grant all on database tst to tst;
GRANT
[postgres@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@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@PGDEV14] tst=> create schema tst;
CREATE SCHEMA
[tst@PGDEV14] tst=> create table t1 (x int);
CREATE TABLE
[tst@PGDEV14] tst=> \dn+ tst
                 Liste des schémas
 Nom | Propriétaire | Droits d'accès | Description
-----+--------------+----------------+-------------
 tst | tst          |                |
(1 ligne)

[tst@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@PGDEV14] tst=> \c - postgres
Vous êtes maintenant connecté à la base de données « tst » en tant qu'utilisateur « postgres ».
[postgres@PGDEV14] tst=# alter database tst owner to postgres;
ALTER DATABASE
[postgres@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@PGDEV14] tst=# \dn+ tst
                 Liste des schémas
 Nom | Propriétaire | Droits d'accès | Description
-----+--------------+----------------+-------------
 tst | tst          |                |
(1 ligne)

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

Regards
Gilles



pgsql-docs by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: SQL command : ALTER DATABASE OWNER TO
Next
From: "David G. Johnston"
Date:
Subject: Re: SQL command : ALTER DATABASE OWNER TO