Re: There should be a way to use the force flag when restoring databases

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: Gurjeet Singh <gurjeet(at)singh(dot)im>
Cc: Joan <aseques(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: There should be a way to use the force flag when restoring databases
Date: 2023-07-20 09:09:53
Message-ID: 969982DE-B568-4BF6-B7B5-73E29066BB50@yesql.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 19 Jul 2023, at 19:28, Gurjeet Singh <gurjeet(at)singh(dot)im> wrote:
>
> On Tue, Jul 18, 2023 at 12:53 AM Joan <aseques(at)gmail(dot)com> wrote:
>>
>> Since posgres 13 there's the option to do a FORCE when dropping a database (so it disconnects current users) Documentation here: https://www.postgresql.org/docs/current/sql-dropdatabase.html
>>
>> I am currently using dir format for the output
>> pg_dump -d "bdname" -F d -j 4 -v -f /tmp/dir
>>
>> And restoring the database with
>> pg_restore -d postgres -C -c --exit-on-error -F d -j 3 -v /tmp/dir
>>
>> Having an option to add the FORCE option to either the generated dump by pg_dump, or in the pg_restore would be very useful when restoring the databases to another servers so it would avoid having to do scripting.
>>
>> In my specific case I am using this to refresh periodically a development environment with data from production servers for a small database (~200M).
>
> Making force-drop a part of pg_dump output may be dangerous, and not
> provide much flexibility at restore time.
>
> Adding a force option to pg_restore feels like providing the right tradeoff.
>
> The docs for 'pg_restore --create` say "Create the database before
> restoring into it. If --clean is also specified, drop and recreate the
> target database before connecting to it."
>
> If we provided a force option, it may then additionally say: "If the
> --clean and --force options are specified, DROP DATABASE ... WITH
> FORCE command will be used to drop the database."

pg_restore --clean refers to dropping any pre-existing database objects and not
just databases, but --force would only apply to databases.

I wonder if it's worth complicating pg_restore with that when running dropdb
--force before pg_restore is an option for those wanting to use WITH FORCE.

--
Daniel Gustafsson

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2023-07-20 09:29:10 Re: Support worker_spi to execute the function dynamically.
Previous Message Bharath Rupireddy 2023-07-20 09:08:29 Re: WAL Insertion Lock Improvements