ALTER DATABASE ... RENAME: permission denied for superuser

Lists: pgsql-bugs
From: "Alexander M(dot) Pravking" <fduch(at)antar(dot)bryansk(dot)ru>
To: pgsql-bugs(at)postgresql(dot)org
Subject: ALTER DATABASE ... RENAME: permission denied for superuser
Date: 2005-03-10 10:43:07
Message-ID: 20050310104307.GA24145@dyatel.antar.bryansk.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Docs say: Only the database owner or a superuser can rename a database;
non-superuser owners must also have the CREATEDB privilege.

Looks like a superuser must have CREATEDB too:

fduch(at)~=# SELECT usesuper, usecreatedb from pg_user where usename = 'fduch';
usesuper | usecreatedb
----------+-------------
t | f
(1 row)

fduch(at)~=# CREATE DATABASE test owner stat;
CREATE DATABASE
fduch(at)~=# ALTER DATABASE test RENAME TO work;
ERROR: permission denied to rename database
fduch(at)~=# ALTER DATABASE test OWNER TO fduch ;
ALTER DATABASE
fduch(at)~=# ALTER DATABASE test RENAME TO work;
ERROR: permission denied to rename database

At last:
fduch(at)~=# ALTER USER fduch CREATEDB ;
ALTER USER
fduch(at)~=# ALTER DATABASE test RENAME TO work;
ALTER DATABASE
fduch(at)~=# ALTER DATABASE work OWNER TO stat;
ALTER DATABASE
fduch(at)~=# ALTER DATABASE work RENAME TO test;
ALTER DATABASE

PostgreSQL 8.0.1 on i386-portbld-freebsd5.3, compiled by GCC cc (GCC) 3.4.2 [FreeBSD] 20040728

--
Fduch M. Pravking


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Alexander M(dot) Pravking" <fduch(at)antar(dot)bryansk(dot)ru>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: ALTER DATABASE ... RENAME: permission denied for superuser
Date: 2005-03-10 15:15:08
Message-ID: 15018.1110467708@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

"Alexander M. Pravking" <fduch(at)antar(dot)bryansk(dot)ru> writes:
> Docs say: Only the database owner or a superuser can rename a database;
> non-superuser owners must also have the CREATEDB privilege.

> Looks like a superuser must have CREATEDB too:

Yeah, the test in RenameDatabase is only looking at createdb and not at
superuserness. Seems like a bug to me --- or does anyone want to argue
that the code behavior is correct and the docs are wrong?

regards, tom lane


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: "Alexander M(dot) Pravking" <fduch(at)antar(dot)bryansk(dot)ru>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: ALTER DATABASE ... RENAME: permission denied for superuser
Date: 2005-03-12 21:30:12
Message-ID: 200503122130.j2CLUCw24472@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


Tom has fixed this bug and backpatched it back to 7.4.X.

---------------------------------------------------------------------------

Alexander M. Pravking wrote:
> Docs say: Only the database owner or a superuser can rename a database;
> non-superuser owners must also have the CREATEDB privilege.
>
> Looks like a superuser must have CREATEDB too:
>
> fduch(at)~=# SELECT usesuper, usecreatedb from pg_user where usename = 'fduch';
> usesuper | usecreatedb
> ----------+-------------
> t | f
> (1 row)
>
> fduch(at)~=# CREATE DATABASE test owner stat;
> CREATE DATABASE
> fduch(at)~=# ALTER DATABASE test RENAME TO work;
> ERROR: permission denied to rename database
> fduch(at)~=# ALTER DATABASE test OWNER TO fduch ;
> ALTER DATABASE
> fduch(at)~=# ALTER DATABASE test RENAME TO work;
> ERROR: permission denied to rename database
>
> At last:
> fduch(at)~=# ALTER USER fduch CREATEDB ;
> ALTER USER
> fduch(at)~=# ALTER DATABASE test RENAME TO work;
> ALTER DATABASE
> fduch(at)~=# ALTER DATABASE work OWNER TO stat;
> ALTER DATABASE
> fduch(at)~=# ALTER DATABASE work RENAME TO test;
> ALTER DATABASE
>
> PostgreSQL 8.0.1 on i386-portbld-freebsd5.3, compiled by GCC cc (GCC) 3.4.2 [FreeBSD] 20040728
>
>
> --
> Fduch M. Pravking
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073