pg_dump and pg_restore with different owners

From: Jaume Sabater <jsabater(at)linuxsilo(dot)net>
To: pgsql-admin(at)postgresql(dot)org
Subject: pg_dump and pg_restore with different owners
Date: 2007-04-19 09:56:46
Message-ID: 46273CDE.50401@linuxsilo.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hello everyone!

We have a two servers, "devel" and "live", both running PostgreSQL
8.1.8. At the devel server there is the database "ots_devel" owned by
user "ots_devel". At the live server there is the database "ots_live"
owned by the user "ots_live". They are normal users, with no ability to
create databases or roles. I have access as superuser.

I want to dump the database "ots_devel", then copy it to the live server
and restore it under a different name ("ots_live") and owned by a
different user "ots_live". These are the commands I am using:

- At the devel server:

pg_dump --oids --no-owner --format=c --file=ots_devel.bak ots_devel

- At the live server:

createuser --no-superuser --no-createdb --no-createrole --pwprompt ots_live

createdb --encoding=UTF-8 --owner=ots_live ots_live

pg_restore --no-owner --dbname=ots_live ots_devel.bak

If I do this, there is no warning, there is no error. But the user
ots_live does not have the right permissions over the tables in the
database. He is not the owner of those objects or the permissions are
not right.

Then I tried restoring this way:

pg_restore --no-owner --dbname=ots_live --host=127.0.0.1 -U ots_live -W
ots_devel.bak

But I got these errors:

pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 3751; 0 0 COMMENT
SCHEMA public postgres
pg_restore: [archiver (db)] could not execute query: ERROR: must be
owner of schema public
Command was:
COMMENT ON SCHEMA public IS 'Standard public schema';
pg_restore: WARNING: no privileges could be revoked
pg_restore: WARNING: no privileges could be revoked
pg_restore: WARNING: no privileges were granted
pg_restore: WARNING: no privileges were granted
WARNING: errors ignored on restore: 1

What I want is that user "ots_live" is the new only owner of everything
inside the database "ots_live". I think that the problem is not when
working inside the database "ots_live", but when updating the schemas,
but I don't know how to prevent that from happening.

I've read about authorization, but I don't know how to apply it to my case.

Any hints? Thanks in advance.

--
Jaume Sabater
http://linuxsilo.net/

"Ubi sapientas ibi libertas"

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Alvaro Herrera 2007-04-19 14:53:20 Re: Auto vacuum
Previous Message Nico Franken 2007-04-19 09:08:15 pgsqlODBC installment