1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

They are two different problems; the TOC entry is important for any

multiline command  or to rerun the command easily later.

Whereas displaying the failed SQL command is a matter of fixing the
error
messages.

The latter is complicated by failed COPY commands which, with
die-on-errors
off, results in the data being processed as a command, so dumping the
command will dump all of the data.

In the case of long commands, should the whole command be dumped? eg.
(eg.
several pages of function definition).

In the case of the COPY command, I'm not sure what to do. Obviously, it
would be best to avoid sending the data, but the data and command are
combined (from memory). Also, the 'data' may be in the form of INSERT
statements.

Attached patch produces the first 125 chars of the command:

pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC Entry 26; 1255 16449270
FUNCTION
plpgsql_call_handler() pjw
pg_restore: [archiver (db)] could not execute query: ERROR:  function
"plpgsql_call_handler" already exists with same argument types
     Command was: CREATE FUNCTION plpgsql_call_handler() RETURNS
language_handler
     AS '/var/lib/pgsql-8.0b1/lib/plpgsql', 'plpgsql_call_han...
pg_restore: [archiver (db)] Error from TOC Entry 27; 1255 16449271
FUNCTION
plpgsql_validator(oid) pjw
pg_restore: [archiver (db)] could not execute query: ERROR:  function
"plpgsql_validator" already exists with same argument types
     Command was: CREATE FUNCTION plpgsql_validator(oid) RETURNS void
     AS '/var/lib/pgsql-8.0b1/lib/plpgsql', 'plpgsql_validator'
     LANGU...

Philip Warner
This commit is contained in:
Bruce Momjian
2004-08-20 20:00:34 +00:00
parent b43fd16eec
commit f7168bd44c
3 changed files with 84 additions and 5 deletions

View File

@ -5,7 +5,7 @@
* Implements the basic DB functions used by the archiver.
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.54 2004/08/20 16:07:15 momjian Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.55 2004/08/20 20:00:34 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -40,6 +40,8 @@ static char *_sendCopyLine(ArchiveHandle *AH, char *qry, char *eos);
static int _isIdentChar(char c);
static int _isDQChar(char c, int atStart);
#define DB_MAX_ERR_STMT 128
static int
_parse_version(ArchiveHandle *AH, const char *versionString)
{
@ -302,6 +304,7 @@ static int
_executeSqlCommand(ArchiveHandle *AH, PGconn *conn, PQExpBuffer qry, char *desc)
{
PGresult *res;
char errStmt[DB_MAX_ERR_STMT];
/* fprintf(stderr, "Executing: '%s'\n\n", qry->data); */
res = PQexec(conn, qry->data);
@ -318,8 +321,18 @@ _executeSqlCommand(ArchiveHandle *AH, PGconn *conn, PQExpBuffer qry, char *desc)
AH->pgCopyIn = 1;
}
else
warn_or_die_horribly(AH, modulename, "%s: %s",
desc, PQerrorMessage(AH->connection));
{
strncpy(errStmt, qry->data, DB_MAX_ERR_STMT);
if (errStmt[DB_MAX_ERR_STMT-1] != '\0') {
errStmt[DB_MAX_ERR_STMT-4] = '.';
errStmt[DB_MAX_ERR_STMT-3] = '.';
errStmt[DB_MAX_ERR_STMT-2] = '.';
errStmt[DB_MAX_ERR_STMT-1] = '\0';
}
warn_or_die_horribly(AH, modulename, "%s: %s Command was: %s\n",
desc, PQerrorMessage(AH->connection),
errStmt);
}
}
PQclear(res);