pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
changing ownership of db
5+ messages / 4 participants
[nested] [flat]

* changing ownership of db
@ 2003-07-29 16:56  Benjamin Thelen (CCGIS) <thelen@ccgis.de>
  0 siblings, 1 reply; 5+ messages in thread

From: Benjamin Thelen (CCGIS) @ 2003-07-29 16:56 UTC (permalink / raw)
  To: pgsql-admin

hello,

I would like to change the ownership of a database. The only thing I 
could find up to now, is that it is difficult, but I couldn't find any 
detailed help.

Does anybody know how to do this!?

Probably create a dump, then create a new db, then import all the data?

thanks in advance,
Benjamin







^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: changing ownership of db
@ 2003-07-29 17:23  Devrim GUNDUZ <devrim@gunduz.org>
  parent: Benjamin Thelen (CCGIS) <thelen@ccgis.de>
  0 siblings, 2 replies; 5+ messages in thread

From: Devrim GUNDUZ @ 2003-07-29 17:23 UTC (permalink / raw)
  To: Benjamin Thelen (CCGIS) <thelen@ccgis.de>; +Cc: pgsql-admin


Hi,

On Tue, 29 Jul 2003, Benjamin Thelen (CCGIS) wrote:

> I would like to change the ownership of a database. The only thing I 
> could find up to now, is that it is difficult, but I couldn't find any 
> detailed help.

Connect to that database via psql. 

Then, first, update pg_database:

UPDATE pg_database SET datdba=(SELECT usesysid FROM pg_shadow WHERE 
usename='new_owner') WHERE datname='db_name';

If you also want to change the owner of the tables, update pg_class:

UPDATE pg_class SET relowner=(SELECT usesysid FROM pg_shadow WHERE
usename='new_owner')  WHERE relname IN (SELECT relname from 
pg_class WHERE relname NOT LIKE 'pg_%');

Maybe there is a shorter way, but I know this one.

HTH,

Regards,
-- 
Devrim GUNDUZ
devrim@gunduz.org				devrim.gunduz@linux.org.tr 
			http://www.tdmsoft.com
			http://www.gunduz.org







^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: changing ownership of db
@ 2003-07-29 21:41  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Devrim GUNDUZ <devrim@gunduz.org>
  1 sibling, 1 reply; 5+ messages in thread

From: Tom Lane @ 2003-07-29 21:41 UTC (permalink / raw)
  To: Devrim GUNDUZ <devrim@gunduz.org>; +Cc: Benjamin Thelen (CCGIS) <thelen@ccgis.de>; pgsql-admin

Devrim GUNDUZ <devrim@gunduz.org> writes:
> On Tue, 29 Jul 2003, Benjamin Thelen (CCGIS) wrote:
>> I would like to change the ownership of a database.

> UPDATE pg_database SET datdba=(SELECT usesysid FROM pg_shadow WHERE 
> usename='new_owner') WHERE datname='db_name';

That is all you need to do --- it's the only place CREATE DATABASE
records the owner's identity.

> If you also want to change the owner of the tables, update pg_class:

> UPDATE pg_class SET relowner=(SELECT usesysid FROM pg_shadow WHERE
> usename='new_owner')  WHERE relname IN (SELECT relname from 
> pg_class WHERE relname NOT LIKE 'pg_%');

This is likely to be a very bad idea, especially if you give ownership
of the system tables to a non-superuser.  Ownership of those tables
stays with the postgres user during a CREATE DATABASE.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: changing ownership of db
@ 2003-07-30 09:17  Colin 't Hart <cthart@yahoo.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Colin 't Hart @ 2003-07-30 09:17 UTC (permalink / raw)
  To: pgsql-admin

On Tue, 29 Jul 2003 17:41:08 -0400, Tom Lane wrote:

> Devrim GUNDUZ <devrim@gunduz.org> writes:
>> On Tue, 29 Jul 2003, Benjamin Thelen (CCGIS) wrote:
>>> I would like to change the ownership of a database.
> 
>> UPDATE pg_database SET datdba=(SELECT usesysid FROM pg_shadow WHERE 
>> usename='new_owner') WHERE datname='db_name';
> 
> That is all you need to do --- it's the only place CREATE DATABASE
> records the owner's identity.

Would it be an idea to encapsulate this as
ALTER DATABASE db_name SET OWNER = 'new_owner'

or something similar?

What syntax would be desired and would you accept a patch?

Cheers,

Colin




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: changing ownership of db
@ 2003-07-31 16:42  Benjamin Thelen (CCGIS) <thelen@ccgis.de>
  parent: Devrim GUNDUZ <devrim@gunduz.org>
  1 sibling, 0 replies; 5+ messages in thread

From: Benjamin Thelen (CCGIS) @ 2003-07-31 16:42 UTC (permalink / raw)
  To: Devrim GUNDUZ <devrim@gunduz.org>; +Cc: pgsql-admin

Thanks very much!!
I had a user who was allowed to create dbs, but wasn't superuser...Now I 
just have a superuser.

Benjamin


Devrim GUNDUZ wrote:
> Hi,
> 
> On Tue, 29 Jul 2003, Benjamin Thelen (CCGIS) wrote:
> 
> 
>>I would like to change the ownership of a database. The only thing I 
>>could find up to now, is that it is difficult, but I couldn't find any 
>>detailed help.
> 
> 
> Connect to that database via psql. 
> 
> Then, first, update pg_database:
> 
> UPDATE pg_database SET datdba=(SELECT usesysid FROM pg_shadow WHERE 
> usename='new_owner') WHERE datname='db_name';
> 
> If you also want to change the owner of the tables, update pg_class:
> 
> UPDATE pg_class SET relowner=(SELECT usesysid FROM pg_shadow WHERE
> usename='new_owner')  WHERE relname IN (SELECT relname from 
> pg_class WHERE relname NOT LIKE 'pg_%');
> 
> Maybe there is a shorter way, but I know this one.
> 
> HTH,
> 
> Regards,





^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2003-07-31 16:42 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-07-29 16:56 changing ownership of db Benjamin Thelen (CCGIS) <thelen@ccgis.de>
2003-07-29 17:23 ` Devrim GUNDUZ <devrim@gunduz.org>
2003-07-29 21:41   ` Tom Lane <tgl@sss.pgh.pa.us>
2003-07-30 09:17     ` Colin 't Hart <cthart@yahoo.com>
2003-07-31 16:42   ` Benjamin Thelen (CCGIS) <thelen@ccgis.de>

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