Skip site navigation (1) Skip section navigation (2)

Usage: pg_dump's text format

From: "JP Beaudry" <jbeaudry(at)cisco(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Usage: pg_dump's text format
Date: 2004-04-08 23:57:27
Message-ID: 003c01c41dc5$3f3b4bf0$ (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
In short, I have not yet found a way to use pg_dump's text formatted file
with psql to restore a database without generating some kind of error. There
is always errors when dropping tables or dropping the database. I have
searched the novice and general archives but have not found the answer to
In long, I use the following command to generate the dump file against a
database named "mystore":
"pg_dump --clean --create --file=db_dump.txt --format p mystore"
The format of the dump file is as such (trimmed to keep length manageable):
\connect - my_admin
DROP INDEX "sys_mess_node_idx";
DROP TABLE "sag_to_sae";
\connect - postgres
Drop Database "mystore";
Create Database "mystore";
\connect mystore postgres
\connect - my_admin
<rest omitted for brevity>
To restore the database, I have tried:
"psql mystore < db_dump.txt"
And this fails at the "Drop Database "mystore"" command.
I have also tried:
"psql template1 < db_dump.txt"
Where the "DROP TABLE..." commands fail, but the database gets deleted prior
to being re-created.
I know the problem is related to being or not being connected to the
database one wants to restore. One cannot drop the database one is connected
to. And if one is connected to another database, the "drop table" fail
because said tables are not there.
Is there anyway to use the dump file wholesale in a cleaner manner? Is there
no other way than using bits and pieces of it? Or hacking it before using
it? I thought of using pg_restore, but found it is not meant for the text
format. If I could somehow customize how the "\connect"'s are done, I think
that would work.
Any advice or suggestion greatly welcomed. Thanks in advance,


pgsql-novice by date

Next:From: R V SreedharanDate: 2004-04-09 05:16:30
Subject: adopendynamic
Previous:From: Sheeraz fazalDate: 2004-04-08 19:17:38
Subject: How to call a function of PL/pgSQL

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group