@@ -130,6 +130,7 @@ get_loadable_libraries(void)
130
130
PGresult * * ress ;
131
131
int totaltups ;
132
132
int dbnum ;
133
+ bool found_public_plpython_handler = false;
133
134
134
135
ress = (PGresult * * )
135
136
pg_malloc (old_cluster .dbarr .ndbs * sizeof (PGresult * ));
@@ -151,9 +152,67 @@ get_loadable_libraries(void)
151
152
FirstNormalObjectId );
152
153
totaltups += PQntuples (ress [dbnum ]);
153
154
155
+ /*
156
+ *Systems that install plpython before 8.1 have
157
+ *plpython_call_handler() defined in the "public" schema, causing
158
+ *pg_dumpall to dump it. However that function still references
159
+ *"plpython" (no "2"), so it throws an error on restore. This code
160
+ *checks for the problem function, reports affected databases to the
161
+ *user and explains how to remove them.
162
+ *8.1 git commit: e0dedd0559f005d60c69c9772163e69c204bac69
163
+ *http://archives.postgresql.org/pgsql-hackers/2012-03/msg01101.php
164
+ *http://archives.postgresql.org/pgsql-bugs/2012-05/msg00206.php
165
+ */
166
+ if (GET_MAJOR_VERSION (old_cluster .major_version )< 901 )
167
+ {
168
+ PGresult * res ;
169
+
170
+ res = executeQueryOrDie (conn ,
171
+ "SELECT 1 "
172
+ "FROMpg_catalog.pg_proc JOIN pg_namespace "
173
+ "ON pronamespace = pg_namespace.oid "
174
+ "WHERE proname = 'plpython_call_handler' AND "
175
+ "nspname = 'public' AND "
176
+ "prolang = 13 /* C */ AND "
177
+ "probin = '$libdir/plpython' AND "
178
+ "pg_proc.oid >= %u;" ,
179
+ FirstNormalObjectId );
180
+ if (PQntuples (res )> 0 )
181
+ {
182
+ if (!found_public_plpython_handler )
183
+ {
184
+ pg_log (PG_WARNING ,
185
+ "\nThe old cluster has a \"plpython_call_handler\" function defined\n"
186
+ "in the \"public\" schema which is a duplicate of the one defined\n"
187
+ "in the \"pg_catalog\" schema. You can confirm this by executing\n"
188
+ "in psql:\n"
189
+ "\n"
190
+ "\\df *.plpython_call_handler\n"
191
+ "\n"
192
+ "The \"public\" schema version of this function was created by a\n"
193
+ "pre-8.1 install of plpython, and must be removed for pg_upgrade\n"
194
+ "to complete because it references a now-obsolete \"plpython\"\n"
195
+ "shared object file. You can remove the \"public\" schema version\n"
196
+ "of this function by running the following command:\n"
197
+ "\n"
198
+ "DROP FUNCTION public.plpython_call_handler()\n"
199
+ "\n"
200
+ "in each affected database:\n"
201
+ "\n" );
202
+ }
203
+ pg_log (PG_WARNING ,"%s\n" ,active_db -> db_name );
204
+ found_public_plpython_handler = true;
205
+ }
206
+ PQclear (res );
207
+ }
208
+
154
209
PQfinish (conn );
155
210
}
156
211
212
+ if (found_public_plpython_handler )
213
+ pg_log (PG_FATAL ,
214
+ "Remove the problem functions from the old cluster to continue.\n" );
215
+
157
216
totaltups ++ ;/* reserve for pg_upgrade_support */
158
217
159
218
/* Allocate what's certainly enough space */