Skip to content

Commit 54a622c

Browse files
committed
Suggest use of psql when pg_restore gets a text dump.
1 parent bc2a050 commit 54a622c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ typedef struct _parallel_slot
7777

7878
#define NO_SLOT (-1)
7979

80+
#define TEXT_DUMP_HEADER "--\n-- PostgreSQL database dump\n--\n\n"
81+
#define TEXT_DUMPALL_HEADER "--\n-- PostgreSQL database cluster dump\n--\n\n"
82+
8083
/* state needed to save/restore an archive's output target */
8184
typedef struct _outputContext
8285
{
@@ -1862,12 +1865,20 @@ _discoverArchiveFormat(ArchiveHandle *AH)
18621865
else
18631866
{
18641867
/*
1865-
* *Maybe* we have a tar archive format file... So, read first 512
1866-
* byte header...
1868+
* *Maybe* we have a tar archive format file or a text dump ...
1869+
* So, read first 512 byte header...
18671870
*/
18681871
cnt = fread(&AH->lookahead[AH->lookaheadLen], 1, 512 - AH->lookaheadLen, fh);
18691872
AH->lookaheadLen += cnt;
18701873

1874+
if (AH->lookaheadLen >= strlen(TEXT_DUMPALL_HEADER) &&
1875+
(strncmp(AH->lookahead, TEXT_DUMP_HEADER, strlen(TEXT_DUMP_HEADER)) == 0 ||
1876+
strncmp(AH->lookahead, TEXT_DUMPALL_HEADER, strlen(TEXT_DUMPALL_HEADER)) == 0))
1877+
{
1878+
/* looks like it's probably a text format dump. so suggest they try psql */
1879+
die_horribly(AH, modulename, "input file appears to be a text format dump. Please use psql.\n");
1880+
}
1881+
18711882
if (AH->lookaheadLen != 512)
18721883
die_horribly(AH, modulename, "input file does not appear to be a valid archive (too short?)\n");
18731884

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