pg_restore: remove unnecessary code from restore_all_databases function

Started by Mahendra Singh Thalorabout 1 month ago3 messageshackers
Jump to latest
#1Mahendra Singh Thalor
mahi6run@gmail.com

Hi hackers,

+++ b/src/bin/pg_dump/pg_restore.c
@@ -1268,16 +1268,6 @@ restore_all_databases(const char *inputFileSpec,
                 */
                memcpy(tmpopts, original_opts, sizeof(RestoreOptions));

- /*
- * We need to reset override_dbname so that objects can be
restored
- * into an already created database. (used with -d/--dbname
option)
- */
- if (tmpopts->cparams.override_dbname)
- {
- pfree(tmpopts->cparams.override_dbname);
- tmpopts->cparams.override_dbname = NULL;
- }
-

In commit 77152d26efefde2eed4, we added some functions and we missed to
remove some unnecessary lines. Those lines are not needed as we are using
memcpy to get the original copy before these lines.

Here, I am attaching a patch to fix this. Please review it.

--
Thanks and Regards
Mahendra Singh Thalor
EnterpriseDB: http://www.enterprisedb.com

Attachments:

v01-pg_restore-remove-unnecessary-code-from-restore_all.patchtext/x-patch; charset=US-ASCII; name=v01-pg_restore-remove-unnecessary-code-from-restore_all.patchDownload+0-11
#2Andrew Dunstan
andrew@dunslane.net
In reply to: Mahendra Singh Thalor (#1)
Re: pg_restore: remove unnecessary code from restore_all_databases function

On 2026-03-14 Sa 11:48 PM, Mahendra Singh Thalor wrote:

Hi hackers,

+++ b/src/bin/pg_dump/pg_restore.c
@@ -1268,16 +1268,6 @@ restore_all_databases(const char *inputFileSpec,
                 */
                memcpy(tmpopts, original_opts, sizeof(RestoreOptions));

-               /*
-                * We need to reset override_dbname so that objects
can be restored
-                * into an already created database. (used with
-d/--dbname option)
-                */
-               if (tmpopts->cparams.override_dbname)
-               {
- pfree(tmpopts->cparams.override_dbname);
-                       tmpopts->cparams.override_dbname = NULL;
-               }
-

In commit 77152d26efefde2eed4, we added some functions and we missed
to remove some unnecessary lines. Those lines are not needed as we are
using memcpy to get the original copy before these lines.

Here, I am attaching a patch to fix this. Please review it.

Thanks. Pushed.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

#3Mahendra Singh Thalor
mahi6run@gmail.com
In reply to: Andrew Dunstan (#2)
Re: pg_restore: remove unnecessary code from restore_all_databases function

On Sun, 15 Mar 2026 at 21:46, Andrew Dunstan <andrew@dunslane.net> wrote:

On 2026-03-14 Sa 11:48 PM, Mahendra Singh Thalor wrote:

Hi hackers,

+++ b/src/bin/pg_dump/pg_restore.c
@@ -1268,16 +1268,6 @@ restore_all_databases(const char *inputFileSpec,
*/
memcpy(tmpopts, original_opts, sizeof(RestoreOptions));

- /*
- * We need to reset override_dbname so that objects
can be restored
- * into an already created database. (used with
-d/--dbname option)
- */
- if (tmpopts->cparams.override_dbname)
- {
- pfree(tmpopts->cparams.override_dbname);
- tmpopts->cparams.override_dbname = NULL;
- }
-

In commit 77152d26efefde2eed4, we added some functions and we missed
to remove some unnecessary lines. Those lines are not needed as we are
using memcpy to get the original copy before these lines.

Here, I am attaching a patch to fix this. Please review it.

Thanks. Pushed.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Thanks Andrew for committing this.

--
Thanks and Regards
Mahendra Singh Thalor
EnterpriseDB: http://www.enterprisedb.com