One less footgun: deprecating pg_dump -d

From: Greg Sabino Mullane <greg(at)endpoint(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: One less footgun: deprecating pg_dump -d
Date: 2009-03-09 15:22:47
Message-ID: 49B53447.30402@endpoint.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Attached is a patch to fix the annoying footgun that is pg_dump -d. Myself and
many others I know have all at one time or another done this:

psql -h localhost -U greg -d postgres

pg_dump -h localhost -U greg -d postgres > dumpfile

The latter command silently succeeds, but only through the combination of -d
being an option that takes no arguments, and the fact that 'postgres' is read by
pg_dump as a separate argument indicating which database to use. Thus, your dump
file now has INSERTs when you wanted to use COPY (as you want your database
restore to take 20 minutes, not three hours).

I thought about changing -d to actually indicate the database, as in psql, but
that brings about another problem: the command above will still silently work,
but produce a dump without INSERTs. While this is good for people who meant to
leave the -d out, it's not good for people (and scripts) that DID want the -d to
work as documented. Thus, changing it will silently break those scripts (until
they try to load the schema into a non-PG database...).

The solution I came up with is to use a new letter, -I, and to deprecate -d by
having it throw an exception when used. The choice of -I seems appropriate as a
shortcut for --inserts, and (as far as I can tell) does not conflict with any
other programs (e.g. psql). Doing so will require people to rewrite any scripts
that are using -d instead of --inserts, but it seems a small price to eliminate
this nasty footgun. As a bonus, their scripts will be easier to read, as -d was
confusing at best, and hardly mnemonic.

--
Greg Sabino Mullane greg(at)endpoint(dot)com greg(at)turnstep(dot)com
End Point Corporation
PGP Key: 0x14964AC8

Attachment Content-Type Size
pg_dump.footgun.patch text/x-diff 10.8 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2009-03-09 15:46:19 Re: small parallel restore optimization
Previous Message Peter Eisentraut 2009-03-09 15:05:29 Re: [PATCH] Regression test fix for Czech locale