Re: pg_dump'ed file contains "DROP DATABASE"

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: pf(at)pfortin(dot)com, pgsql-general(at)lists(dot)postgresql(dot)org
Cc: Rick Yost <Rick(at)NCDataTeam(dot)org>
Subject: Re: pg_dump'ed file contains "DROP DATABASE"
Date: 2023-02-20 23:24:23
Message-ID: 73beed04-25a2-e28b-20f8-855b81fca8ec@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2/20/23 11:36, pf(at)pfortin(dot)com wrote:
> On Mon, 20 Feb 2023 11:06:34 -0800 Adrian Klaver wrote:
>
>> On 2/20/23 10:27, pf(at)pfortin(dot)com wrote:
>>> [Still a newbie; but learning fast...]
>>>
>>> Hi,

>
> Notwithstanding the man page, my take is that the DROP DATABASE statement
> needs to be eliminated at pg_dump creation by pgAdmin4. Taking this to
> that mailing list.

It just dawned on me you might be doing all of this through the
pgAdmin4 GUI.

In which case from most recent documentation:

https://www.pgadmin.org/docs/pgadmin4/6.20/index.html

Backup Dialog:

https://www.pgadmin.org/docs/pgadmin4/6.20/backup_dialog.html

Options tab:
"
Move the switch next to Include CREATE DATABASE statement towards right
position to include a command in the backup that creates a new database
when restoring the backup.

Move the switch next to Include DROP DATABASE statement towards right
position to include a command in the backup that will drop any existing
database object with the same name before recreating the object during a
backup.
"

So the default is not to include those options.

For Restore dialog:

https://www.pgadmin.org/docs/pgadmin4/6.20/restore_dialog.html

Options tab(for custom format):

"
Move the switch next to Include CREATE DATABASE statement towards right
position to include a command that creates a new database before
performing the restore.

Move the switch next to Clean before restore towards right position to
drop each existing database object (and data) before restoring.
"

Again the default is to not include those options.

>
> Thanks Tom & Adrian!
>
>>> Was my 134 table[1] myname DB saved because it was open?
>
> Tom: Yup.
>
>>> If the dump file
>>> contains the above statements, how can I be absolutely certain I won't
>>> lose the DB?
>
> Tom:
> Reading the manual is advisable. --create --clean specifies exactly
> that the target database is to be dropped and recreated.
>
> regards, tom lane
>
>>> I'm obviously quite paranoid now...
>>
>> You will lose the database if you do as the docs specify for -C:
>>
>> "
>> -C
>>
>> ...
>>
>> When this option is used, the database named with -d is used only to
>> issue the initial DROP DATABASE and CREATE DATABASE commands. All data
>> is restored into the database name that appears in the archive.
>> "
>>
>>
>> It will then be recreated with whatever information is in "dumpfile". If
>> that is the same data or new data you want then you are fine. Otherwise
>> you will need to be more specific about what you are trying to achieve.
>>
>>
>>>
>>> [1] 3 types of tables: ~40%=8.5M rows; ~40%=33M rows; ~20%=varying sizes
>>>
>>> Thanks,
>>> Pierre
>>>
>>>
>>
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jonathan S. Katz 2023-02-20 23:44:58 Re: Support logical replication of DDLs
Previous Message Daniel Verite 2023-02-20 21:01:13 Re: Thanks! Re: Who adds the "start transaction" and "commit" to the intended SQL statement in "autocommit" mode?