Export content of a DB - Mailing list pgsql-novice

From Ben Clewett
Subject Export content of a DB
Date
Msg-id 3E894C0B.50509@roadrunner.uk.com
Whole thread Raw
In response to Modifying WHERE input conditions for a VIEW  (Tony Holmes <tony@crosswinds.net>)
List pgsql-novice
Is it possible to export an entire DB in a form where it can be
re-imported?  For each table in a DB, output to a line-sequential file?

I have found that:

echo "select 'insert into $table values', * from $table |
    psql -F " " -A -t $database >> outfile.txt

Does at least give a file of sql statements.  But the strings are not
quoted or escaped.  So multi-word fields, and field''''s with quotes
mess up.

For this I also need a list of tables in a DB.  I can use:

for $table in read `echo "\dt" | psql -F " " -A -t rr | awk '{ print $2 }'`
do
    (as above)
done

But it's getting a little weigted!  I can't help fealing there must be
some clever option I am missing for dumping a DB in a form designed for
re-import, without all this work!


Thanks in advance if anybody can give me a hand...

Ben


pgsql-novice by date:

Previous
From: Oliver Elphick
Date:
Subject: Re: Postgres logs w/ Logrotate
Next
From: "Crombleholme, Roy"
Date:
Subject: Re: Export content of a DB