Skip to content

Commit 4a9ee86

Browse files
committed
Revert Non text modes for pg_dumpall, and pg_restore support
Recent discussions of the mechanisms used to manage global data have raised concerns about their robustness and security. Rather than try to deal with those concerns at a very late stage of the release cycle, the conclusion is to revert these features and work on them for the next release. This reverts parts or all of the following commits: 1495eff Non text modes for pg_dumpall, correspondingly change pg_restore 5db3bf7 Clean up from commit 1495eff 289f74d Add more TAP tests for pg_dumpall 2ef5790 Fix a couple of error messages and tests for them b52a4a5 Clean up error messages from 1495eff 4170298 Further cleanup for directory creation on pg_dump/pg_dumpall 22cb6d2 Fix memory leak in pg_restore.c 928394b Improve various new-to-v18 appendStringInfo calls 39729ec Fix fat fingering in 22cb6d2 5822bf2 Add missing space in pg_restore documentation. f09088a Free memory properly in pg_restore.c 40b9c27 pg_restore cleanups 4aad2cb Portability fix: isdigit() must be passed an unsigned char. 88e9471 Fix typos and grammar in the code f60420c doc: Alphabetize long options for pg_dump[all]. bc35ade doc: Put new options in consistent order on man pages a876464 Message style improvements dec6643 Improve pg_dump/pg_dumpall help synopses and terminology 0ebd242 Run pgperltidy Discussion: https://postgr.es/m/20250708212819.09.nmisch@google.com Backpatch-to: 18 Reviewed-by: Noah Misch <noah@leadboat.com>
1 parent cd2d52c commit 4a9ee86

File tree

13 files changed

+85
-1540
lines changed

13 files changed

+85
-1540
lines changed

doc/src/sgml/ref/pg_dumpall.sgml

Lines changed: 3 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ PostgreSQL documentation
1616

1717
<refnamediv>
1818
<refname>pg_dumpall</refname>
19-
20-
<refpurpose>
21-
export a <productname>PostgreSQL</productname> database cluster as an SQL script or to other formats
22-
</refpurpose>
19+
<refpurpose>extract a <productname>PostgreSQL</productname> database cluster into a script file</refpurpose>
2320
</refnamediv>
2421

2522
<refsynopsisdiv>
@@ -36,7 +33,7 @@ PostgreSQL documentation
3633
<para>
3734
<application>pg_dumpall</application> is a utility for writing out
3835
(<quote>dumping</quote>) all <productname>PostgreSQL</productname> databases
39-
of a cluster into an SQL script file or an archive. The output contains
36+
of a cluster into one script file. The script file contains
4037
<acronym>SQL</acronym> commands that can be used as input to <xref
4138
linkend="app-psql"/> to restore the databases. It does this by
4239
calling <xref linkend="app-pgdump"/> for each database in the cluster.
@@ -55,16 +52,11 @@ PostgreSQL documentation
5552
</para>
5653

5754
<para>
58-
Plain text SQL scripts will be written to the standard output. Use the
55+
The SQL script will be written to the standard output. Use the
5956
<option>-f</option>/<option>--file</option> option or shell operators to
6057
redirect it into a file.
6158
</para>
6259

