Skip to content

Commit 3c2aa0c

Browse files
committed
psql: complain if pg_dump custom-format is detected
Apparently, this is a very common mistake for users to make; it is better to have it fail reasonably rather than throw potentially a large number of errors. Since we have a magic string at the start of the file, we can detect the case easily and there's no other possible useful behavior anyway. Author: Craig Ringer
1 parent b01a4f6 commit 3c2aa0c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/bin/psql/mainloop.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ MainLoop(FILE *source)
175175
if (pset.lineno == 1 && pset.encoding == PG_UTF8 && strncmp(line, "\xef\xbb\xbf", 3) == 0)
176176
memmove(line, line + 3, strlen(line + 3) + 1);
177177

178+
/* Detect attempts to run custom-format dumps as SQL scripts */
179+
if (pset.lineno == 1 && !pset.cur_cmd_interactive &&
180+
strncmp(line, "PGDMP", 5) == 0)
181+
{
182+
free(line);
183+
puts(_("The input is a PostgreSQL custom-format dump.\n"
184+
"Use the pg_restore command-line client to restore this dump to a database.\n"));
185+
fflush(stdout);
186+
successResult = EXIT_FAILURE;
187+
break;
188+
}
189+
178190
/* nothing left on line? then ignore */
179191
if (line[0] == '\0' && !psql_scan_in_quote(scan_state))
180192
{

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