agora inbox for [email protected]
help / color / mirror / Atom feed[PATCH v15 03/14] meson: prereq: De-special-case pgevent's rc file handling
7+ messages / 3 participants
[nested] [flat]
* [PATCH v15 03/14] meson: prereq: De-special-case pgevent's rc file handling
@ 2022-09-13 17:07 Andres Freund <[email protected]>
0 siblings, 0 replies; 7+ messages in thread
From: Andres Freund @ 2022-09-13 17:07 UTC (permalink / raw)
There's really no need to build win32ver.rc as part of building pgmsgevent.rc.
---
src/bin/pgevent/Makefile | 5 +++--
src/bin/pgevent/pgmsgevent.rc | 2 --
src/tools/msvc/Mkvcbuild.pm | 1 -
3 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/bin/pgevent/Makefile b/src/bin/pgevent/Makefile
index dea79d3f137..04d49711d8d 100644
--- a/src/bin/pgevent/Makefile
+++ b/src/bin/pgevent/Makefile
@@ -17,7 +17,8 @@ ifeq ($(PORTNAME), win32)
OBJS = \
pgevent.o \
- pgmsgevent.o
+ pgmsgevent.o \
+ $(WIN32RES)
NAME=pgevent
SHLIB_LINK =
@@ -29,7 +30,7 @@ install: all install-lib
include $(top_srcdir)/src/Makefile.shlib
-pgmsgevent.o: pgmsgevent.rc win32ver.rc
+pgmsgevent.o: pgmsgevent.rc
$(WINDRES) $< -o $@ --include-dir=$(top_builddir)/src/include --include-dir=$(top_srcdir)/src/include --include-dir=$(srcdir) --include-dir=.
clean distclean: clean-lib
diff --git a/src/bin/pgevent/pgmsgevent.rc b/src/bin/pgevent/pgmsgevent.rc
index e69862e882c..0885a897e6f 100644
--- a/src/bin/pgevent/pgmsgevent.rc
+++ b/src/bin/pgevent/pgmsgevent.rc
@@ -1,4 +1,2 @@
LANGUAGE 0x9,0x1
1 11 MSG00001.bin
-
-#include "win32ver.rc"
diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm
index 098bc3f1b09..ddb4f25eb12 100644
--- a/src/tools/msvc/Mkvcbuild.pm
+++ b/src/tools/msvc/Mkvcbuild.pm
@@ -425,7 +425,6 @@ sub mkvcbuild
$pgevent->AddFiles('src/bin/pgevent', 'pgevent.c', 'pgmsgevent.rc');
$pgevent->AddResourceFile('src/bin/pgevent', 'Eventlog message formatter',
'win32');
- $pgevent->RemoveFile('src/bin/pgevent/win32ver.rc');
$pgevent->UseDef('src/bin/pgevent/pgevent.def');
$pgevent->DisableLinkerWarnings('4104');
--
2.37.3.542.gdd3f6c4cae
--ayx3t42hstokjw3l
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v15-0004-meson-prereq-win-remove-date-from-version-number.patch"
^ permalink raw reply [nested|flat] 7+ messages in thread
* [PATCH v13 11/20] meson: prereq: De-special-case pgevent's rc file handling
@ 2022-09-13 17:07 Andres Freund <[email protected]>
0 siblings, 0 replies; 7+ messages in thread
From: Andres Freund @ 2022-09-13 17:07 UTC (permalink / raw)
There's really no need to build win32ver.rc as part of building pgmsgevent.rc.
---
src/bin/pgevent/Makefile | 5 +++--
src/bin/pgevent/pgmsgevent.rc | 2 --
src/tools/msvc/Mkvcbuild.pm | 1 -
3 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/bin/pgevent/Makefile b/src/bin/pgevent/Makefile
index dea79d3f137..04d49711d8d 100644
--- a/src/bin/pgevent/Makefile
+++ b/src/bin/pgevent/Makefile
@@ -17,7 +17,8 @@ ifeq ($(PORTNAME), win32)
OBJS = \
pgevent.o \
- pgmsgevent.o
+ pgmsgevent.o \
+ $(WIN32RES)
NAME=pgevent
SHLIB_LINK =
@@ -29,7 +30,7 @@ install: all install-lib
include $(top_srcdir)/src/Makefile.shlib
-pgmsgevent.o: pgmsgevent.rc win32ver.rc
+pgmsgevent.o: pgmsgevent.rc
$(WINDRES) $< -o $@ --include-dir=$(top_builddir)/src/include --include-dir=$(top_srcdir)/src/include --include-dir=$(srcdir) --include-dir=.
clean distclean: clean-lib
diff --git a/src/bin/pgevent/pgmsgevent.rc b/src/bin/pgevent/pgmsgevent.rc
index e69862e882c..0885a897e6f 100644
--- a/src/bin/pgevent/pgmsgevent.rc
+++ b/src/bin/pgevent/pgmsgevent.rc
@@ -1,4 +1,2 @@
LANGUAGE 0x9,0x1
1 11 MSG00001.bin
-
-#include "win32ver.rc"
diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm
index 098bc3f1b09..ddb4f25eb12 100644
--- a/src/tools/msvc/Mkvcbuild.pm
+++ b/src/tools/msvc/Mkvcbuild.pm
@@ -425,7 +425,6 @@ sub mkvcbuild
$pgevent->AddFiles('src/bin/pgevent', 'pgevent.c', 'pgmsgevent.rc');
$pgevent->AddResourceFile('src/bin/pgevent', 'Eventlog message formatter',
'win32');
- $pgevent->RemoveFile('src/bin/pgevent/win32ver.rc');
$pgevent->UseDef('src/bin/pgevent/pgevent.def');
$pgevent->DisableLinkerWarnings('4104');
--
2.37.3.542.gdd3f6c4cae
--4uoxke3bx6ymzqvl
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v13-0012-meson-prereq-win-remove-date-from-version-number.patch"
^ permalink raw reply [nested|flat] 7+ messages in thread
* [PATCH v13 11/20] meson: prereq: De-special-case pgevent's rc file handling
@ 2022-09-13 17:07 Andres Freund <[email protected]>
0 siblings, 0 replies; 7+ messages in thread
From: Andres Freund @ 2022-09-13 17:07 UTC (permalink / raw)
There's really no need to build win32ver.rc as part of building pgmsgevent.rc.
---
src/bin/pgevent/Makefile | 5 +++--
src/bin/pgevent/pgmsgevent.rc | 2 --
src/tools/msvc/Mkvcbuild.pm | 1 -
3 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/bin/pgevent/Makefile b/src/bin/pgevent/Makefile
index dea79d3f137..04d49711d8d 100644
--- a/src/bin/pgevent/Makefile
+++ b/src/bin/pgevent/Makefile
@@ -17,7 +17,8 @@ ifeq ($(PORTNAME), win32)
OBJS = \
pgevent.o \
- pgmsgevent.o
+ pgmsgevent.o \
+ $(WIN32RES)
NAME=pgevent
SHLIB_LINK =
@@ -29,7 +30,7 @@ install: all install-lib
include $(top_srcdir)/src/Makefile.shlib
-pgmsgevent.o: pgmsgevent.rc win32ver.rc
+pgmsgevent.o: pgmsgevent.rc
$(WINDRES) $< -o $@ --include-dir=$(top_builddir)/src/include --include-dir=$(top_srcdir)/src/include --include-dir=$(srcdir) --include-dir=.
clean distclean: clean-lib
diff --git a/src/bin/pgevent/pgmsgevent.rc b/src/bin/pgevent/pgmsgevent.rc
index e69862e882c..0885a897e6f 100644
--- a/src/bin/pgevent/pgmsgevent.rc
+++ b/src/bin/pgevent/pgmsgevent.rc
@@ -1,4 +1,2 @@
LANGUAGE 0x9,0x1
1 11 MSG00001.bin
-
-#include "win32ver.rc"
diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm
index 098bc3f1b09..ddb4f25eb12 100644
--- a/src/tools/msvc/Mkvcbuild.pm
+++ b/src/tools/msvc/Mkvcbuild.pm
@@ -425,7 +425,6 @@ sub mkvcbuild
$pgevent->AddFiles('src/bin/pgevent', 'pgevent.c', 'pgmsgevent.rc');
$pgevent->AddResourceFile('src/bin/pgevent', 'Eventlog message formatter',
'win32');
- $pgevent->RemoveFile('src/bin/pgevent/win32ver.rc');
$pgevent->UseDef('src/bin/pgevent/pgevent.def');
$pgevent->DisableLinkerWarnings('4104');
--
2.37.3.542.gdd3f6c4cae
--4uoxke3bx6ymzqvl
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v13-0012-meson-prereq-win-remove-date-from-version-number.patch"
^ permalink raw reply [nested|flat] 7+ messages in thread
* [PATCH v8 04/10] heapam: Use exclusive lock on old page in CLUSTER
@ 2025-01-26 20:18 Andres Freund <[email protected]>
0 siblings, 0 replies; 7+ messages in thread
From: Andres Freund @ 2025-01-26 20:18 UTC (permalink / raw)
To be able to guarantee that we can set the hint bit, acquire an exclusive
lock on the old buffer. We need the hint bits to be set as otherwise
reform_and_rewrite_tuple() -> rewrite_heap_tuple() -> heap_freeze_tuple() will
get confused.
It'd be better if we somehow could avoid setting hint bits on the old page. A
commonreason to use VACUUM FULL are very bloated tables - rewriting most of
the old table before during VACUUM FULL doesn't exactly help.
Author:
Reviewed-by:
Discussion: https://postgr.es/m/
Backpatch:
---
src/backend/access/heap/heapam_handler.c | 13 ++++++++++++-
src/backend/access/heap/heapam_visibility.c | 7 +++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index dd4fe6bf62f..0c684786382 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -837,7 +837,18 @@ heapam_relation_copy_for_cluster(Relation OldHeap, Relation NewHeap,
tuple = ExecFetchSlotHeapTuple(slot, false, NULL);
buf = hslot->buffer;
- LockBuffer(buf, BUFFER_LOCK_SHARE);
+ /*
+ * To be able to guarantee that we can set the hint bit, acquire an
+ * exclusive lock on the old buffer. We need the hint bits to be set
+ * as otherwise reform_and_rewrite_tuple() -> rewrite_heap_tuple() ->
+ * heap_freeze_tuple() will get confused.
+ *
+ * It'd be better if we somehow could avoid setting hint bits on the
+ * old page. One reason to use VACUUM FULL are very bloated tables -
+ * rewriting most of the old table before during VACUUM FULL doesn't
+ * exactly help...
+ */
+ LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE);
switch (HeapTupleSatisfiesVacuum(tuple, OldestXmin, buf))
{
diff --git a/src/backend/access/heap/heapam_visibility.c b/src/backend/access/heap/heapam_visibility.c
index bf899c2d2c6..debf5d56b95 100644
--- a/src/backend/access/heap/heapam_visibility.c
+++ b/src/backend/access/heap/heapam_visibility.c
@@ -141,6 +141,13 @@ void
HeapTupleSetHintBits(HeapTupleHeader tuple, Buffer buffer,
uint16 infomask, TransactionId xid)
{
+ /*
+ * The uses from heapam.c rely on being able to perform the hint bit
+ * updates, which can only be guaranteed if we are holding an exclusive
+ * lock on the buffer - which all callers are doing.
+ */
+ Assert(BufferIsLockedByMeInMode(buffer, BUFFER_LOCK_EXCLUSIVE));
+
SetHintBits(tuple, buffer, infomask, xid);
}
--
2.48.1.76.g4e746b1a31.dirty
--lbbj3oq7cjvyhmbk
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v8-0005-heapam-Add-batch-mode-mvcc-check-and-use-it-in-pa.patch"
^ permalink raw reply [nested|flat] 7+ messages in thread
* pg_restore add --no-globals option when restored using pg_dumpall non-text dump
@ 2026-02-27 06:27 Mahendra Singh Thalor <[email protected]>
2026-02-27 07:47 ` Re: pg_restore add --no-globals option when restored using pg_dumpall non-text dump Mahendra Singh Thalor <[email protected]>
0 siblings, 1 reply; 7+ messages in thread
From: Mahendra Singh Thalor @ 2026-02-27 06:27 UTC (permalink / raw)
To: PostgreSQL Hackers <[email protected]>; +Cc: jian he <[email protected]>; tushar <[email protected]>; Andrew Dunstan <[email protected]>
Hi,
Recently we committed a patch to dump a full cluster with pg_dumpall in
non-text archive format and then restore using pg_restore.
Here, I am proposing a patch to add the "pg_restore --no-globals" option so
that users can skip global objects.
I made a patch for pg_restore --no-globals (only pg_restore option, not
needed with pg_dumpall as we will filter at restore end, or later we can
add for pg_dumpall also.)
*Brief*:
pg_restore: add --no-globals option to skip globals
Do not restore global objects (roles and tablespaces) and even don't
create new database if
--create or -C is not specified.
Note: database will be created only if -C is specified, otherwise
restore will be skipped for a particular database. If a db is already
created, then data of a particular db will be restored.
Please review this patch and let me know your feedback.
--
Thanks and Regards
Mahendra Singh Thalor
EnterpriseDB: http://www.enterprisedb.com
Attachments:
[application/octet-stream] v01-pg_restore-add-no-globals-option-to-skip-globals.patch (6.0K, ../../CAKYtNAoZUkX2qJsTf73P1zCnh9sVJ7PDtthN3i0wZCTLiBsxMg@mail.gmail.com/3-v01-pg_restore-add-no-globals-option-to-skip-globals.patch)
download | inline diff:
From 93d3b51e884d844a2cafb93acd3abfca8edbd869 Mon Sep 17 00:00:00 2001
From: Mahendra Singh Thalor <[email protected]>
Date: Fri, 27 Feb 2026 00:35:01 +0530
Subject: [PATCH] pg_restore: add --no-globals option to skip globals
Do not restore global objects (roles and tablespaces) and even don't create new database if
--create or -C is not specified.
Note: database will be created only if -C is specified, otherwise
restore will be skiped for particular database. If db is already
created, then data of particular db will be restored.
---
doc/src/sgml/ref/pg_restore.sgml | 16 +++++++++++++++-
src/bin/pg_dump/pg_restore.c | 27 +++++++++++++++++++++++----
src/bin/pg_dump/t/001_basic.pl | 6 ++++++
3 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/doc/src/sgml/ref/pg_restore.sgml b/doc/src/sgml/ref/pg_restore.sgml
index 4a21a089840..74107380a75 100644
--- a/doc/src/sgml/ref/pg_restore.sgml
+++ b/doc/src/sgml/ref/pg_restore.sgml
@@ -294,7 +294,21 @@ PostgreSQL documentation
<option>--exit-on-error</option>,
<option>--single-transaction</option>,
<option>--clean</option>, or
- <option>--transaction-size</option>.
+ <option>--transaction-size</option>,
+ <option>--no-globals</option>.
+ </para>
+ </listitem>
+ </varlistentry>
+
+<varlistentry>
+ <term><option>--no-globals</option></term>
+ <listitem>
+ <para>
+ Do not restore global objects (roles and tablespaces) and even don't create new database if
+ <term><option>--create</option></term> or <term><option>--C</option></term> is not specified.
+ </para>
+ <para>
+ This option is only relevant when restoring from a non-plain-text archive made using <application>pg_dumpall</application>.
</para>
</listitem>
</varlistentry>
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index 14d886fc86e..8810f9215d4 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -108,6 +108,7 @@ main(int argc, char **argv)
static int no_security_labels = 0;
static int no_statistics = 0;
static int no_subscriptions = 0;
+ static int no_globals = 0;
static int strict_names = 0;
static int statistics_only = 0;
static int with_statistics = 0;
@@ -171,6 +172,7 @@ main(int argc, char **argv)
{"filter", required_argument, NULL, 4},
{"restrict-key", required_argument, NULL, 6},
{"exclude-database", required_argument, NULL, 7},
+ {"no-globals", no_argument, &no_globals, 1},
{NULL, 0, NULL, 0}
};
@@ -489,6 +491,10 @@ main(int argc, char **argv)
pg_fatal("options %s and %s cannot be used together",
"--statistics", "-g/--globals-only");
+ if (no_globals && globals_only)
+ pg_fatal("options %s and %s cannot be used together",
+ "--no-globals", "-g/--globals-only");
+
/*
* -C is not compatible with -1, because we can't create a database inside
* a transaction block.
@@ -614,9 +620,10 @@ main(int argc, char **argv)
/*
* To restore from a pg_dumpall archive, -C (create database) option
- * must be specified unless we are only restoring globals.
+ * must be specified unless we are only restoring globals or we are
+ * skiping globals.
*/
- if (!globals_only && opts->createDB != 1)
+ if (!no_globals && !globals_only && opts->createDB != 1)
{
pg_log_error("option %s must be specified when restoring an archive created by pg_dumpall",
"-C/--create");
@@ -626,13 +633,17 @@ main(int argc, char **argv)
}
/*
- * Always restore global objects, even if --exclude-database results
+ * Restore global objects, even if --exclude-database results
* in zero databases to process. If 'globals-only' is set, exit
* immediately.
*/
snprintf(global_path, MAXPGPATH, "%s/toc.glo", inputFileSpec);
- n_errors = restore_global_objects(global_path, tmpopts);
+ if (!no_globals)
+ n_errors = restore_global_objects(global_path, tmpopts);
+ else
+ pg_log_info("toc.glo(globals) restoring skipped because option %s is specified",
+ "--no-globals");
if (globals_only)
pg_log_info("database restoring skipped because option %s was specified",
@@ -831,6 +842,7 @@ usage(const char *progname)
printf(_(" --no-subscriptions do not restore subscriptions\n"));
printf(_(" --no-table-access-method do not restore table access methods\n"));
printf(_(" --no-tablespaces do not restore tablespace assignments\n"));
+ printf(_(" --no-globals do not restore global objects (roles and tablespaces)\n"));
printf(_(" --restrict-key=RESTRICT_KEY use provided string as psql \\restrict key\n"));
printf(_(" --section=SECTION restore named section (pre-data, data, or post-data)\n"));
printf(_(" --statistics restore the statistics\n"));
@@ -1349,6 +1361,13 @@ restore_all_databases(const char *inputFileSpec,
}
else
{
+ if (!tmpopts->createDB)
+ {
+ pg_log_info("database %s restoring skipped because options %s and %s=false are specified with dump of pg_dumpall",
+ dbidname->str, "--no-globals", "-C/--create" );
+ continue;
+ }
+
/* We'll have to create it */
tmpopts->createDB = 1;
tmpopts->cparams.dbname = connected_db;
diff --git a/src/bin/pg_dump/t/001_basic.pl b/src/bin/pg_dump/t/001_basic.pl
index a895bc314b0..e2d6b30e437 100644
--- a/src/bin/pg_dump/t/001_basic.pl
+++ b/src/bin/pg_dump/t/001_basic.pl
@@ -299,4 +299,10 @@ command_fails_like(
qr/\Qpg_restore: error: option -g\/--globals-only can be used only when restoring an archive created by pg_dumpall\E/,
'When option --globals-only is used in pg_restore with the dump of pg_dump'
);
+
+command_fails_like(
+ [ 'pg_restore', '--globals-only', '--no-globals', '-d', 'xxx', 'dumpdir' ],
+ qr/\Qpg_restore: error: options --no-globals and -g\/--globals-only cannot be used together\E/,
+ 'pg_restore: error: options --no-globals and -g/--globals-only cannot be used together'
+);
done_testing();
--
2.52.0
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: pg_restore add --no-globals option when restored using pg_dumpall non-text dump
2026-02-27 06:27 pg_restore add --no-globals option when restored using pg_dumpall non-text dump Mahendra Singh Thalor <[email protected]>
@ 2026-02-27 07:47 ` Mahendra Singh Thalor <[email protected]>
2026-03-04 21:59 ` Re: pg_restore add --no-globals option when restored using pg_dumpall non-text dump Andrew Dunstan <[email protected]>
0 siblings, 1 reply; 7+ messages in thread
From: Mahendra Singh Thalor @ 2026-02-27 07:47 UTC (permalink / raw)
To: PostgreSQL Hackers <[email protected]>; +Cc: jian he <[email protected]>; tushar <[email protected]>; Andrew Dunstan <[email protected]>
On Fri, 27 Feb 2026 at 11:57, Mahendra Singh Thalor <[email protected]> wrote:
>
> Hi,
> Recently we committed a patch to dump a full cluster with pg_dumpall in non-text archive format and then restore using pg_restore.
> Here, I am proposing a patch to add the "pg_restore --no-globals" option so that users can skip global objects.
>
> I made a patch for pg_restore --no-globals (only pg_restore option, not needed with pg_dumpall as we will filter at restore end, or later we can add for pg_dumpall also.)
>
> Brief:
> pg_restore: add --no-globals option to skip globals
>
> Do not restore global objects (roles and tablespaces) and even don't create new database if
> --create or -C is not specified.
> Note: database will be created only if -C is specified, otherwise
> restore will be skipped for a particular database. If a db is already
> created, then data of a particular db will be restored.
>
> Please review this patch and let me know your feedback.
>
> --
> Thanks and Regards
> Mahendra Singh Thalor
> EnterpriseDB: http://www.enterprisedb.com
Here, I am attaching an updated patch.
--
Thanks and Regards
Mahendra Singh Thalor
EnterpriseDB: http://www.enterprisedb.com
Attachments:
[text/x-patch] v02-pg_restore-add-no-globals-option-to-skip-globals.patch (5.9K, ../../CAKYtNArdcc5kx1MdTtTKFNYiauo3=zCA-NB0LmBCW-RU_kSb3A@mail.gmail.com/2-v02-pg_restore-add-no-globals-option-to-skip-globals.patch)
download | inline diff:
From dd89d42a533f0762b1c211cc8acc0ae20c7cdf8b Mon Sep 17 00:00:00 2001
From: Mahendra Singh Thalor <[email protected]>
Date: Fri, 27 Feb 2026 13:15:07 +0530
Subject: [PATCH] pg_restore: add --no-globals option to skip globals
Do not restore global objects (roles and tablespaces) and even don't create new database if
--create or -C is not specified.
Note: database will be created only if -C is specified, otherwise
restoration will be skipped for the particular database. If db is already
created, the data for that database will be restored.
---
doc/src/sgml/ref/pg_restore.sgml | 16 +++++++++++++++-
src/bin/pg_dump/pg_restore.c | 27 +++++++++++++++++++++++----
src/bin/pg_dump/t/001_basic.pl | 6 ++++++
3 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/doc/src/sgml/ref/pg_restore.sgml b/doc/src/sgml/ref/pg_restore.sgml
index 4a21a089840..1921c97b725 100644
--- a/doc/src/sgml/ref/pg_restore.sgml
+++ b/doc/src/sgml/ref/pg_restore.sgml
@@ -294,7 +294,21 @@ PostgreSQL documentation
<option>--exit-on-error</option>,
<option>--single-transaction</option>,
<option>--clean</option>, or
- <option>--transaction-size</option>.
+ <option>--transaction-size</option>,
+ <option>--no-globals</option>.
+ </para>
+ </listitem>
+ </varlistentry>
+
+<varlistentry>
+ <term><option>--no-globals</option></term>
+ <listitem>
+ <para>
+ Do not restore global objects (roles and tablespaces) and even don't create new database if
+ <option>--create</option> or <option>-C</option> is not specified.
+ </para>
+ <para>
+ This option is only relevant when restoring from a non-plain-text archive made using <application>pg_dumpall</application>.
</para>
</listitem>
</varlistentry>
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index 14d886fc86e..8810f9215d4 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -108,6 +108,7 @@ main(int argc, char **argv)
static int no_security_labels = 0;
static int no_statistics = 0;
static int no_subscriptions = 0;
+ static int no_globals = 0;
static int strict_names = 0;
static int statistics_only = 0;
static int with_statistics = 0;
@@ -171,6 +172,7 @@ main(int argc, char **argv)
{"filter", required_argument, NULL, 4},
{"restrict-key", required_argument, NULL, 6},
{"exclude-database", required_argument, NULL, 7},
+ {"no-globals", no_argument, &no_globals, 1},
{NULL, 0, NULL, 0}
};
@@ -489,6 +491,10 @@ main(int argc, char **argv)
pg_fatal("options %s and %s cannot be used together",
"--statistics", "-g/--globals-only");
+ if (no_globals && globals_only)
+ pg_fatal("options %s and %s cannot be used together",
+ "--no-globals", "-g/--globals-only");
+
/*
* -C is not compatible with -1, because we can't create a database inside
* a transaction block.
@@ -614,9 +620,10 @@ main(int argc, char **argv)
/*
* To restore from a pg_dumpall archive, -C (create database) option
- * must be specified unless we are only restoring globals.
+ * must be specified unless we are only restoring globals or we are
+ * skiping globals.
*/
- if (!globals_only && opts->createDB != 1)
+ if (!no_globals && !globals_only && opts->createDB != 1)
{
pg_log_error("option %s must be specified when restoring an archive created by pg_dumpall",
"-C/--create");
@@ -626,13 +633,17 @@ main(int argc, char **argv)
}
/*
- * Always restore global objects, even if --exclude-database results
+ * Restore global objects, even if --exclude-database results
* in zero databases to process. If 'globals-only' is set, exit
* immediately.
*/
snprintf(global_path, MAXPGPATH, "%s/toc.glo", inputFileSpec);
- n_errors = restore_global_objects(global_path, tmpopts);
+ if (!no_globals)
+ n_errors = restore_global_objects(global_path, tmpopts);
+ else
+ pg_log_info("toc.glo(globals) restoring skipped because option %s is specified",
+ "--no-globals");
if (globals_only)
pg_log_info("database restoring skipped because option %s was specified",
@@ -831,6 +842,7 @@ usage(const char *progname)
printf(_(" --no-subscriptions do not restore subscriptions\n"));
printf(_(" --no-table-access-method do not restore table access methods\n"));
printf(_(" --no-tablespaces do not restore tablespace assignments\n"));
+ printf(_(" --no-globals do not restore global objects (roles and tablespaces)\n"));
printf(_(" --restrict-key=RESTRICT_KEY use provided string as psql \\restrict key\n"));
printf(_(" --section=SECTION restore named section (pre-data, data, or post-data)\n"));
printf(_(" --statistics restore the statistics\n"));
@@ -1349,6 +1361,13 @@ restore_all_databases(const char *inputFileSpec,
}
else
{
+ if (!tmpopts->createDB)
+ {
+ pg_log_info("database %s restoring skipped because options %s and %s=false are specified with dump of pg_dumpall",
+ dbidname->str, "--no-globals", "-C/--create" );
+ continue;
+ }
+
/* We'll have to create it */
tmpopts->createDB = 1;
tmpopts->cparams.dbname = connected_db;
diff --git a/src/bin/pg_dump/t/001_basic.pl b/src/bin/pg_dump/t/001_basic.pl
index a895bc314b0..e2d6b30e437 100644
--- a/src/bin/pg_dump/t/001_basic.pl
+++ b/src/bin/pg_dump/t/001_basic.pl
@@ -299,4 +299,10 @@ command_fails_like(
qr/\Qpg_restore: error: option -g\/--globals-only can be used only when restoring an archive created by pg_dumpall\E/,
'When option --globals-only is used in pg_restore with the dump of pg_dump'
);
+
+command_fails_like(
+ [ 'pg_restore', '--globals-only', '--no-globals', '-d', 'xxx', 'dumpdir' ],
+ qr/\Qpg_restore: error: options --no-globals and -g\/--globals-only cannot be used together\E/,
+ 'pg_restore: error: options --no-globals and -g/--globals-only cannot be used together'
+);
done_testing();
--
2.52.0
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: pg_restore add --no-globals option when restored using pg_dumpall non-text dump
2026-02-27 06:27 pg_restore add --no-globals option when restored using pg_dumpall non-text dump Mahendra Singh Thalor <[email protected]>
2026-02-27 07:47 ` Re: pg_restore add --no-globals option when restored using pg_dumpall non-text dump Mahendra Singh Thalor <[email protected]>
@ 2026-03-04 21:59 ` Andrew Dunstan <[email protected]>
0 siblings, 0 replies; 7+ messages in thread
From: Andrew Dunstan @ 2026-03-04 21:59 UTC (permalink / raw)
To: Mahendra Singh Thalor <[email protected]>; PostgreSQL Hackers <[email protected]>; +Cc: jian he <[email protected]>; tushar <[email protected]>
On 2026-02-27 Fr 2:47 AM, Mahendra Singh Thalor wrote:
> On Fri, 27 Feb 2026 at 11:57, Mahendra Singh Thalor<[email protected]> wrote:
>> Hi,
>> Recently we committed a patch to dump a full cluster with pg_dumpall in non-text archive format and then restore using pg_restore.
>> Here, I am proposing a patch to add the "pg_restore --no-globals" option so that users can skip global objects.
>>
>> I made a patch for pg_restore --no-globals (only pg_restore option, not needed with pg_dumpall as we will filter at restore end, or later we can add for pg_dumpall also.)
>>
>> Brief:
>> pg_restore: add --no-globals option to skip globals
>>
>> Do not restore global objects (roles and tablespaces) and even don't create new database if
>> --create or -C is not specified.
>> Note: database will be created only if -C is specified, otherwise
>> restore will be skipped for a particular database. If a db is already
>> created, then data of a particular db will be restored.
>>
>> Please review this patch and let me know your feedback.
>>
>> --
>> Thanks and Regards
>> Mahendra Singh Thalor
>> EnterpriseDB:http://www.enterprisedb.com
> Here, I am attaching an updated patch.
Thanks, I have pushed a version of this.
cheers
andrew
--
Andrew Dunstan
EDB:https://www.enterprisedb.com
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2026-03-04 21:59 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-09-13 17:07 [PATCH v15 03/14] meson: prereq: De-special-case pgevent's rc file handling Andres Freund <[email protected]>
2022-09-13 17:07 [PATCH v13 11/20] meson: prereq: De-special-case pgevent's rc file handling Andres Freund <[email protected]>
2022-09-13 17:07 [PATCH v13 11/20] meson: prereq: De-special-case pgevent's rc file handling Andres Freund <[email protected]>
2025-01-26 20:18 [PATCH v8 04/10] heapam: Use exclusive lock on old page in CLUSTER Andres Freund <[email protected]>
2026-02-27 06:27 pg_restore add --no-globals option when restored using pg_dumpall non-text dump Mahendra Singh Thalor <[email protected]>
2026-02-27 07:47 ` Re: pg_restore add --no-globals option when restored using pg_dumpall non-text dump Mahendra Singh Thalor <[email protected]>
2026-03-04 21:59 ` Re: pg_restore add --no-globals option when restored using pg_dumpall non-text dump Andrew Dunstan <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox