@@ -1899,6 +1899,13 @@ selectDumpableProcLang(ProcLangInfo *plang, Archive *fout)
1899
1899
static void
1900
1900
selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
1901
1901
{
1902
+ /* see getAccessMethods() comment about v9.6. */
1903
+ if (fout->remoteVersion < 90600)
1904
+ {
1905
+ method->dobj.dump = DUMP_COMPONENT_NONE;
1906
+ return;
1907
+ }
1908
+
1902
1909
if (checkExtensionMembership(&method->dobj, fout))
1903
1910
return; /* extension membership overrides all else */
1904
1911
@@ -5525,6 +5532,8 @@ getOperators(Archive *fout, int *numOprs)
5525
5532
int i_oprnamespace;
5526
5533
int i_rolname;
5527
5534
int i_oprkind;
5535
+ int i_oprleft;
5536
+ int i_oprright;
5528
5537
int i_oprcode;
5529
5538
5530
5539
/*
@@ -5536,6 +5545,8 @@ getOperators(Archive *fout, int *numOprs)
5536
5545
"oprnamespace, "
5537
5546
"(%s oprowner) AS rolname, "
5538
5547
"oprkind, "
5548
+ "oprleft, "
5549
+ "oprright, "
5539
5550
"oprcode::oid AS oprcode "
5540
5551
"FROM pg_operator",
5541
5552
username_subquery);
@@ -5553,6 +5564,8 @@ getOperators(Archive *fout, int *numOprs)
5553
5564
i_oprnamespace = PQfnumber(res, "oprnamespace");
5554
5565
i_rolname = PQfnumber(res, "rolname");
5555
5566
i_oprkind = PQfnumber(res, "oprkind");
5567
+ i_oprleft = PQfnumber(res, "oprleft");
5568
+ i_oprright = PQfnumber(res, "oprright");
5556
5569
i_oprcode = PQfnumber(res, "oprcode");
5557
5570
5558
5571
for (i = 0; i < ntups; i++)
@@ -5566,6 +5579,8 @@ getOperators(Archive *fout, int *numOprs)
5566
5579
findNamespace(atooid(PQgetvalue(res, i, i_oprnamespace)));
5567
5580
oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5568
5581
oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
5582
+ oprinfo[i].oprleft = atooid(PQgetvalue(res, i, i_oprleft));
5583
+ oprinfo[i].oprright = atooid(PQgetvalue(res, i, i_oprright));
5569
5584
oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
5570
5585
5571
5586
/* Decide whether we want to dump it */
@@ -5606,6 +5621,7 @@ getCollations(Archive *fout, int *numCollations)
5606
5621
int i_collname;
5607
5622
int i_collnamespace;
5608
5623
int i_rolname;
5624
+ int i_collencoding;
5609
5625
5610
5626
/* Collations didn't exist pre-9.1 */
5611
5627
if (fout->remoteVersion < 90100)
@@ -5623,7 +5639,8 @@ getCollations(Archive *fout, int *numCollations)
5623
5639
5624
5640
appendPQExpBuffer(query, "SELECT tableoid, oid, collname, "
5625
5641
"collnamespace, "
5626
- "(%s collowner) AS rolname "
5642
+ "(%s collowner) AS rolname, "
5643
+ "collencoding "
5627
5644
"FROM pg_collation",
5628
5645
username_subquery);
5629
5646
@@ -5639,6 +5656,7 @@ getCollations(Archive *fout, int *numCollations)
5639
5656
i_collname = PQfnumber(res, "collname");
5640
5657
i_collnamespace = PQfnumber(res, "collnamespace");
5641
5658
i_rolname = PQfnumber(res, "rolname");
5659
+ i_collencoding = PQfnumber(res, "collencoding");
5642
5660
5643
5661
for (i = 0; i < ntups; i++)
5644
5662
{
@@ -5650,6 +5668,7 @@ getCollations(Archive *fout, int *numCollations)
5650
5668
collinfo[i].dobj.namespace =
5651
5669
findNamespace(atooid(PQgetvalue(res, i, i_collnamespace)));
5652
5670
collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5671
+ collinfo[i].collencoding = atoi(PQgetvalue(res, i, i_collencoding));
5653
5672
5654
5673
/* Decide whether we want to dump it */
5655
5674
selectDumpableObject(&(collinfo[i].dobj), fout);
@@ -5758,19 +5777,28 @@ getAccessMethods(Archive *fout, int *numAccessMethods)
5758
5777
int i_amhandler;
5759
5778
int i_amtype;
5760
5779
5761
- /* Before 9.6, there are no user-defined access methods */
5762
- if (fout->remoteVersion < 90600)
5763
- {
5764
- *numAccessMethods = 0;
5765
- return NULL;
5766
- }
5767
-
5768
5780
query = createPQExpBuffer();
5769
5781
5770
- /* Select all access methods from pg_am table */
5771
- appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, amtype, "
5772
- "amhandler::pg_catalog.regproc AS amhandler "
5773
- "FROM pg_am");
5782
+ /*
5783
+ * Select all access methods from pg_am table. v9.6 introduced CREATE
5784
+ * ACCESS METHOD, so earlier versions usually have only built-in access
5785
+ * methods. v9.6 also changed the access method API, replacing dozens of
5786
+ * pg_am columns with amhandler. Even if a user created an access method
5787
+ * by "INSERT INTO pg_am", we have no way to translate pre-v9.6 pg_am
5788
+ * columns to a v9.6+ CREATE ACCESS METHOD. Hence, before v9.6, read
5789
+ * pg_am just to facilitate findAccessMethodByOid() providing the
5790
+ * OID-to-name mapping.
5791
+ */
5792
+ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, ");
5793
+ if (fout->remoteVersion >= 90600)
5794
+ appendPQExpBufferStr(query,
5795
+ "amtype, "
5796
+ "amhandler::pg_catalog.regproc AS amhandler ");
5797
+ else
5798
+ appendPQExpBufferStr(query,
5799
+ "'i'::pg_catalog.\"char\" AS amtype, "
5800
+ "'-'::pg_catalog.regproc AS amhandler ");
5801
+ appendPQExpBufferStr(query, "FROM pg_am");
5774
5802
5775
5803
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5776
5804
@@ -5828,6 +5856,7 @@ getOpclasses(Archive *fout, int *numOpclasses)
5828
5856
OpclassInfo *opcinfo;
5829
5857
int i_tableoid;
5830
5858
int i_oid;
5859
+ int i_opcmethod;
5831
5860
int i_opcname;
5832
5861
int i_opcnamespace;
5833
5862
int i_rolname;
@@ -5837,11 +5866,20 @@ getOpclasses(Archive *fout, int *numOpclasses)
5837
5866
* system-defined opclasses at dump-out time.
5838
5867
*/
5839
5868
5840
- appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, "
5841
- "opcnamespace, "
5842
- "(%s opcowner) AS rolname "
5843
- "FROM pg_opclass",
5844
- username_subquery);
5869
+ if (fout->remoteVersion >= 80300)
5870
+ appendPQExpBuffer(query, "SELECT tableoid, oid, "
5871
+ "opcmethod, opcname, "
5872
+ "opcnamespace, "
5873
+ "(%s opcowner) AS rolname "
5874
+ "FROM pg_opclass",
5875
+ username_subquery);
5876
+ else
5877
+ appendPQExpBuffer(query, "SELECT tableoid, oid, "
5878
+ "opcamid AS opcmethod, opcname, "
5879
+ "opcnamespace, "
5880
+ "(%s opcowner) AS rolname "
5881
+ "FROM pg_opclass",
5882
+ username_subquery);
5845
5883
5846
5884
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5847
5885
@@ -5852,6 +5890,7 @@ getOpclasses(Archive *fout, int *numOpclasses)
5852
5890
5853
5891
i_tableoid = PQfnumber(res, "tableoid");
5854
5892
i_oid = PQfnumber(res, "oid");
5893
+ i_opcmethod = PQfnumber(res, "opcmethod");
5855
5894
i_opcname = PQfnumber(res, "opcname");
5856
5895
i_opcnamespace = PQfnumber(res, "opcnamespace");
5857
5896
i_rolname = PQfnumber(res, "rolname");
@@ -5865,6 +5904,7 @@ getOpclasses(Archive *fout, int *numOpclasses)
5865
5904
opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
5866
5905
opcinfo[i].dobj.namespace =
5867
5906
findNamespace(atooid(PQgetvalue(res, i, i_opcnamespace)));
5907
+ opcinfo[i].opcmethod = atooid(PQgetvalue(res, i, i_opcmethod));
5868
5908
opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5869
5909
5870
5910
/* Decide whether we want to dump it */
@@ -5902,6 +5942,7 @@ getOpfamilies(Archive *fout, int *numOpfamilies)
5902
5942
OpfamilyInfo *opfinfo;
5903
5943
int i_tableoid;
5904
5944
int i_oid;
5945
+ int i_opfmethod;
5905
5946
int i_opfname;
5906
5947
int i_opfnamespace;
5907
5948
int i_rolname;
@@ -5920,7 +5961,7 @@ getOpfamilies(Archive *fout, int *numOpfamilies)
5920
5961
* system-defined opfamilies at dump-out time.
5921
5962
*/
5922
5963
5923
- appendPQExpBuffer(query, "SELECT tableoid, oid, opfname, "
5964
+ appendPQExpBuffer(query, "SELECT tableoid, oid, opfmethod, opfname, "
5924
5965
"opfnamespace, "
5925
5966
"(%s opfowner) AS rolname "
5926
5967
"FROM pg_opfamily",
@@ -5936,6 +5977,7 @@ getOpfamilies(Archive *fout, int *numOpfamilies)
5936
5977
i_tableoid = PQfnumber(res, "tableoid");
5937
5978
i_oid = PQfnumber(res, "oid");
5938
5979
i_opfname = PQfnumber(res, "opfname");
5980
+ i_opfmethod = PQfnumber(res, "opfmethod");
5939
5981
i_opfnamespace = PQfnumber(res, "opfnamespace");
5940
5982
i_rolname = PQfnumber(res, "rolname");
5941
5983
@@ -5948,6 +5990,7 @@ getOpfamilies(Archive *fout, int *numOpfamilies)
5948
5990
opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
5949
5991
opfinfo[i].dobj.namespace =
5950
5992
findNamespace(atooid(PQgetvalue(res, i, i_opfnamespace)));
5993
+ opfinfo[i].opfmethod = atooid(PQgetvalue(res, i, i_opfmethod));
5951
5994
opfinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
5952
5995
5953
5996
/* Decide whether we want to dump it */
0 commit comments