diff --git a/src/bin/psql/mainloop.c b/src/bin/psql/mainloop.c index 98211dcb2a..7b02609701 100644 --- a/src/bin/psql/mainloop.c +++ b/src/bin/psql/mainloop.c @@ -175,6 +175,18 @@ MainLoop(FILE *source) if (pset.lineno == 1 && pset.encoding == PG_UTF8 && strncmp(line, "\xef\xbb\xbf", 3) == 0) memmove(line, line + 3, strlen(line + 3) + 1); + /* Detect attempts to run custom-format dumps as SQL scripts */ + if (pset.lineno == 1 && !pset.cur_cmd_interactive && + strncmp(line, "PGDMP", 5) == 0) + { + free(line); + puts(_("The input is a PostgreSQL custom-format dump.\n" + "Use the pg_restore command-line client to restore this dump to a database.\n")); + fflush(stdout); + successResult = EXIT_FAILURE; + break; + } + /* nothing left on line? then ignore */ if (line[0] == '\0' && !psql_scan_in_quote(scan_state)) {