Re: Non-text mode for pg_dumpall - Mailing list pgsql-hackers

From Andrew Dunstan
Subject Re: Non-text mode for pg_dumpall
Date
Msg-id 59d3616f-6d6d-40d5-87e2-e019e350b52d@dunslane.net
Whole thread Raw
In response to Re: Non-text mode for pg_dumpall  (jian he <jian.universality@gmail.com>)
Responses Re: Non-text mode for pg_dumpall
List pgsql-hackers


On 2026-02-20 Fr 9:15 PM, jian he wrote:
Hi.
        RestoreOptions *tmpopts = (RestoreOptions *)
pg_malloc0(sizeof(RestoreOptions));
need change to        RestoreOptions *tmpopts = pg_malloc0_object(RestoreOptions);


Fixed



+  <para>
+   If the dump was taken in a non-plain-text format, use
+   <application>pg_restore</application> to restore the databases:
+<screen>
+<prompt>$</prompt> <userinput>pg_restore db.out -d postgres -C</userinput>
+</screen>
+   This will restore all databases. To restore only some databases, use
+   the <option>--exclude-database</option> option to skip those not wanted.
+  </para>

The change above was added to pg_dumpall.sgml, which seems inappropriate;
it would be more correct to place it in pg_restore.sgml.


I don't agree. The previous paragraph mentions using psql to restore a text dump, so mentioning pg_restore for a non-text dump seems reasonable.

But I have added a para to the pg_restore docs explaining how it processes pg_dumpall archives.



+     <varlistentry>
+      <term><option>-g</option></term>
+      <term><option>--globals-only</option></term>
+      <listitem>
+       <para>
+        Restore only global objects (roles and tablespaces), no databases.
+       </para>
+       <para>
+        This option is only relevant when restoring from an archive
made using <application>pg_dumpall</application>.
+        Note: <option>--globals-only</option> cannot be used with
<option>--exit-on-error</option>,
+              <option>--single-transaction</option>,
<option>--clean</option>, or <option>--transaction-size</option>.
+       </para>
+      </listitem>
+     </varlistentry>
+
<option>--globals-only</option> cannot be used with --data-only,
--schema-only, --statistics-only, --statistics.
We should also mention that.


Fixed



In doc/src/sgml/ref/pg_restore.sgml
"when restoring from an archive made using pg_dumpall."
It  would be better using
"when restoring from a non-plain-text archive made using pg_dumpall."
that would be aligned with pg_dumpall.sgml.
      <varlistentry>       <term><option>-g</option></term>       <term><option>--globals-only</option></term>       <listitem>        <para>         Dump only global objects (roles and tablespaces), no databases.
+        Note: <option>--globals-only</option> cannot be used with
+        <option>--clean</option> with non-text dump format.        </para>
Elsewhere, we use the term “non-plain-text,” so we should use
“non-plain-text” here as well instead of “non-text,” for consistency.

In doc/src/sgml/ref/pg_restore.sgml, We did not mention that many
options cannot be used with pg_restore when performing a
non-plain-text restore.
Like:
"-l/--list"
"-L/--use-list"
"--strict-names"
"--no-schema"
"-a/--data-only"
"--statistics-only"
--section does not include "--pre-data"


Fixed, but ...


What about options like these?:

  n/--schema
  N/--exclude-schema
  t/--table
  T/--trigger
  I/--index
  P/--function
  -filter

We're not currently doing anything about those, but do they make sense when restoring a pg_dumpall archive?



pg_restore --clean --format=directory will produce DROP DATABASE will
process global objects,
it will also produce DROP DATABASE when processing each individual database.
To prevent errors during a subsequent restore, we can require
pg_restore --clean option must be used together with --if-exists when
restoring a non-plain-text dump.


We could. Or we could just turn it on (and document that it will be turned on) in this case. I'd rather not force people to use lots of flags.


Patch attached with the above noted fixes. It also adds a header comment to map.dat and has pg_restore ignore comment lines (anything that doesn't begin with a digit).


cheers


andrew

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

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: generating function default settings from pg_proc.dat
Next
From: Marcos Pegoraro
Date:
Subject: Re: Partial Mode in Aggregate Functions