1257
1257
* Mark a type as to be dumped or not
1259
1259
* If it's a table's rowtype or an autogenerated array type, we also apply a
1260
* special type code to facilitate sorting into the desired order. (We don't
1260
* special type code to facilitate sorting into the desired order. (We don't
1261
1261
* want to consider those to be ordinary types because that would bring tables
1262
1262
* up into the datatype part of the dump order.) We still set the object's
1263
1263
* dump flag; that's not going to cause the dummy type to be dumped, but we
1540
1540
* Caution: when we restore from an archive file direct to database, the
1541
1541
* INSERT commands emitted by this function have to be parsed by
1542
* pg_backup_db.c's ExecuteInsertCommands(), which will not handle comments,
1542
* pg_backup_db.c's ExecuteSimpleCommands(), which will not handle comments,
1543
1543
* E'' strings, or dollar-quoted strings. So don't emit anything like that.
1636
1636
* These types are printed without quotes unless
1637
1637
* they contain values that aren't accepted by the
1638
* scanner unquoted (e.g., 'NaN'). Note that
1638
* scanner unquoted (e.g., 'NaN'). Note that
1639
1639
* strtod() and friends might accept NaN, so we
1640
1640
* can't use that to test.
2029
2029
* guessConstraintInheritance:
2030
2030
* In pre-8.4 databases, we can't tell for certain which constraints
2031
* are inherited. We assume a CHECK constraint is inherited if its name
2031
* are inherited. We assume a CHECK constraint is inherited if its name
2032
2032
* matches the name of any constraint in the parent. Originally this code
2033
2033
* tried to compare the expression texts, but that can fail for various
2034
2034
* reasons --- for example, if the parent and child tables are in different
2139
2140
selectSourceSchema(fout, "pg_catalog");
2141
2142
/* Get the database owner and parameters from pg_database */
2142
if (fout->remoteVersion >= 80400)
2144
appendPQExpBuffer(dbQry, "SELECT tableoid, oid, "
2145
"(%s datdba) AS dba, "
2146
"pg_encoding_to_char(encoding) AS encoding, "
2147
"datcollate, datctype, datfrozenxid, "
2143
if (fout->remoteVersion >= 90300)
2145
appendPQExpBuffer(dbQry, "SELECT tableoid, oid, "
2146
"(%s datdba) AS dba, "
2147
"pg_encoding_to_char(encoding) AS encoding, "
2148
"datcollate, datctype, datfrozenxid, datminmxid, "
2149
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
2150
"shobj_description(oid, 'pg_database') AS description "
2155
appendStringLiteralAH(dbQry, datname, fout);
2157
else if (fout->remoteVersion >= 80400)
2159
appendPQExpBuffer(dbQry, "SELECT tableoid, oid, "
2160
"(%s datdba) AS dba, "
2161
"pg_encoding_to_char(encoding) AS encoding, "
2162
"datcollate, datctype, datfrozenxid, 0 AS datminmxid, "
2148
2163
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
2149
2164
"shobj_description(oid, 'pg_database') AS description "
2158
2173
appendPQExpBuffer(dbQry, "SELECT tableoid, oid, "
2159
2174
"(%s datdba) AS dba, "
2160
2175
"pg_encoding_to_char(encoding) AS encoding, "
2161
"NULL AS datcollate, NULL AS datctype, datfrozenxid, "
2176
"NULL AS datcollate, NULL AS datctype, datfrozenxid, 0 AS datminmxid, "
2162
2177
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
2163
2178
"shobj_description(oid, 'pg_database') AS description "
2172
2187
appendPQExpBuffer(dbQry, "SELECT tableoid, oid, "
2173
2188
"(%s datdba) AS dba, "
2174
2189
"pg_encoding_to_char(encoding) AS encoding, "
2175
"NULL AS datcollate, NULL AS datctype, datfrozenxid, "
2190
"NULL AS datcollate, NULL AS datctype, datfrozenxid, 0 AS datminmxid, "
2176
2191
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace "
2177
2192
"FROM pg_database "
2178
2193
"WHERE datname = ",
2185
2200
"(%s datdba) AS dba, "
2186
2201
"pg_encoding_to_char(encoding) AS encoding, "
2187
2202
"NULL AS datcollate, NULL AS datctype, "
2188
"0 AS datfrozenxid, "
2203
"0 AS datfrozenxid, 0 AS datminmxid, "
2189
2204
"NULL AS tablespace "
2190
2205
"FROM pg_database "
2191
2206
"WHERE datname = ",
2200
2215
"(%s datdba) AS dba, "
2201
2216
"pg_encoding_to_char(encoding) AS encoding, "
2202
2217
"NULL AS datcollate, NULL AS datctype, "
2203
"0 AS datfrozenxid, "
2218
"0 AS datfrozenxid, 0 AS datminmxid, "
2204
2219
"NULL AS tablespace "
2205
2220
"FROM pg_database "
2206
2221
"WHERE datname = ",
2217
2232
i_collate = PQfnumber(res, "datcollate");
2218
2233
i_ctype = PQfnumber(res, "datctype");
2219
2234
i_frozenxid = PQfnumber(res, "datfrozenxid");
2235
i_minmxid = PQfnumber(res, "datminmxid");
2220
2236
i_tablespace = PQfnumber(res, "tablespace");
2222
2238
dbCatId.tableoid = atooid(PQgetvalue(res, 0, i_tableoid));
2226
2242
collate = PQgetvalue(res, 0, i_collate);
2227
2243
ctype = PQgetvalue(res, 0, i_ctype);
2228
2244
frozenxid = atooid(PQgetvalue(res, 0, i_frozenxid));
2245
minmxid = atooid(PQgetvalue(res, 0, i_minmxid));
2229
2246
tablespace = PQgetvalue(res, 0, i_tablespace);
2231
2248
appendPQExpBuffer(creaQry, "CREATE DATABASE %s WITH TEMPLATE = template0",
2253
2270
if (binary_upgrade)
2255
appendPQExpBuffer(creaQry, "\n-- For binary upgrade, set datfrozenxid.\n");
2272
appendPQExpBuffer(creaQry, "\n-- For binary upgrade, set datfrozenxid and datminmxid.\n");
2256
2273
appendPQExpBuffer(creaQry, "UPDATE pg_catalog.pg_database\n"
2257
"SET datfrozenxid = '%u'\n"
2274
"SET datfrozenxid = '%u', datminmxid = '%u'\n"
2258
2275
"WHERE datname = ",
2276
frozenxid, minmxid);
2260
2277
appendStringLiteralAH(creaQry, datname, fout);
2261
2278
appendPQExpBuffer(creaQry, ";\n");
2289
2306
* pg_largeobject and pg_largeobject_metadata come from the old system
2290
* intact, so set their relfrozenxids.
2307
* intact, so set their relfrozenxids and relminmxids.
2292
2309
if (binary_upgrade)
2294
2311
PGresult *lo_res;
2295
2312
PQExpBuffer loFrozenQry = createPQExpBuffer();
2296
2313
PQExpBuffer loOutQry = createPQExpBuffer();
2314
int i_relfrozenxid, i_relminmxid;
2300
2317
* pg_largeobject
2302
appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid\n"
2303
"FROM pg_catalog.pg_class\n"
2304
"WHERE oid = %u;\n",
2305
LargeObjectRelationId);
2319
if (fout->remoteVersion >= 90300)
2320
appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid\n"
2321
"FROM pg_catalog.pg_class\n"
2322
"WHERE oid = %u;\n",
2323
LargeObjectRelationId);
2325
appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, 0 AS relminmxid\n"
2326
"FROM pg_catalog.pg_class\n"
2327
"WHERE oid = %u;\n",
2328
LargeObjectRelationId);
2307
2330
lo_res = ExecuteSqlQueryForSingleRow(fout, loFrozenQry->data);
2309
2332
i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid");
2333
i_relminmxid = PQfnumber(lo_res, "relminmxid");
2311
appendPQExpBuffer(loOutQry, "\n-- For binary upgrade, set pg_largeobject.relfrozenxid\n");
2335
appendPQExpBuffer(loOutQry, "\n-- For binary upgrade, set pg_largeobject relfrozenxid and relminmxid\n");
2312
2336
appendPQExpBuffer(loOutQry, "UPDATE pg_catalog.pg_class\n"
2313
"SET relfrozenxid = '%u'\n"
2337
"SET relfrozenxid = '%u', relminmxid = '%u'\n"
2314
2338
"WHERE oid = %u;\n",
2315
2339
atoi(PQgetvalue(lo_res, 0, i_relfrozenxid)),
2340
atoi(PQgetvalue(lo_res, 0, i_relminmxid)),
2316
2341
LargeObjectRelationId);
2317
2342
ArchiveEntry(fout, nilCatalogId, createDumpId(),
2318
2343
"pg_largeobject", NULL, NULL, "",
2331
2356
resetPQExpBuffer(loFrozenQry);
2332
2357
resetPQExpBuffer(loOutQry);
2334
appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid\n"
2359
if (fout->remoteVersion >= 90300)
2360
appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid\n"
2361
"FROM pg_catalog.pg_class\n"
2362
"WHERE oid = %u;\n",
2363
LargeObjectMetadataRelationId);
2365
appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, 0 AS relminmxid\n"
2335
2366
"FROM pg_catalog.pg_class\n"
2336
2367
"WHERE oid = %u;\n",
2337
2368
LargeObjectMetadataRelationId);
2339
2370
lo_res = ExecuteSqlQueryForSingleRow(fout, loFrozenQry->data);
2341
2372
i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid");
2373
i_relminmxid = PQfnumber(lo_res, "relminmxid");
2343
appendPQExpBuffer(loOutQry, "\n-- For binary upgrade, set pg_largeobject_metadata.relfrozenxid\n");
2375
appendPQExpBuffer(loOutQry, "\n-- For binary upgrade, set pg_largeobject_metadata relfrozenxid and relminmxid\n");
2344
2376
appendPQExpBuffer(loOutQry, "UPDATE pg_catalog.pg_class\n"
2345
"SET relfrozenxid = '%u'\n"
2377
"SET relfrozenxid = '%u', relminmxid = '%u'\n"
2346
2378
"WHERE oid = %u;\n",
2347
2379
atoi(PQgetvalue(lo_res, 0, i_relfrozenxid)),
2380
atoi(PQgetvalue(lo_res, 0, i_relminmxid)),
2348
2381
LargeObjectMetadataRelationId);
2349
2382
ArchiveEntry(fout, nilCatalogId, createDumpId(),
2350
2383
"pg_largeobject_metadata", NULL, NULL, "",
2983
3016
* getNamespaces
2985
3018
* NB: for pre-7.3 source database, we use object OID to guess whether it's
2986
* a system object or not. In 7.3 and later there is no guessing, and we
3019
* a system object or not. In 7.3 and later there is no guessing, and we
2987
3020
* don't use objoid at all.
2989
3022
static NamespaceInfo *
3142
3175
* auto-generated array type by checking the element type's typarray.
3143
3176
* (Before that the test is capable of generating false positives.) We
3144
3177
* still check for name beginning with '_', though, so as to avoid the
3145
* cost of the subselect probe for all standard types. This would have to
3178
* cost of the subselect probe for all standard types. This would have to
3146
3179
* be revisited if the backend ever allows renaming of array types.
3289
3322
* If it's a base type, make a DumpableObject representing a shell
3290
* definition of the type. We will need to dump that ahead of the I/O
3291
* functions for the type. Similarly, range types need a shell
3323
* definition of the type. We will need to dump that ahead of the I/O
3324
* functions for the type. Similarly, range types need a shell
3292
3325
* definition in case they have a canonicalize function.
3294
3327
* Note: the shell type doesn't have a catId. You might think it
4039
4072
* Find all user-defined functions. Normally we can exclude functions in
4040
4073
* pg_catalog, which is worth doing since there are several thousand of
4041
4074
* 'em. However, there are some extensions that create functions in
4042
* pg_catalog. In normal dumps we can still ignore those --- but in
4075
* pg_catalog. In normal dumps we can still ignore those --- but in
4043
4076
* binary-upgrade mode, we must dump the member objects of the extension,
4044
4077
* so be sure to fetch any such functions.
4263
4298
"(%s c.relowner) AS rolname, "
4264
4299
"c.relchecks, c.relhastriggers, "
4265
4300
"c.relhasindex, c.relhasrules, c.relhasoids, "
4266
"c.relfrozenxid, tc.oid AS toid, "
4301
"c.relfrozenxid, c.relminmxid, tc.oid AS toid, "
4267
4302
"tc.relfrozenxid AS tfrozenxid, "
4303
"tc.relminmxid AS tminmxid, "
4268
4304
"c.relpersistence, c.relispopulated, "
4270
4306
"CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, "
4300
4336
"(%s c.relowner) AS rolname, "
4301
4337
"c.relchecks, c.relhastriggers, "
4302
4338
"c.relhasindex, c.relhasrules, c.relhasoids, "
4303
"c.relfrozenxid, tc.oid AS toid, "
4339
"c.relfrozenxid, 0 AS relminmxid, tc.oid AS toid, "
4304
4340
"tc.relfrozenxid AS tfrozenxid, "
4305
4342
"c.relpersistence, 't' as relispopulated, "
4307
4344
"CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, "
4337
4374
"(%s c.relowner) AS rolname, "
4338
4375
"c.relchecks, c.relhastriggers, "
4339
4376
"c.relhasindex, c.relhasrules, c.relhasoids, "
4340
"c.relfrozenxid, tc.oid AS toid, "
4377
"c.relfrozenxid, 0 AS relminmxid, tc.oid AS toid, "
4341
4378
"tc.relfrozenxid AS tfrozenxid, "
4342
4380
"'p' AS relpersistence, 't' as relispopulated, "
4344
4382
"CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, "
4373
4411
"(%s c.relowner) AS rolname, "
4374
4412
"c.relchecks, c.relhastriggers, "
4375
4413
"c.relhasindex, c.relhasrules, c.relhasoids, "
4376
"c.relfrozenxid, tc.oid AS toid, "
4414
"c.relfrozenxid, 0 AS relminmxid, tc.oid AS toid, "
4377
4415
"tc.relfrozenxid AS tfrozenxid, "
4378
4417
"'p' AS relpersistence, 't' as relispopulated, "
4380
4419
"NULL AS reloftype, "
4409
4448
"(%s c.relowner) AS rolname, "
4410
4449
"c.relchecks, (c.reltriggers <> 0) AS relhastriggers, "
4411
4450
"c.relhasindex, c.relhasrules, c.relhasoids, "
4412
"c.relfrozenxid, tc.oid AS toid, "
4451
"c.relfrozenxid, 0 AS relminmxid, tc.oid AS toid, "
4413
4452
"tc.relfrozenxid AS tfrozenxid, "
4414
4454
"'p' AS relpersistence, 't' as relispopulated, "
4416
4456
"NULL AS reloftype, "
4445
4485
"(%s relowner) AS rolname, "
4446
4486
"relchecks, (reltriggers <> 0) AS relhastriggers, "
4447
4487
"relhasindex, relhasrules, relhasoids, "
4448
"0 AS relfrozenxid, "
4488
"0 AS relfrozenxid, 0 AS relminmxid,"
4490
"0 AS tfrozenxid, 0 AS tminmxid,"
4451
4491
"'p' AS relpersistence, 't' as relispopulated, "
4453
4493
"NULL AS reloftype, "
4481
4521
"(%s relowner) AS rolname, "
4482
4522
"relchecks, (reltriggers <> 0) AS relhastriggers, "
4483
4523
"relhasindex, relhasrules, relhasoids, "
4484
"0 AS relfrozenxid, "
4524
"0 AS relfrozenxid, 0 AS relminmxid,"
4526
"0 AS tfrozenxid, 0 AS tminmxid,"
4487
4527
"'p' AS relpersistence, 't' as relispopulated, "
4489
4529
"NULL AS reloftype, "
4513
4553
"(%s relowner) AS rolname, "
4514
4554
"relchecks, (reltriggers <> 0) AS relhastriggers, "
4515
4555
"relhasindex, relhasrules, relhasoids, "
4516
"0 AS relfrozenxid, "
4556
"0 AS relfrozenxid, 0 AS relminmxid,"
4558
"0 AS tfrozenxid, 0 AS tminmxid,"
4519
4559
"'p' AS relpersistence, 't' as relispopulated, "
4521
4561
"NULL AS reloftype, "
4540
4580
"relchecks, (reltriggers <> 0) AS relhastriggers, "
4541
4581
"relhasindex, relhasrules, "
4542
4582
"'t'::bool AS relhasoids, "
4543
"0 AS relfrozenxid, "
4583
"0 AS relfrozenxid, 0 AS relminmxid,"
4585
"0 AS tfrozenxid, 0 AS tminmxid,"
4546
4586
"'p' AS relpersistence, 't' as relispopulated, "
4548
4588
"NULL AS reloftype, "
4577
4617
"relchecks, (reltriggers <> 0) AS relhastriggers, "
4578
4618
"relhasindex, relhasrules, "
4579
4619
"'t'::bool AS relhasoids, "
4580
"0 as relfrozenxid, "
4620
"0 AS relfrozenxid, 0 AS relminmxid,"
4622
"0 AS tfrozenxid, 0 AS tminmxid,"
4583
4623
"'p' AS relpersistence, 't' as relispopulated, "
4584
4624
"0 AS relpages, "
4585
4625
"NULL AS reloftype, "
4626
4666
i_relhasrules = PQfnumber(res, "relhasrules");
4627
4667
i_relhasoids = PQfnumber(res, "relhasoids");
4628
4668
i_relfrozenxid = PQfnumber(res, "relfrozenxid");
4669
i_relminmxid = PQfnumber(res, "relminmxid");
4629
4670
i_toastoid = PQfnumber(res, "toid");
4630
4671
i_toastfrozenxid = PQfnumber(res, "tfrozenxid");
4672
i_toastminmxid = PQfnumber(res, "tminmxid");
4631
4673
i_relpersistence = PQfnumber(res, "relpersistence");
4632
4674
i_relispopulated = PQfnumber(res, "relispopulated");
4633
4675
i_relpages = PQfnumber(res, "relpages");
4675
4717
tblinfo[i].relispopulated = (strcmp(PQgetvalue(res, i, i_relispopulated), "t") == 0);
4676
4718
tblinfo[i].relpages = atoi(PQgetvalue(res, i, i_relpages));
4677
4719
tblinfo[i].frozenxid = atooid(PQgetvalue(res, i, i_relfrozenxid));
4720
tblinfo[i].minmxid = atooid(PQgetvalue(res, i, i_relminmxid));
4678
4721
tblinfo[i].toast_oid = atooid(PQgetvalue(res, i, i_toastoid));
4679
4722
tblinfo[i].toast_frozenxid = atooid(PQgetvalue(res, i, i_toastfrozenxid));
4723
tblinfo[i].toast_minmxid = atooid(PQgetvalue(res, i, i_toastminmxid));
4680
4724
if (PQgetisnull(res, i, i_reloftype))
4681
4725
tblinfo[i].reloftype = NULL;
4707
4751
selectDumpableTable(&tblinfo[i]);
4708
4752
tblinfo[i].interesting = tblinfo[i].dobj.dump;
4754
tblinfo[i].postponed_def = false; /* might get set during sort */
4711
4757
* Read-lock target tables to make sure they aren't DROPPED or altered
4712
4758
* in schema before we get around to dumping them.
5117
5163
* In pre-7.4 releases, indkeys may contain more entries than
5118
5164
* indnkeys says (since indnkeys will be 1 for a functional
5119
* index). We don't actually care about this case since we don't
5165
* index). We don't actually care about this case since we don't
5120
5166
* examine indkeys except for indexes associated with PRIMARY and
5121
5167
* UNIQUE constraints, which are never functional indexes. But we
5122
5168
* have to allocate enough space to keep parseOidArray from
5366
5412
* Make the domain depend on the constraint, ensuring it won't be
5367
* output till any constraint dependencies are OK. If the constraint
5413
* output till any constraint dependencies are OK. If the constraint
5368
5414
* has not been validated, it's going to be dumped after the domain
5369
5415
* anyway, so this doesn't matter.
6200
6246
else if (fout->remoteVersion >= 90100)
6203
* attcollation is new in 9.1. Since we only want to dump COLLATE
6249
* attcollation is new in 9.1. Since we only want to dump COLLATE
6204
6250
* clauses for attributes whose collation is different from their
6205
6251
* type's default, we use a CASE here to suppress uninteresting
6206
6252
* attcollations cheaply.
6457
6503
* Defaults on a VIEW must always be dumped as separate ALTER
6458
* TABLE commands. Defaults on regular tables are dumped as
6504
* TABLE commands. Defaults on regular tables are dumped as
6459
6505
* part of the CREATE TABLE if possible, which it won't be if
6460
6506
* the column is not going to be emitted explicitly.
6654
6700
* If the constraint is inherited, this will be detected later
6655
* (in pre-8.4 databases). We also detect later if the
6701
* (in pre-8.4 databases). We also detect later if the
6656
6702
* constraint must be split out from the table definition.
7493
7539
* Pre-7.2, pg_description does not contain classoid, so collectComments
7494
* just stores a zero. If there's a collision on object OID, well, you
7540
* just stores a zero. If there's a collision on object OID, well, you
7495
7541
* get duplicate comments.
7497
7543
if (fout->remoteVersion < 70200)
7870
7916
* We unconditionally create the extension, so we must drop it if it
7871
* exists. This could happen if the user deleted 'plpgsql' and then
7917
* exists. This could happen if the user deleted 'plpgsql' and then
7872
7918
* readded it, causing its oid to be greater than FirstNormalObjectId.
7873
7919
* The FirstNormalObjectId test was kept to avoid repeatedly dropping
7874
7920
* and recreating extensions like 'plpgsql'.
7889
7935
* Note that we're pushing extconfig (an OID array) back into
7890
* pg_extension exactly as-is. This is OK because pg_class OIDs are
7936
* pg_extension exactly as-is. This is OK because pg_class OIDs are
7891
7937
* preserved in binary upgrade.
7893
7939
if (strlen(extinfo->extconfig) > 2)
8818
8864
if (fout->remoteVersion >= 90100)
8821
* attcollation is new in 9.1. Since we only want to dump COLLATE
8867
* attcollation is new in 9.1. Since we only want to dump COLLATE
8822
8868
* clauses for attributes whose collation is different from their
8823
8869
* type's default, we use a CASE here to suppress uninteresting
8824
8870
* attcollations cheaply. atttypid will be 0 for dropped columns;
9136
9182
* Note the lack of a DROP command for the shell type; any required DROP
9137
* is driven off the base type entry, instead. This interacts with
9183
* is driven off the base type entry, instead. This interacts with
9138
9184
* _printTocEntry()'s use of the presence of a DROP command to decide
9139
9185
* whether an entry needs an ALTER OWNER command. We don't want to alter
9140
9186
* the shell type's owner immediately on creation; that should happen only
9172
9218
* For some backwards compatibility with the older behavior, we forcibly
9173
9219
* dump a PL if its handler function (and validator if any) are in a
9174
* dumpable namespace. That case is not checked here.
9220
* dumpable namespace. That case is not checked here.
9176
9222
* Also, if the PL belongs to an extension, we do not use this heuristic.
9177
9223
* That case isn't checked here either.
9859
9905
* COST and ROWS are emitted only if present and not default, so as not to
9860
* break backwards-compatibility of the dump without need. Keep this code
9906
* break backwards-compatibility of the dump without need. Keep this code
9861
9907
* in sync with the defaults in functioncmds.c.
9863
9909
if (strcmp(procost, "0") != 0)
10633
10679
* XXX RECHECK is gone as of 8.4, but we'll still print it if dumping an
10634
10680
* older server's opclass in which it is used. This is to avoid
10635
10681
* hard-to-detect breakage if a newer pg_dump is used to dump from an
10636
* older server and then reload into that old version. This can go away
10682
* older server and then reload into that old version. This can go away
10637
10683
* once 8.3 is so old as to not be of interest to anyone.
10639
10685
resetPQExpBuffer(query);
10911
10957
* XXX RECHECK is gone as of 8.4, but we'll still print it if dumping an
10912
10958
* older server's opclass in which it is used. This is to avoid
10913
10959
* hard-to-detect breakage if a newer pg_dump is used to dump from an
10914
* older server and then reload into that old version. This can go away
10960
* older server and then reload into that old version. This can go away
10915
10961
* once 8.3 is so old as to not be of interest to anyone.
10917
10963
if (fout->remoteVersion >= 90100)
12171
12217
* to fail if run by a non-superuser. Note that the view will show
12172
12218
* umoptions as null if the user hasn't got privileges for the associated
12173
12219
* server; this means that pg_dump will dump such a mapping, but with no
12174
* OPTIONS clause. A possible alternative is to skip such mappings
12220
* OPTIONS clause. A possible alternative is to skip such mappings
12175
12221
* altogether, but it's not clear that that's an improvement.
12177
12223
selectSourceSchema(fout, "pg_catalog");
12312
12358
* 'type' must be one of
12313
12359
* TABLE, SEQUENCE, FUNCTION, LANGUAGE, SCHEMA, DATABASE, TABLESPACE,
12314
12360
* FOREIGN DATA WRAPPER, SERVER, or LARGE OBJECT.
12315
* 'name' is the formatted name of the object. Must be quoted etc. already.
12361
* 'name' is the formatted name of the object. Must be quoted etc. already.
12316
12362
* 'subname' is the formatted name of the sub-object, if any. Must be quoted.
12317
12363
* 'tag' is the tag for the archive entry (typ. unquoted name of object).
12318
12364
* 'nspname' is the namespace the object is in (NULL if none).
12683
12729
tbinfo->relacl);
12686
* Handle column ACLs, if any. Note: we pull these with a separate
12732
* Handle column ACLs, if any. Note: we pull these with a separate
12687
12733
* query rather than trying to fetch them during getTableAttrs, so
12688
12734
* that we won't miss ACLs on system columns.
13120
13166
* physical column order, including dropped columns, as in the
13121
13167
* original. Therefore, we create dropped columns above and drop them
13122
13168
* here, also updating their attlen/attalign values so that the
13123
* dropped column can be skipped properly. (We do not bother with
13169
* dropped column can be skipped properly. (We do not bother with
13124
13170
* restoring the original attbyval setting.) Also, inheritance
13125
13171
* relationships are set up by doing ALTER INHERIT rather than using
13126
13172
* an INHERITS clause --- the latter would possibly mess up the column
13218
13264
tbinfo->reloftype);
13221
appendPQExpBuffer(q, "\n-- For binary upgrade, set heap's relfrozenxid\n");
13267
appendPQExpBuffer(q, "\n-- For binary upgrade, set heap's relfrozenxid and relminmxid\n");
13222
13268
appendPQExpBuffer(q, "UPDATE pg_catalog.pg_class\n"
13223
"SET relfrozenxid = '%u'\n"
13269
"SET relfrozenxid = '%u', relminmxid = '%u'\n"
13224
13270
"WHERE oid = ",
13225
tbinfo->frozenxid);
13271
tbinfo->frozenxid, tbinfo->minmxid);
13226
13272
appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout);
13227
13273
appendPQExpBuffer(q, "::pg_catalog.regclass;\n");
13229
13275
if (tbinfo->toast_oid)
13231
13277
/* We preserve the toast oids, so we can use it during restore */
13232
appendPQExpBuffer(q, "\n-- For binary upgrade, set toast's relfrozenxid\n");
13278
appendPQExpBuffer(q, "\n-- For binary upgrade, set toast's relfrozenxid and relminmxid\n");
13233
13279
appendPQExpBuffer(q, "UPDATE pg_catalog.pg_class\n"
13234
"SET relfrozenxid = '%u'\n"
13280
"SET relfrozenxid = '%u', relminmxid = '%u'\n"
13235
13281
"WHERE oid = '%u';\n",
13236
tbinfo->toast_frozenxid, tbinfo->toast_oid);
13282
tbinfo->toast_frozenxid,
13283
tbinfo->toast_minmxid, tbinfo->toast_oid);
13370
13417
(tbinfo->relkind == RELKIND_VIEW) ? NULL : tbinfo->reltablespace,
13371
13418
tbinfo->rolname,
13372
13419
(strcmp(reltypename, "TABLE") == 0) ? tbinfo->hasoids : false,
13373
reltypename, SECTION_PRE_DATA,
13421
tbinfo->postponed_def ? SECTION_POST_DATA : SECTION_PRE_DATA,
13374
13422
q->data, delq->data, NULL,
13511
13559
* If there's an associated constraint, don't dump the index per se, but
13512
* do dump any comment for it. (This is safe because dependency ordering
13560
* do dump any comment for it. (This is safe because dependency ordering
13513
13561
* will have ensured the constraint is emitted first.) Note that the
13514
13562
* emitted comment has to be shown as depending on the constraint, not
13515
13563
* the index, in such cases.
13849
13897
* find the last built in oid
13851
13899
* For 7.0, we do this by assuming that the last thing that initdb does is to
13852
* create the pg_indexes view. This sucks in general, but seeing that 7.0.x
13900
* create the pg_indexes view. This sucks in general, but seeing that 7.0.x
13853
13901
* initdb won't be changing anymore, it'll do.
14839
14887
* Ordinarily, table rowtypes have implicit dependencies on their
14840
* tables. However, for a composite type the implicit dependency goes
14888
* tables. However, for a composite type the implicit dependency goes
14841
14889
* the other way in pg_depend; which is the right thing for DROP but
14842
14890
* it doesn't produce the dependency ordering we need. So in that one
14843
14891
* case, we reverse the direction of the dependency.
14974
15022
* chains linking through objects that don't appear explicitly in the dump.
14975
15023
* For example, a view will depend on its _RETURN rule while the _RETURN rule
14976
15024
* will depend on other objects --- but the rule will not appear as a separate
14977
* object in the dump. We need to adjust the view's dependencies to include
15025
* object in the dump. We need to adjust the view's dependencies to include
14978
15026
* whatever the rule depends on that is included in the dump.
14980
15028
* Just to make things more complicated, there are also "special" dependencies