~ubuntu-branches/ubuntu/trusty/postgresql-9.3/trusty-updates

« back to all changes in this revision

Viewing changes to contrib/pg_upgrade/dump.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2016-05-12 16:06:03 UTC
  • mfrom: (1.1.16) (19.1.4 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20160512160603-8h0t7au3bkfjuiv4
Tags: 9.3.13-0ubuntu0.14.04
* New upstream bug fix release. (LP: #1581016)
  - See http://www.postgresql.org/docs/9.3/static/release-9-3-13.html for
    details.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#include "pg_upgrade.h"
13
13
 
14
14
#include <sys/types.h>
15
 
#include "catalog/pg_authid.h"
16
 
 
17
 
/* pick a OID that will never be used for TOAST tables */
18
 
#define OPTIONALLY_CREATE_TOAST_OID   BOOTSTRAP_SUPERUSERID
19
15
 
20
16
 
21
17
void
72
68
        end_progress_output();
73
69
        check_ok();
74
70
}
75
 
 
76
 
 
77
 
/*
78
 
 * It is possible for there to be a mismatch in the need for TOAST tables
79
 
 * between the old and new servers, e.g. some pre-9.1 tables didn't need
80
 
 * TOAST tables but will need them in 9.1+.  (There are also opposite cases,
81
 
 * but these are handled by setting binary_upgrade_next_toast_pg_class_oid.)
82
 
 *
83
 
 * We can't allow the TOAST table to be created by pg_dump with a
84
 
 * pg_dump-assigned oid because it might conflict with a later table that
85
 
 * uses that oid, causing a "file exists" error for pg_class conflicts, and
86
 
 * a "duplicate oid" error for pg_type conflicts.  (TOAST tables need pg_type
87
 
 * entries.)
88
 
 *
89
 
 * Therefore, a backend in binary-upgrade mode will not create a TOAST
90
 
 * table unless an OID as passed in via pg_upgrade_support functions.
91
 
 * This function is called after the restore and uses ALTER TABLE to
92
 
 * auto-create any needed TOAST tables which will not conflict with
93
 
 * restored oids.
94
 
 */
95
 
void
96
 
optionally_create_toast_tables(void)
97
 
{
98
 
        int                     dbnum;
99
 
 
100
 
        prep_status("Creating newly-required TOAST tables");
101
 
 
102
 
        for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
103
 
        {
104
 
                PGresult   *res;
105
 
                int                     ntups;
106
 
                int                     rowno;
107
 
                int                     i_nspname,
108
 
                                        i_relname;
109
 
                DbInfo     *active_db = &new_cluster.dbarr.dbs[dbnum];
110
 
                PGconn     *conn = connectToServer(&new_cluster, active_db->db_name);
111
 
 
112
 
                res = executeQueryOrDie(conn,
113
 
                                                                "SELECT n.nspname, c.relname "
114
 
                                                                "FROM   pg_catalog.pg_class c, "
115
 
                                                                "               pg_catalog.pg_namespace n "
116
 
                                                                "WHERE  c.relnamespace = n.oid AND "
117
 
                                                          "             n.nspname NOT IN ('pg_catalog', 'information_schema') AND "
118
 
                                                                "c.relkind IN ('r', 'm') AND "
119
 
                                                                "c.reltoastrelid = 0");
120
 
 
121
 
                ntups = PQntuples(res);
122
 
                i_nspname = PQfnumber(res, "nspname");
123
 
                i_relname = PQfnumber(res, "relname");
124
 
                for (rowno = 0; rowno < ntups; rowno++)
125
 
                {
126
 
                        /* enable auto-oid-numbered TOAST creation if needed */
127
 
                        PQclear(executeQueryOrDie(conn, "SELECT binary_upgrade.set_next_toast_pg_class_oid('%d'::pg_catalog.oid);",
128
 
                                        OPTIONALLY_CREATE_TOAST_OID));
129
 
 
130
 
                        /* dummy command that also triggers check for required TOAST table */
131
 
                        PQclear(executeQueryOrDie(conn, "ALTER TABLE %s.%s RESET (binary_upgrade_dummy_option);",
132
 
                                        quote_identifier(PQgetvalue(res, rowno, i_nspname)),
133
 
                                        quote_identifier(PQgetvalue(res, rowno, i_relname))));
134
 
                }
135
 
 
136
 
                PQclear(res);
137
 
 
138
 
                PQfinish(conn);
139
 
        }
140
 
 
141
 
        check_ok();
142
 
}