63-
<para>
64-
Archives in other formats will be placed in a directory named using the
65-
<option>-f</option>/<option>--file</option>, which is required in this case.
66-
</para>
67-
6860
<para>
6961
<application>pg_dumpall</application> needs to connect several
7062
times to the <productname>PostgreSQL</productname> server (once per
@@ -129,85 +121,10 @@ PostgreSQL documentation
129121
<para>
130122
Send output to the specified file. If this is omitted, the
131123
standard output is used.
132-
Note: This option can only be omitted when <option>--format</option> is plain
133124
</para>
134125
</listitem>
135126
</varlistentry>
136127

137-
<varlistentry>
138-
<term><option>-F <replaceable class="parameter">format</replaceable></option></term>
139-
<term><option>--format=<replaceable class="parameter">format</replaceable></option></term>
140-
<listitem>
141-
<para>
142-
Specify the format of dump files. In plain format, all the dump data is
143-
sent in a single text stream. This is the default.
144-
145-
In all other modes, <application>pg_dumpall</application> first creates two files:
146-
<filename>global.dat</filename> and <filename>map.dat</filename>, in the directory
147-
specified by <option>--file</option>.
148-
The first file contains global data, such as roles and tablespaces. The second
149-
contains a mapping between database oids and names. These files are used by
150-
<application>pg_restore</application>. Data for individual databases is placed in
151-
<filename>databases</filename> subdirectory, named using the database's <type>oid</type>.
152-
153-
<variablelist>
154-
<varlistentry>
155-
<term><literal>d</literal></term>
156-
<term><literal>directory</literal></term>
157-
<listitem>
158-
<para>
159-
Output directory-format archives for each database,
160-
suitable for input into pg_restore. The directory
161-
will have database <type>oid</type> as its name.
162-
</para>
163-
</listitem>
164-
</varlistentry>
165-
166-
<varlistentry>
167-
<term><literal>p</literal></term>
168-
<term><literal>plain</literal></term>
169-
<listitem>
170-
<para>
171-
Output a plain-text SQL script file (the default).
172-
</para>
173-
</listitem>
174-
</varlistentry>
175-
176-
<varlistentry>
177-
<term><literal>c</literal></term>
178-
<term><literal>custom</literal></term>
179-
<listitem>
180-
<para>
181-
Output a custom-format archive for each database,
182-
suitable for input into pg_restore. The archive
183-
will be named <filename>dboid.dmp</filename> where <type>dboid</type> is the
184-
<type>oid</type> of the database.
185-
</para>
186-
</listitem>
187-
</varlistentry>
188-
189-
<varlistentry>
190-
<term><literal>t</literal></term>
191-
<term><literal>tar</literal></term>
192-
<listitem>
193-
<para>
194-
Output a tar-format archive for each database,
195-
suitable for input into pg_restore. The archive
196-
will be named <filename>dboid.tar</filename> where <type>dboid</type> is the
197-
<type>oid</type> of the database.
198-
</para>
199-
</listitem>
200-
</varlistentry>
201-
202-
</variablelist>
203-
204-
Note: see <xref linkend="app-pgdump"/> for details
205-
of how the various non plain text archives work.
206-
207-
</para>
208-
</listitem>
209-
</varlistentry>
210-
211128
<varlistentry>
212129
<term><option>-g</option></term>
213130
<term><option>--globals-only</option></term>

doc/src/sgml/ref/pg_restore.sgml

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ PostgreSQL documentation
1818
<refname>pg_restore</refname>
1919

2020
<refpurpose>
21-
restore <productname>PostgreSQL</productname> databases from archives
22-
created by <application>pg_dump</application> or
23-
<application>pg_dumpall</application>
21+
restore a <productname>PostgreSQL</productname> database from an
22+
archive file created by <application>pg_dump</application>
2423
</refpurpose>
2524
</refnamediv>
2625

@@ -39,32 +38,24 @@ PostgreSQL documentation
3938

4039
<para>
4140
<application>pg_restore</application> is a utility for restoring a
42-
<productname>PostgreSQL</productname> database or cluster from an archive
43-
created by <xref linkend="app-pgdump"/> or
44-
<xref linkend="app-pg-dumpall"/> in one of the non-plain-text
41+
<productname>PostgreSQL</productname> database from an archive
42+
created by <xref linkend="app-pgdump"/> in one of the non-plain-text
4543
formats. It will issue the commands necessary to reconstruct the
46-
database or cluster to the state it was in at the time it was saved. The
47-
archives also allow <application>pg_restore</application> to
44+
database to the state it was in at the time it was saved. The
45+
archive files also allow <application>pg_restore</application> to
4846
be selective about what is restored, or even to reorder the items
49-
prior to being restored. The archive formats are designed to be
47+
prior to being restored. The archive files are designed to be
5048
portable across architectures.
5149
</para>
5250

5351
<para>
5452
<application>pg_restore</application> can operate in two modes.
5553
If a database name is specified, <application>pg_restore</application>
5654
connects to that database and restores archive contents directly into
57-
the database.
58-
When restoring from a dump made by <application>pg_dumpall</application>,
59-
each database will be created and then the restoration will be run in that
60-
database.
61-
62-
Otherwise, when a database name is not specified, a script containing the SQL
63-
commands necessary to rebuild the database or cluster is created and written
55+
the database. Otherwise, a script containing the SQL
56+
commands necessary to rebuild the database is created and written
6457
to a file or standard output. This script output is equivalent to
65-
the plain text output format of <application>pg_dump</application> or
66-
<application>pg_dumpall</application>.
67-
58+
the plain text output format of <application>pg_dump</application>.
6859
Some of the options controlling the output are therefore analogous to
6960
<application>pg_dump</application> options.
7061
</para>
@@ -149,8 +140,6 @@ PostgreSQL documentation
149140
commands that mention this database.
150141
Access privileges for the database itself are also restored,
151142
unless <option>--no-acl</option> is specified.
152-
<option>--create</option> is required when restoring multiple databases
153-
from an archive created by <application>pg_dumpall</application>.
154143
</para>
155144

156145
<para>
@@ -246,19 +235,6 @@ PostgreSQL documentation
246235
</listitem>
247236
</varlistentry>
248237

249-
<varlistentry>
250-
<term><option>-g</option></term>
251-
<term><option>--globals-only</option></term>
252-
<listitem>
253-
<para>
254-
Restore only global objects (roles and tablespaces), no databases.
255-
</para>
256-
<para>
257-
This option is only relevant when restoring from an archive made using <application>pg_dumpall</application>.
258-
</para>
259-
</listitem>
260-
</varlistentry>
261-
262238
<varlistentry>
263239
<term><option>-I <replaceable class="parameter">index</replaceable></option></term>
264240
<term><option>--index=<replaceable class="parameter">index</replaceable></option></term>
@@ -603,28 +579,6 @@ PostgreSQL documentation
603579
</listitem>
604580
</varlistentry>
605581

606-
<varlistentry>
607-
<term><option>--exclude-database=<replaceable class="parameter">pattern</replaceable></option></term>
608-
<listitem>
609-
<para>
610-
Do not restore databases whose name matches
611-
<replaceable class="parameter">pattern</replaceable>.
612-
Multiple patterns can be excluded by writing multiple
613-
<option>--exclude-database</option> switches. The
614-
<replaceable class="parameter">pattern</replaceable> parameter is
615-
interpreted as a pattern according to the same rules used by
616-
<application>psql</application>'s <literal>\d</literal>
617-
commands (see <xref linkend="app-psql-patterns"/>),
618-
so multiple databases can also be excluded by writing wildcard
619-
characters in the pattern. When using wildcards, be careful to
620-
quote the pattern if needed to prevent shell wildcard expansion.
621-
</para>
622-
<para>
623-
This option is only relevant when restoring from an archive made using <application>pg_dumpall</application>.
624-
</para>
625-
</listitem>
626-
</varlistentry>
627-
628582
<varlistentry>
629583
<term><option>--filter=<replaceable class="parameter">filename</replaceable></option></term>
630584
<listitem>

src/bin/pg_dump/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ tests += {
102102
't/003_pg_dump_with_server.pl',
103103
't/004_pg_dump_parallel.pl',
104104
't/005_pg_dump_filterfile.pl',
105-
't/006_pg_dumpall.pl',
106105
't/010_dump_connstr.pl',
107106
],
108107
},

