~ubuntu-branches/ubuntu/karmic/postgresql-8.4/karmic-proposed

« back to all changes in this revision

Viewing changes to src/bin/pg_dump/pg_dump.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2010-12-21 21:17:08 UTC
  • mfrom: (1.3.1 upstream) (8.1.3 karmic-security)
  • Revision ID: james.westby@ubuntu.com-20101221211708-5gcqa90kf99fkcfz
Tags: 8.4.6-0ubuntu9.10
* New upstream bug fix release: (LP: #693157)
  - Force the default wal_sync_method to be fdatasync on Linux.
    The default on Linux has actually been fdatasync for many years,
    but recent kernel changes caused PostgreSQL to choose open_datasync
    instead. This choice did not result in any performance improvement,
    and caused outright failures on certain filesystems, notably ext4
    with the data=journal mount option.
  - Fix assorted bugs in WAL replay logic for GIN indexes.
    This could result in "bad buffer id: 0" failures or corruption of
    index contents during replication.
  - Fix recovery from base backup when the starting checkpoint WAL
    record is not in the same WAL segment as its redo point.
  - Fix persistent slowdown of autovacuum workers when multiple workers
    remain active for a long time.
    The effective vacuum_cost_limit for an autovacuum worker could drop
    to nearly zero if it processed enough tables, causing it to run
    extremely slowly.
  - Add support for detecting register-stack overrun on IA64.
    The IA64 architecture has two hardware stacks. Full prevention of
    stack-overrun failures requires checking both.
  - Add a check for stack overflow in copyObject().
    Certain code paths could crash due to stack overflow given a
    sufficiently complex query.
  - Fix detection of page splits in temporary GiST indexes.
    It is possible to have a "concurrent" page split in a temporary
    index, if for example there is an open cursor scanning the index
    when an insertion is done. GiST failed to detect this case and
    hence could deliver wrong results when execution of the cursor
    continued.
  - Fix error checking during early connection processing.
    The check for too many child processes was skipped in some cases,
    possibly leading to postmaster crash when attempting to add the new
    child process to fixed-size arrays.
  - Improve efficiency of window functions.
    Certain cases where a large number of tuples needed to be read in
    advance, but work_mem was large enough to allow them all to be held
    in memory, were unexpectedly slow. percent_rank(), cume_dist() and
    ntile() in particular were subject to this problem.
  - Avoid memory leakage while "ANALYZE"'ing complex index expressions.
  - Ensure an index that uses a whole-row Var still depends on its
    table.
    An index declared like create index i on t (foo(t.-)) would not
    automatically get dropped when its table was dropped.
  - Do not "inline" a SQL function with multiple OUT parameters.
    This avoids a possible crash due to loss of information about the
    expected result rowtype.
  - Behave correctly if ORDER BY, LIMIT, FOR UPDATE, or WITH is
    attached to the VALUES part of INSERT ... VALUES.
  - Fix constant-folding of COALESCE() expressions.
    The planner would sometimes attempt to evaluate sub-expressions
    that in fact could never be reached, possibly leading to unexpected
    errors.
  - Fix postmaster crash when connection acceptance (accept() or one of
    the calls made immediately after it) fails, and the postmaster was
    compiled with GSSAPI support.
  - Fix missed unlink of temporary files when log_temp_files is active.
    If an error occurred while attempting to emit the log message, the
    unlink was not done, resulting in accumulation of temp files.
  - Add print functionality for InhRelation nodes.
    This avoids a failure when debug_print_parse is enabled and certain
    types of query are executed.
  - Fix incorrect calculation of distance from a point to a horizontal
    line segment.
    This bug affected several different geometric distance-measurement
    operators.
  - Fix incorrect calculation of transaction status in ecpg.
  - Fix PL/pgSQL's handling of "simple" expressions to not fail in
    recursion or error-recovery cases.
  - Fix PL/Python's handling of set-returning functions.
    Attempts to call SPI functions within the iterator generating a set
    result would fail.
  - Fix bug in "contrib/cube"'s GiST picksplit algorithm.
    This could result in considerable inefficiency, though not actually
    incorrect answers, in a GiST index on a cube column. If you have
    such an index, consider "REINDEX"ing it after installing this
    update.
  - Don't emit "identifier will be truncated" notices in
    "contrib/dblink" except when creating new connections.
  - Fix potential coredump on missing public key in "contrib/pgcrypto".
  - Fix memory leak in "contrib/xml2"'s XPath query functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 *      by PostgreSQL
13
13
 *
14
14
 * IDENTIFICATION
15
 
 *        $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.539.2.4 2010/03/03 20:10:42 heikki Exp $
 
15
 *        $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.539.2.5 2010/07/14 21:21:23 tgl Exp $
16
16
 *
17
17
 *-------------------------------------------------------------------------
18
18
 */
158
158
static void dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo);
159
159
static void dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo);
160
160
static void dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo);
161
 
