pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: T.J. Adami <adamitj@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: backup and restore
Date: Tue, 15 Jan 2008 14:29:32 +0000
Message-ID: <478CC34C.8010304@archonet.com> (raw)
In-Reply-To: <2d910723-1b4d-444b-b355-5f32bc399342@c4g2000hsg.googlegroups.com>
References: <881d13a4-9564-4910-862b-5ace0a592bf8@j78g2000hsd.googlegroups.com>
	<2d910723-1b4d-444b-b355-5f32bc399342@c4g2000hsg.googlegroups.com>

T.J. Adami wrote:
> On 14 jan, 10:36, hiddenhippo <reda...@gmail.com> wrote:
>> Having recently jumped ship from MSSQL to Postgres I'm finding it a
>> little difficult getting onto the 'correct path.'  Basically I have a
>> live database and I want to take a copy of that and then restore it
>> onto a backup server.
>>
>> Firstly I'm using Postgres 8.2 and pgAdmin 1.6.3

OK. Latest is 8.2.6 I believe, make sure you keep up to date with minor 
updates.
Oh, and pgAdmin has released version 1.8 now, although that shouldn't 
affect backups.

>> Within the pgAdmin interface I've selected the database I wish to
>> backup, given it a filename, selected 'Compress' and have chosen blobs
>> and OIDs.  From the documentation it appears that if you use foreign
>> keys then you should use OIDs.  

You probably want "compress" - that format allows you do partial 
restores as well as being compressed. I can't tell whether you've got 
any blobs ("large objects" in PG terminology). I don't think you'll need 
to dump OIDs unless you're explicitly using them. The manuals have 
recommended against that for some years now, so if you can remember 
which bit gave you the impression you need them for foreign keys then 
that would be useful.

 >  Anyway, the backup appears to work
>> fine and a file is created.  No errors are displayed at any point.

Excellent. You should also have a "messages" tab that shows the pg_dump 
command it uses. You can run the same from the command-line to dump your 
database. If you've got "verbose messages" turned on then it will name 
each item as it dumps it too. I'm working from pgAdmin 1.8 here, but I 
don't think it was any different in 1.6

>> When I come to restore the database I fistly create a blank one, and
>> then right click and choose restore.  The problem is that errors are
>> thrown because of foreign-key constraints.

OK, that's down to one of three things:
1. The database wasn't empty - perhaps you had a partial restore 
in-place. Unlikely, since I'm sure you repeated your steps above.

2. The dump was in plain-text and you were doing separate schema + data 
restores. We can rule this out because you've said otherwise.

3. You aren't restoring as a super-user (typically "postgres"), so it 
can't disable + re-enable foreign keys. That's what I think is happening.

>> With a little more investigation I changed the backup output to
>> 'plain' so that I could see the script generated.  It appears that the
>> backup process is created tables and their associated data in the
>> wrong order.  For example,  at the top of the generated file it
>> attempts to insert data into a given table, however the table dictates
>> that some entries must have a corresponding entry in another, for
>> example a user id (a foreign key saying that UID value must exist on
>> the user tables primary key).  After detailing the data for the first
>> table it then details the data that should go into the parent table,
>> or in my example above, it then attempts to populate the user table.
>> When you run the restore process this it fails because the user table
>> doesn't have the corresponding entries.

If you look more carefully, you should see that all the foreign keys are 
created at the bottom of the file after the data restore.

>> Could someone please suggest why this is happening and how, if it can
>> be done, I fix it?
>>
>> Thanks
> 
> It's quite simple to have problems with pgAdmin's backup procedure.

Hmm - shouldn't be, and if so then please let the pgAdmin people know! 
They're always working to improve the package and it's

> Althought pgAdmin 3 uses pg_dump and pg_restore utilities, I could
> report many errors when did backups and/or restores from it.

Did you keep any notes, and can you reproduce them?

> I suggest you to use pg_dump command line utility into a plain SQL
> file, so you can compress it with bzip2 to maximum compress rates.
> When you restore, decompress the file (if you have packed it) and use
> the psql to load the script file into the new and clean database.

You're better off using the compressed mode imnsho. The flexibility is 
well worth any minor loss vs bzip2's compression. Check out the -l / -L 
options to let you pick and choose what you restore.

-- 
   Richard Huxton
   Archonet Ltd



view thread (26+ messages)  latest in thread

Message-ID: <478CC34C.8010304@archonet.com>
Permalink:  ../478CC34C.8010304@archonet.com/
Also on:    postgresql.org/message-id/478CC34C.8010304@archonet.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: dev@archonet.com, adamitj@gmail.com
  Subject: Re: backup and restore
  In-Reply-To: <478CC34C.8010304@archonet.com>
  References: <881d13a4-9564-4910-862b-5ace0a592bf8@j78g2000hsd.googlegroups.com> <2d910723-1b4d-444b-b355-5f32bc399342@c4g2000hsg.googlegroups.com> <478CC34C.8010304@archonet.com>

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

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