@@ -1767,6 +1767,13 @@ selectDumpableProcLang(ProcLangInfo *plang, Archive *fout)
1767
1767
static void
1768
1768
selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
1769
1769
{
1770
+ /* see getAccessMethods() comment about v9.6. */
1771
+ if (fout->remoteVersion < 90600)
1772
+ {
1773
+ method->dobj.dump = DUMP_COMPONENT_NONE;
1774
+ return;
1775
+ }
1776
+
1770
1777
if (checkExtensionMembership(&method->dobj, fout))
1771
1778
return; /* extension membership overrides all else */
1772
1779
@@ -5325,6 +5332,8 @@ getOperators(Archive *fout, int *numOprs)
5325
5332
int i_oprnamespace;
5326
5333
int i_rolname;
5327
5334
int i_oprkind;
5335
+ int i_oprleft;
5336
+ int i_oprright;
5328
5337
int i_oprcode;
5329
5338
5330
5339
/*
@@ -5336,6 +5345,8 @@ getOperators(Archive *fout, int *numOprs)
5336
5345
"oprnamespace, "
5337
5346
"(%s oprowner) AS rolname, "
5338
5347
"oprkind, "
5348
+ "oprleft, "
5349
+ "oprright, "
5339
5350
"oprcode::oid AS oprcode "
5340
5351
"FROM pg_operator",
5341
5352
username_subquery);
@@ -5353,6 +5364,8 @@ getOperators(Archive *fout, int *numOprs)
5353
5364
i_oprnamespace = PQfnumber(res, "oprnamespace");
5354
5365
i_rolname = PQfnumber(res, "rolname");
5355
5366
i_oprkind = PQfnumber(res, "oprkind");
5367
+ i_oprleft = PQfnumber(res, "oprleft");
5368
+ i_oprright = PQfnumber(res, "oprright");
5356
5369
i_oprcode = PQfnumber(res, "oprcode");
5357
5370
5358
5371
for (i = 0; i < ntups; i++)
@@ -5367,6 +5380,8 @@ getOperators(Archive *fout, int *numOprs)
5367
5380
atooid(PQgetvalue(res, i, i_oprnamespace)));
5368
5381
oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5369
5382
oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
5383
+ oprinfo[i].oprleft = atooid(PQgetvalue(res, i, i_oprleft));
5384
+ oprinfo[i].oprright = atooid(PQgetvalue(res, i, i_oprright));
5370
5385
oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
5371
5386
5372
5387
/* Decide whether we want to dump it */
@@ -5407,6 +5422,7 @@ getCollations(Archive *fout, int *numCollations)
5407
5422
int i_collname;
5408
5423
int i_collnamespace;
5409
5424
int i_rolname;
5425
+ int i_collencoding;
5410
5426
5411
5427
/* Collations didn't exist pre-9.1 */
5412
5428
if (fout->remoteVersion < 90100)
@@ -5424,7 +5440,8 @@ getCollations(Archive *fout, int *numCollations)
5424
5440
5425
5441
appendPQExpBuffer(query, "SELECT tableoid, oid, collname, "
5426
5442
"collnamespace, "
5427
- "(%s collowner) AS rolname "
5443
+ "(%s collowner) AS rolname, "
5444
+ "collencoding "
5428
5445
"FROM pg_collation",
5429
5446
username_subquery);
5430
5447
@@ -5440,6 +5457,7 @@ getCollations(Archive *fout, int *numCollations)
5440
5457
i_collname = PQfnumber(res, "collname");
5441
5458
i_collnamespace = PQfnumber(res, "collnamespace");
5442
5459
i_rolname = PQfnumber(res, "rolname");
5460
+ i_collencoding = PQfnumber(res, "collencoding");
5443
5461
5444
5462
for (i = 0; i < ntups; i++)
5445
5463
{
@@ -5452,6 +5470,7 @@ getCollations(Archive *fout, int *numCollations)
5452
5470
findNamespace(fout,
5453
5471
atooid(PQgetvalue(res, i, i_collnamespace)));
5454
5472
collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5473
+ collinfo[i].collencoding = atoi(PQgetvalue(res, i, i_collencoding));
5455
5474
5456
5475
/* Decide whether we want to dump it */
5457
5476
selectDumpableObject(&(collinfo[i].dobj), fout);
@@ -5561,19 +5580,28 @@ getAccessMethods(Archive *fout, int *numAccessMethods)
5561
5580
int i_amhandler;
5562
5581
int i_amtype;
5563
5582
5564
- /* Before 9.6, there are no user-defined access methods */
5565
- if (fout->remoteVersion < 90600)
5566
- {
5567
- *numAccessMethods = 0;
5568
- return NULL;
5569
- }
5570
-
5571
5583
query = createPQExpBuffer();
5572
5584
5573
- /* Select all access methods from pg_am table */
5574
- appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, amtype, "
5575
- "amhandler::pg_catalog.regproc AS amhandler "
5576
- "FROM pg_am");
5585
+ /*
5586
+ * Select all access methods from pg_am table. v9.6 introduced CREATE
5587
+ * ACCESS METHOD, so earlier versions usually have only built-in access
5588
+ * methods. v9.6 also changed the access method API, replacing dozens of
5589
+ * pg_am columns with amhandler. Even if a user created an access method
5590
+ * by "INSERT INTO pg_am", we have no way to translate pre-v9.6 pg_am
5591
+ * columns to a v9.6+ CREATE ACCESS METHOD. Hence, before v9.6, read
5592
+ * pg_am just to facilitate findAccessMethodByOid() providing the
5593
+ * OID-to-name mapping.
5594
+ */
5595
+ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, ");
5596
+ if (fout->remoteVersion >= 90600)
5597
+ appendPQExpBufferStr(query,
5598
+ "amtype, "
5599
+ "amhandler::pg_catalog.regproc AS amhandler ");
5600
+ else
5601
+ appendPQExpBufferStr(query,
5602
+ "'i'::pg_catalog.\"char\" AS amtype, "
5603
+ "'-'::pg_catalog.regproc AS amhandler ");
5604
+ appendPQExpBufferStr(query, "FROM pg_am");
5577
5605
5578
5606
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5579
5607
@@ -5631,6 +5659,7 @@ getOpclasses(Archive *fout, int *numOpclasses)
5631
5659
OpclassInfo *opcinfo;
5632
5660
int i_tableoid;
5633
5661
int i_oid;
5662
+ int i_opcmethod;
5634
5663
int i_opcname;
5635
5664
int i_opcnamespace;
5636
5665
int i_rolname;
@@ -5640,11 +5669,20 @@ getOpclasses(Archive *fout, int *numOpclasses)
5640
5669
* system-defined opclasses at dump-out time.
5641
5670
*/
5642
5671
5643
- appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, "
5644
- "opcnamespace, "
5645
- "(%s opcowner) AS rolname "
5646
- "FROM pg_opclass",
5647
- username_subquery);
5672
+ if (fout->remoteVersion >= 80300)
5673
+ appendPQExpBuffer(query, "SELECT tableoid, oid, "
5674
+ "opcmethod, opcname, "
5675
+ "opcnamespace, "
5676
+ "(%s opcowner) AS rolname "
5677
+ "FROM pg_opclass",
5678
+ username_subquery);
5679
+ else
5680
+ appendPQExpBuffer(query, "SELECT tableoid, oid, "
5681
+ "opcamid AS opcmethod, opcname, "
5682
+ "opcnamespace, "
5683
+ "(%s opcowner) AS rolname "
5684
+ "FROM pg_opclass",
5685
+ username_subquery);
5648
5686
5649
5687
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5650
5688
@@ -5655,6 +5693,7 @@ getOpclasses(Archive *fout, int *numOpclasses)
5655
5693
5656
5694
i_tableoid = PQfnumber(res, "tableoid");
5657
5695
i_oid = PQfnumber(res, "oid");
5696
+ i_opcmethod = PQfnumber(res, "opcmethod");
5658
5697
i_opcname = PQfnumber(res, "opcname");
5659
5698
i_opcnamespace = PQfnumber(res, "opcnamespace");
5660
5699
i_rolname = PQfnumber(res, "rolname");
@@ -5669,6 +5708,7 @@ getOpclasses(Archive *fout, int *numOpclasses)
5669
5708
opcinfo[i].dobj.namespace =
5670
5709
findNamespace(fout,
5671
5710
atooid(PQgetvalue(res, i, i_opcnamespace)));
5711
+ opcinfo[i].opcmethod = atooid(PQgetvalue(res, i, i_opcmethod));
5672
5712
opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5673
5713
5674
5714
/* Decide whether we want to dump it */
@@ -5706,6 +5746,7 @@ getOpfamilies(Archive *fout, int *numOpfamilies)
5706
5746
OpfamilyInfo *opfinfo;
5707
5747
int i_tableoid;
5708
5748
int i_oid;
5749
+ int i_opfmethod;
5709
5750
int i_opfname;
5710
5751
int i_opfnamespace;
5711
5752
int i_rolname;
@@ -5724,7 +5765,7 @@ getOpfamilies(Archive *fout, int *numOpfamilies)
5724
5765
* system-defined opfamilies at dump-out time.
5725
5766
*/
5726
5767
5727
- appendPQExpBuffer(query, "SELECT tableoid, oid, opfname, "
5768
+ appendPQExpBuffer(query, "SELECT tableoid, oid, opfmethod, opfname, "
5728
5769
"opfnamespace, "
5729
5770
"(%s opfowner) AS rolname "
5730
5771
"FROM pg_opfamily",
@@ -5740,6 +5781,7 @@ getOpfamilies(Archive *fout, int *numOpfamilies)
5740
5781
i_tableoid = PQfnumber(res, "tableoid");
5741
5782
i_oid = PQfnumber(res, "oid");
5742
5783
i_opfname = PQfnumber(res, "opfname");
5784
+ i_opfmethod = PQfnumber(res, "opfmethod");
5743
5785
i_opfnamespace = PQfnumber(res, "opfnamespace");
5744
5786
i_rolname = PQfnumber(res, "rolname");
5745
5787
@@ -5753,6 +5795,7 @@ getOpfamilies(Archive *fout, int *numOpfamilies)
5753
5795
opfinfo[i].dobj.namespace =
5754
5796
findNamespace(fout,
5755
5797
atooid(PQgetvalue(res, i, i_opfnamespace)));
5798
+ opfinfo[i].opfmethod = atooid(PQgetvalue(res, i, i_opfmethod));
5756
5799
opfinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5757
5800
5758
5801
/* Decide whether we want to dump it */
0 commit comments