Обсуждение: Why pg_dump overwrites dump file?

Поиск
Список
Период
Сортировка

Why pg_dump overwrites dump file?

От
Chao Li
Дата:
Hi Hacker,

I noticed this problem while testing the other patch.

When I do custom-format dump, if a target file exists, pg_dump will just go ahead overwrite the existing file; however, when I do directory dump, if a target dir exists, pg_dump will fail with an error “directory xxx is not empty”.

Behaviors of the two types of pg_dump are inconsistent, I wonder if that’s by design?

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/




Re: Why pg_dump overwrites dump file?

От
Daniel Gustafsson
Дата:
> On 14 Oct 2025, at 07:42, Chao Li <li.evan.chao@gmail.com> wrote:

> Behaviors of the two types of pg_dump are inconsistent, I wonder if that’s by design?

It does admittedly seem odd that --file works differently for files and
directories, but at this point it might be behavior that users expect and
changing it might break current usecases?  Not sure what the best option is
here.

Another inconsistency is that the documentation states this:

    "In this case the directory is created by pg_dump and must not exist
    before."

..which isn't true, since it will happily reuse an existing directory as long as
it's empty, the comment in the code makes the intention clear:

  /*
   * create_or_open_dir
   *
   * This will create a new directory with the given dirname. If there is
   * already an empty directory with that name, then use it.
   */

So regardless it seems we should something like the attached at least.

--
Daniel Gustafsson


Вложения