static void dumpUserMappings(Archive *fout, const char *target,
 
161
static void dumpUserMappings(Archive *fout,
162
162
                                 const char *servername, const char *namespace,
163
163
                                 const char *owner, CatalogId catalogId, DumpId dumpId);
164
164
 
5433
5433
        int                     i;
5434
5434
        PQExpBuffer query = createPQExpBuffer();
5435
5435
        FdwInfo    *fdwinfo;
 
5436
        int                     i_tableoid;
5436
5437
        int                     i_oid;
5437
5438
        int                     i_fdwname;
5438
5439
        int                     i_rolname;
5450
5451
        /* Make sure we are in proper schema */
5451
5452
        selectSourceSchema("pg_catalog");
5452
5453
 
5453
 
        appendPQExpBuffer(query, "SELECT oid, fdwname, "
 
5454
        appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
5454
5455
                "(%s fdwowner) AS rolname, fdwvalidator::pg_catalog.regproc, fdwacl,"
5455
5456
                                          "array_to_string(ARRAY("
5456
5457
                 "              SELECT option_name || ' ' || quote_literal(option_value) "
5466
5467
 
5467
5468
        fdwinfo = (FdwInfo *) malloc(ntups * sizeof(FdwInfo));
5468
5469
 
 
5470
        i_tableoid = PQfnumber(res, "tableoid");
5469
5471
        i_oid = PQfnumber(res, "oid");
5470
5472
        i_fdwname = PQfnumber(res, "fdwname");
5471
5473
        i_rolname = PQfnumber(res, "rolname");
5476
5478
        for (i = 0; i < ntups; i++)
5477
5479
        {
5478
5480
                fdwinfo[i].dobj.objType = DO_FDW;
 
5481
                fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5479
5482
                fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5480
5483
                AssignDumpId(&fdwinfo[i].dobj);
5481
5484
                fdwinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_fdwname));
5512
5515
        int                     i;
5513
5516
        PQExpBuffer query = createPQExpBuffer();
5514
5517
        ForeignServerInfo *srvinfo;
 
5518
        int                     i_tableoid;
5515
5519
        int                     i_oid;
5516
5520
        int                     i_srvname;
5517
5521
        int                     i_rolname;
5531
5535
        /* Make sure we are in proper schema */
5532
5536
        selectSourceSchema("pg_catalog");
5533
5537
 
5534
 
        appendPQExpBuffer(query, "SELECT oid, srvname, "
 
5538
        appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, "
5535
5539
                                          "(%s srvowner) AS rolname, "
5536
5540
                                          "srvfdw, srvtype, srvversion, srvacl,"
5537
5541
                                          "array_to_string(ARRAY("
5548
5552
 
5549
5553
        srvinfo = (ForeignServerInfo *) malloc(ntups * sizeof(ForeignServerInfo));
5550
5554
 
 
5555
        i_tableoid = PQfnumber(res, "tableoid");
5551
5556
        i_oid = PQfnumber(res, "oid");
5552
5557
        i_srvname = PQfnumber(res, "srvname");
5553
5558
        i_rolname = PQfnumber(res, "rolname");
5560
5565
        for (i = 0; i < ntups; i++)
5561
5566
        {
5562
5567
                srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
 
5568
                srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
5563
5569
                srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5564
5570
                AssignDumpId(&srvinfo[i].dobj);
5565
5571
                srvinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_srvname));
9441
9447
        query = createPQExpBuffer();
9442
9448
 
9443
9449
        /* look up the foreign-data wrapper */
 
9450
        selectSourceSchema("pg_catalog");
9444
9451
        appendPQExpBuffer(query, "SELECT fdwname "
9445
9452
                                          "FROM pg_foreign_data_wrapper w "
9446
9453
                                          "WHERE w.oid = '%u'",
9501
9508
        free(namecopy);
9502
9509
 
9503
9510
        /* Dump user mappings */
9504
 
        resetPQExpBuffer(q);
9505
 
        appendPQExpBuffer(q, "SERVER %s", fmtId(srvinfo->dobj.name));
9506
 
        dumpUserMappings(fout, q->data,
 
9511
        dumpUserMappings(fout,
9507
9512
                                         srvinfo->dobj.name, NULL,
9508
9513
                                         srvinfo->rolname,
9509
9514
                                         srvinfo->dobj.catId, srvinfo->dobj.dumpId);
9520
9525
 * for the server.
9521
9526
 */
9522
9527
static void
9523
 
dumpUserMappings(Archive *fout, const char *target,
 
9528
dumpUserMappings(Archive *fout,
9524
9529
                                 const char *servername, const char *namespace,
9525
9530
                                 const char *owner,
9526
9531
                                 CatalogId catalogId, DumpId dumpId)
9531
9536
        PQExpBuffer tag;
9532
9537
        PGresult   *res;
9533
9538
        int                     ntups;
9534
 
        int                     i_umuser;
 
9539
        int                     i_usename;
9535
9540
        int                     i_umoptions;
9536
9541
        int                     i;
9537
9542
 
9540
9545
        delq = createPQExpBuffer();
9541
9546
        query = createPQExpBuffer();
9542
9547
 
 
9548
        /*
 
9549
         * We read from the publicly accessible view pg_user_mappings, so as not
 
9550
         * to fail if run by a non-superuser.  Note that the view will show
 
9551
         * umoptions as null if the user hasn't got privileges for the associated
 
9552
         * server; this means that pg_dump will dump such a mapping, but with no
 
9553
         * OPTIONS clause.  A possible alternative is to skip such mappings
 
9554
         * altogether, but it's not clear that that's an improvement.
 
9555
         */
 
9556
        selectSourceSchema("pg_catalog");
 
9557
 
9543
9558
        appendPQExpBuffer(query,
9544
 
                                          "SELECT (%s umuser) AS umuser, "
 
9559
                                          "SELECT usename, "
9545
9560
                                          "array_to_string(ARRAY(SELECT option_name || ' ' || quote_literal(option_value) FROM pg_options_to_table(umoptions)), ', ') AS umoptions\n"
9546
 
                                          "FROM pg_user_mapping "
9547
 
                                          "WHERE umserver=%u",
9548
 
                                          username_subquery,
 
9561
                                          "FROM pg_user_mappings "
 
9562
                                          "WHERE srvid = %u",
9549
9563
                                          catalogId.oid);
9550
9564
 
9551
9565
        res = PQexec(g_conn, query->data);
9552
9566
        check_sql_result(res, g_conn, query->data, PGRES_TUPLES_OK);
9553
9567
 
9554
9568
        ntups = PQntuples(res);
9555
 
        i_umuser = PQfnumber(res, "umuser");
 
9569
        i_usename = PQfnumber(res, "usename");
9556
9570
        i_umoptions = PQfnumber(res, "umoptions");
9557
9571
 
9558
9572
        for (i = 0; i < ntups; i++)
9559
9573
        {
9560
 
                char       *umuser;
 
9574
                char       *usename;
9561
9575
                char       *umoptions;
9562
9576
 
9563
 
                umuser = PQgetvalue(res, i, i_umuser);
 
9577
                usename = PQgetvalue(res, i, i_usename);
9564
9578
                umoptions = PQgetvalue(res, i, i_umoptions);
9565
9579
 
9566
9580
                resetPQExpBuffer(q);
9567
 
                appendPQExpBuffer(q, "CREATE USER MAPPING FOR %s", fmtId(umuser));
 
9581
                appendPQExpBuffer(q, "CREATE USER MAPPING FOR %s", fmtId(usename));
9568
9582
                appendPQExpBuffer(q, " SERVER %s", fmtId(servername));
9569
9583
 
9570
9584
                if (umoptions && strlen(umoptions) > 0)
9573
9587
                appendPQExpBuffer(q, ";\n");
9574
9588
 
9575
9589
                resetPQExpBuffer(delq);
9576
 
                appendPQExpBuffer(delq, "DROP USER MAPPING FOR %s SERVER %s;\n", fmtId(umuser), fmtId(servername));
 
9590
                appendPQExpBuffer(delq, "DROP USER MAPPING FOR %s", fmtId(usename));
 
9591
                appendPQExpBuffer(delq, " SERVER %s;\n", fmtId(servername));
9577
9592
 
9578
9593
                resetPQExpBuffer(tag);
9579
 
                appendPQExpBuffer(tag, "USER MAPPING %s %s", fmtId(umuser), target);
 
9594
                appendPQExpBuffer(tag, "USER MAPPING %s SERVER %s",
 
9595
                                                  usename, servername);
9580
9596
 
9581
9597
                ArchiveEntry(fout, nilCatalogId, createDumpId(),
9582
9598
                                         tag->data,