public inbox for [email protected]  
help / color / mirror / Atom feed
From: [email protected]
To: Laurenz Albe <[email protected]>
Cc: Daniel Gustafsson <[email protected]>
Cc: pgsql-docs <[email protected]>
Subject: Re: SQL command : ALTER DATABASE OWNER TO
Date: Wed, 24 Jan 2024 17:23:04 +0100 (CET)
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <2023185982.281851219.1646733038464.JavaMail.root@zimbra15-e2.priv.proxad.net>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>

----- Mail original -----
De: "Laurenz Albe" <[email protected]>
À: "gparc" <[email protected]>, "Daniel Gustafsson" <[email protected]>
Cc: "pgsql-docs" <[email protected]>
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, [email protected] 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





reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: SQL command : ALTER DATABASE OWNER TO
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox