pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedpg_dump -n schema -Fc has a DROP DATABASE command... confused
3+ messages / 3 participants
[nested] [flat]
* pg_dump -n schema -Fc has a DROP DATABASE command... confused
@ 2022-01-21 04:44 Wells Oliver <wells.oliver@gmail.com>
2022-01-21 04:57 ` Re: pg_dump -n schema -Fc has a DROP DATABASE command... confused David G. Johnston <david.g.johnston@gmail.com>
2022-01-21 05:02 ` Re: pg_dump -n schema -Fc has a DROP DATABASE command... confused Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 3+ messages in thread
From: Wells Oliver @ 2022-01-21 04:44 UTC (permalink / raw)
To: pgsql-admin
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:
[image: Screen Shot 2022-01-20 at 8.40.24 PM.png]
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?
Doing a text dump w/o -Fc yields a text file with no DROP statement.
More just curious, less afraid at this point.
--
Wells Oliver
wells.oliver@gmail.com <wellsoliver@gmail.com>
Attachments:
Screen Shot 2022-01-20 at 8.40.24 PM.png (image/png, 261.9K) download
view image
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: pg_dump -n schema -Fc has a DROP DATABASE command... confused
2022-01-21 04:44 pg_dump -n schema -Fc has a DROP DATABASE command... confused Wells Oliver <wells.oliver@gmail.com>
@ 2022-01-21 04:57 ` David G. Johnston <david.g.johnston@gmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: David G. Johnston @ 2022-01-21 04:57 UTC (permalink / raw)
To: Wells Oliver <wells.oliver@gmail.com>; +Cc: pgsql-admin
On Thu, Jan 20, 2022 at 9:45 PM Wells Oliver <wells.oliver@gmail.com> wrote:
> 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?
>
> Doing a text dump w/o -Fc yields a text file with no DROP statement.
>
The whole point of the custom format - which indeed defaults to compressed
mode (read the docs) - is to move any decisions about what to do during
restoring to the pg_restore commands. So, if the restore wants to drop the
database it has a drop database command available which it can execute. If
it doesn't that command will simply be skipped.
-Fp is a plain text format meant to be run via psql (or any other program
that can execute a basic SQL script - again, see the docs). Such a program
is not expected to specify restore conditions so whatever was defined
during the pg_dump will simply take effect.
David J.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: pg_dump -n schema -Fc has a DROP DATABASE command... confused
2022-01-21 04:44 pg_dump -n schema -Fc has a DROP DATABASE command... confused Wells Oliver <wells.oliver@gmail.com>
@ 2022-01-21 05:02 ` Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lane @ 2022-01-21 05:02 UTC (permalink / raw)
To: Wells Oliver <wells.oliver@gmail.com>; +Cc: pgsql-admin
Wells Oliver <wells.oliver@gmail.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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2022-01-21 05:02 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-01-21 04:44 pg_dump -n schema -Fc has a DROP DATABASE command... confused Wells Oliver <wells.oliver@gmail.com>
2022-01-21 04:57 ` David G. Johnston <david.g.johnston@gmail.com>
2022-01-21 05:02 ` Tom Lane <tgl@sss.pgh.pa.us>
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