Re: pg_dump -n schema -Fc has a DROP DATABASE command... confused

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Wells Oliver <wells(dot)oliver(at)gmail(dot)com>
Cc: pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: Re: pg_dump -n schema -Fc has a DROP DATABASE command... confused
Date: 2022-01-21 05:02:58
Message-ID: 1123450.1642741378@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Wells Oliver <wells(dot)oliver(at)gmail(dot)com> writes:
> I did a few pg_dumps of different schemas using:
> pg_dump -h host dbname -n schema -Fc > schema.dump
> Opening it in VIM brings up a binary file (compressed, sure) but it looks
> like this:
> Which contains the line "DROP DATABASE". Which is weird-- it does not drop
> the database, I mean, I restored from the same file. Why is this in there?

pg_dump -Fc produces an archive file that pg_restore can use to
do whatever you can ask pg_restore to do. One of those things
is the --clean switch, which says to drop every database object
before restoring. So among the strings in the archive file you
will find DROP commands for all the dumped objects. Those are
not issued by default, though.

(The other DROP commands might be obscured by compression.
Try --compress=0 to get a clearer view of what's in there.)

regards, tom lane

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Дмитрий Иванов 2022-01-21 08:26:42 Re: Password authorization
Previous Message David G. Johnston 2022-01-21 04:57:21 Re: pg_dump -n schema -Fc has a DROP DATABASE command... confused