src/bin/pg_dump/parallel.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,6 @@ on_exit_close_archive(Archive *AHX)
333333
on_exit_nicely(archive_close_connection, &shutdown_info);
334334
}
335335

336-
/*
337-
* When pg_restore restores multiple databases, then update already added entry
338-
* into array for cleanup.
339-
*/
340-
void
341-
replace_on_exit_close_archive(Archive *AHX)
342-
{
343-
shutdown_info.AHX = AHX;
344-
}
345-
346336
/*
347337
* on_exit_nicely handler for shutting down database connections and
348338
* worker processes cleanly.

src/bin/pg_dump/pg_backup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ extern void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ro
308308

309309
extern void ProcessArchiveRestoreOptions(Archive *AHX);
310310

311-
extern void RestoreArchive(Archive *AHX, bool append_data);
311+
extern void RestoreArchive(Archive *AHX);
312312

313313
/* Open an existing archive */
314314
extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static int RestoringToDB(ArchiveHandle *AH);
8585
static void dump_lo_buf(ArchiveHandle *AH);
8686
static void dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim);
8787
static void SetOutput(ArchiveHandle *AH, const char *filename,
88-
const pg_compress_specification compression_spec, bool append_data);
88+
const pg_compress_specification compression_spec);
8989
static CompressFileHandle *SaveOutput(ArchiveHandle *AH);
9090
static void RestoreOutput(ArchiveHandle *AH, CompressFileHandle *savedOutput);
9191

