Re: how do I do dump and restore without bugging with constraint?

From: Iñigo Martinez Lasala <imartinez(at)vectorsf(dot)com>
To: "'Net Tree Inc(dot)'" <nettreeinc(at)gmail(dot)com>
Cc: <pgsql-admin(at)postgresql(dot)org>
Subject: Re: how do I do dump and restore without bugging with constraint?
Date: 2010-02-23 17:49:14
Message-ID: 03d401cab4b0$8cd6c690$a68453b0$@com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general

To avoid contraints you have to use –disable-triggers flag during restore.
That is done in step 5.

In order to modify schema you have to locate what is failing. So, first
restore old schema without modifications in your new database, watch for
errors and fix them.

For example:

psql -U username -d database -h server_destination -f schema.sql
2>import_error.log

You’ll find all import errors in import_error.log. Since you are only
going to launch an schema definition, It will only take a few seconds, so
test all you need.

After locating errors, open schema.sql with your favorite editor and fix
them. There are minor changes between postgresql versions and you’ll
probably have no problems in order to fix them, or ask here if you have
many problems.

Once fixed, you will have your new modified_schema.sql and you can proceed
with steps 4 and 5.

Obviously, if errors are related to indexes, functions, broken
dependencies, etc without touching table definitions, everything will go
well. However if you have to modify table definitions, you will probably
not be able to import data in that new schema and it will be necesary to
look for a new strategy.

De: Net Tree Inc. [mailto:nettreeinc(at)gmail(dot)com]
Enviado el: martes, 23 de febrero de 2010 17:36
Para: Iñigo Martinez Lasala
CC: pgsql-admin(at)postgresql(dot)org; pgsql-general(at)postgresql(dot)org
Asunto: Re: [ADMIN] how do I do dump and restore without bugging with
constraint?

Thanks. Is it by doing these steps I can avoid constrain restriction? for
step 3, how should I modify the schema? and which schema? the target DB's
schema that I am trying to dump the schema and data in? But this is the
problem, I am not sure whats different between the two schema's, there are
just too many tables to check. What's your tips?

Steven

On Tue, Feb 23, 2010 at 7:03 PM, Iñigo Martinez Lasala
<imartinez(at)vectorsf(dot)com> wrote:

Using pg_dump from your new host (that is, newer version)

1- Dump schema.
pg_dump -h server_source -U username -s -Fp -f schema.sql database

2- Dump data only.
pg_dump -h server_source -U username -a -Fc -f data.dmp database

3- Modify schema.

4- Restore schema in new host.
psql -U username -d database -h server_destination -f modified_schema.sql

5- Restore data disabling triggers
pg_restore -h server_destination -U username -d database
--disable-triggers -a data.dmp

-----Original Message-----
From: Net Tree Inc. <nettreeinc(at)gmail(dot)com
<mailto:%22Net%20Tree%20Inc(dot)%22%20%3cnettreeinc(at)gmail(dot)com%3e> >
To: pgsql-admin(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org
Subject: [ADMIN] how do I do dump and restore without bugging with
constraint?
Date: Tue, 23 Feb 2010 12:50:27 +0800

Hi all,

I am dumping both schema and data from old database to new one. The new
database schema is somehow contain slightly different schema then the old
one. When I do restore it shown alot errors related with constraints. How
can I dump and to restore from old to new without dealing with constraint
and just forces data dump to where it suppose to belong?

--
---------------------------------------
Steven Huang

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message P 2010-02-23 19:52:58 Query DDL Comments?
Previous Message Net Tree Inc. 2010-02-23 16:36:10 Re: how do I do dump and restore without bugging with constraint?

Browse pgsql-general by date

  From Date Subject
Next Message Peter Headland 2010-02-23 18:38:22 Re: COPY command character set
Previous Message Tom Lane 2010-02-23 17:41:39 Re: "make check" failed on 8.4.2 install