diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-03-03 23:38:30 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-03-03 23:38:30 +0000 |
| commit | decdaf3592dfa05642373a7bffcb431e45cc5aac (patch) | |
| tree | e994bb79bcc1772b1166967e06f226d9984ef90f /src/bin/pg_dump/pg_dump.c | |
| parent | 0b1b010c12d6682d0b9d4802f6b014aaef61dfcd (diff) | |
| download | postgresql-decdaf3592dfa05642373a7bffcb431e45cc5aac.tar.gz | |
Improve pg_dump and psql to use libpq's newer COPY support routines,
instead of the old deprecated ones.
Volkan Yazici, with some editorializing by moi.
Diffstat (limited to 'src/bin/pg_dump/pg_dump.c')
| -rw-r--r-- | src/bin/pg_dump/pg_dump.c | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 4eb2cafc19..535104d83e 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -12,7 +12,7 @@ * by PostgreSQL * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.431 2006/03/02 01:18:25 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.432 2006/03/03 23:38:29 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -831,8 +831,6 @@ selectDumpableObject(DumpableObject *dobj) * to be dumped. */ -#define COPYBUFSIZ 8192 - static int dumpTableData_copy(Archive *fout, void *dcontext) { @@ -844,8 +842,7 @@ dumpTableData_copy(Archive *fout, void *dcontext) PQExpBuffer q = createPQExpBuffer(); PGresult *res; int ret; - bool copydone; - char copybuf[COPYBUFSIZ]; + char *copybuf; const char *column_list; if (g_verbose) @@ -886,33 +883,19 @@ dumpTableData_copy(Archive *fout, void *dcontext) } res = PQexec(g_conn, q->data); check_sql_result(res, g_conn, q->data, PGRES_COPY_OUT); + PQclear(res); - copydone = false; - - while (!copydone) + for (;;) { - ret = PQgetline(g_conn, copybuf, COPYBUFSIZ); + ret = PQgetCopyData(g_conn, ©buf, 0); + + if (ret < 0) + break; /* done or error */ - if (copybuf[0] == '\\' && - copybuf[1] == '.' && - copybuf[2] == '\0') + if (copybuf) { - copydone = true; /* don't print this... */ - } - else - { - archputs(copybuf, fout); - switch (ret) - { - case EOF: - copydone = true; - /* FALLTHROUGH */ - case 0: - archputs("\n", fout); - break; - case 1: - break; - } + WriteData(fout, copybuf, ret); + PQfreemem(copybuf); } /* @@ -920,7 +903,7 @@ dumpTableData_copy(Archive *fout, void *dcontext) * * There was considerable discussion in late July, 2000 regarding * slowing down pg_dump when backing up large tables. Users with both - * slow & fast (muti-processor) machines experienced performance + * slow & fast (multi-processor) machines experienced performance * degradation when doing a backup. * * Initial attempts based on sleeping for a number of ms for each ms @@ -957,16 +940,20 @@ dumpTableData_copy(Archive *fout, void *dcontext) } archprintf(fout, "\\.\n\n\n"); - ret = PQendcopy(g_conn); - if (ret != 0) + if (ret == -2) { - write_msg(NULL, "SQL command to dump the contents of table \"%s\" failed: PQendcopy() failed.\n", classname); + /* copy data transfer failed */ + write_msg(NULL, "Dumping the contents of table \"%s\" failed: PQgetCopyData() failed.\n", classname); write_msg(NULL, "Error message from server: %s", PQerrorMessage(g_conn)); write_msg(NULL, "The command was: %s\n", q->data); exit_nicely(); } + /* Check command status and return to normal libpq state */ + res = PQgetResult(g_conn); + check_sql_result(res, g_conn, q->data, PGRES_COMMAND_OK); PQclear(res); + destroyPQExpBuffer(q); return 1; } |