@@ -337,14 +337,9 @@ ProcessArchiveRestoreOptions(Archive *AHX)
337337
StrictNamesCheck(ropt);
338338
}
339339

340-
/*
341-
* RestoreArchive
342-
*
343-
* If append_data is set, then append data into file as we are restoring dump
344-
* of multiple databases which was taken by pg_dumpall.
345-
*/
340+
/* Public */
346341
void
347-
RestoreArchive(Archive *AHX, bool append_data)
342+
RestoreArchive(Archive *AHX)
348343
{
349344
ArchiveHandle *AH = (ArchiveHandle *) AHX;
350345
RestoreOptions *ropt = AH->public.ropt;
@@ -461,7 +456,7 @@ RestoreArchive(Archive *AHX, bool append_data)
461456
*/
462457
sav = SaveOutput(AH);
463458
if (ropt->filename || ropt->compression_spec.algorithm != PG_COMPRESSION_NONE)
464-
SetOutput(AH, ropt->filename, ropt->compression_spec, append_data);
459+
SetOutput(AH, ropt->filename, ropt->compression_spec);
465460

466461
ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n");
467462

@@ -1300,7 +1295,7 @@ PrintTOCSummary(Archive *AHX)
13001295

13011296
sav = SaveOutput(AH);
13021297
if (ropt->filename)
1303-
SetOutput(AH, ropt->filename, out_compression_spec, false);
1298+
SetOutput(AH, ropt->filename, out_compression_spec);
13041299

13051300
if (strftime(stamp_str, sizeof(stamp_str), PGDUMP_STRFTIME_FMT,
13061301
localtime(&AH->createDate)) == 0)
@@ -1679,8 +1674,7 @@ archprintf(Archive *AH, const char *fmt,...)
16791674

16801675
static void
16811676
SetOutput(ArchiveHandle *AH, const char *filename,
1682-
const pg_compress_specification compression_spec,
1683-
bool append_data)
1677+
const pg_compress_specification compression_spec)
16841678
{
16851679
CompressFileHandle *CFH;
16861680
const char *mode;
@@ -1700,7 +1694,7 @@ SetOutput(ArchiveHandle *AH, const char *filename,
17001694
else
17011695
fn = fileno(stdout);
17021696

1703-
if (append_data || AH->mode == archModeAppend)
1697+
if (AH->mode == archModeAppend)
17041698
mode = PG_BINARY_A;
17051699
else
17061700
mode = PG_BINARY_W;

src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ struct _tocEntry
394394

395395
extern int parallel_restore(ArchiveHandle *AH, TocEntry *te);
396396
extern void on_exit_close_archive(Archive *AHX);
397-
extern void replace_on_exit_close_archive(Archive *AHX);
398397

399398
extern void warn_or_exit_horribly(ArchiveHandle *AH, const char *fmt,...) pg_attribute_printf(2, 3);
400399

src/bin/pg_dump/pg_backup_tar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ _CloseArchive(ArchiveHandle *AH)
826826
savVerbose = AH->public.verbose;
827827
AH->public.verbose = 0;
828828

829-
RestoreArchive((Archive *) AH, false);
829+
RestoreArchive((Archive *) AH);
830830

831831
SetArchiveOptions((Archive *) AH, savDopt, savRopt);
832832

src/bin/pg_dump/pg_dump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ main(int argc, char **argv)
12271227
* right now.
12281228
*/
12291229
if (plainText)
1230-
RestoreArchive(fout, false);
1230+
RestoreArchive(fout);
12311231

12321232
CloseArchive(fout);
12331233

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy