diff --git a/contrib/pg_upgrade/check.c b/contrib/pg_upgrade/check.c
new file mode 100644
index 2b481da..377dea2
*** a/contrib/pg_upgrade/check.c
--- b/contrib/pg_upgrade/check.c
*************** static void check_is_super_user(ClusterI
*** 19,24 ****
--- 19,25 ----
  static void check_for_prepared_transactions(ClusterInfo *cluster);
  static void check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster);
  static void check_for_reg_data_type_usage(ClusterInfo *cluster);
+ static void check_for_support_lib(ClusterInfo *cluster);
  
  
  void
*************** check_cluster_versions(void)
*** 245,265 ****
  void
  check_cluster_compatibility(bool live_check)
  {
! 	char		libfile[MAXPGPATH];
! 	FILE	   *lib_test;
! 
! 	/*
! 	 * Test pg_upgrade_support.so is in the proper place.	 We cannot copy it
! 	 * ourselves because install directories are typically root-owned.
! 	 */
! 	snprintf(libfile, sizeof(libfile), "%s/pg_upgrade_support%s", new_cluster.libpath,
! 			 DLSUFFIX);
! 
! 	if ((lib_test = fopen(libfile, "r")) == NULL)
! 		pg_log(PG_FATAL,
! 			   "pg_upgrade_support%s must be created and installed in %s\n", DLSUFFIX, libfile);
! 	else
! 		fclose(lib_test);
  
  	/* get/check pg_control data of servers */
  	get_control_data(&old_cluster, live_check);
--- 246,252 ----
  void
  check_cluster_compatibility(bool live_check)
  {
! 	check_for_support_lib(&new_cluster);
  
  	/* get/check pg_control data of servers */
  	get_control_data(&old_cluster, live_check);
*************** check_for_reg_data_type_usage(ClusterInf
*** 730,732 ****
--- 717,758 ----
  	else
  		check_ok();
  }
+ 
+ 
+ /*
+  * Test pg_upgrade_support.so is in the proper place.	 We cannot copy it
+  * ourselves because install directories are typically root-owned.
+  */
+ static void
+ check_for_support_lib(ClusterInfo *cluster)
+ {
+ 	char		cmd[MAXPGPATH];
+ 	char		libdir[MAX_STRING];
+ 	char		libfile[MAXPGPATH];
+ 	FILE	   *lib_test;
+ 	FILE	   *output;
+ 
+ 	snprintf(cmd, sizeof(cmd), "\"%s/pg_config\" --pkglibdir", cluster->bindir);
+ 
+ 	if ((output = popen(cmd, "r")) == NULL)
+ 		pg_log(PG_FATAL, "Could not get pkglibdir data: %s\n",
+ 			   getErrorText(errno));
+ 
+ 	fgets(libdir, sizeof(libdir), output);
+ 
+ 	pclose(output);
+ 
+ 	/* Remove trailing newline */
+ 	if (strchr(libdir, '\n') != NULL)
+ 		*strchr(libdir, '\n') = '\0';
+ 
+ 	snprintf(libfile, sizeof(libfile), "%s/pg_upgrade_support%s", libdir,
+ 			 DLSUFFIX);
+ 
+ 	if ((lib_test = fopen(libfile, "r")) == NULL)
+ 		pg_log(PG_FATAL,
+ 			   "The pg_upgrade_support module must be created and installed in the %s cluster.\n",
+ 				CLUSTER_NAME(cluster));
+ 
+ 	fclose(lib_test);
+ }
diff --git a/contrib/pg_upgrade/option.c b/contrib/pg_upgrade/option.c
new file mode 100644
index 8153e30..18ce9d7
*** a/contrib/pg_upgrade/option.c
--- b/contrib/pg_upgrade/option.c
***************
*** 19,26 ****
  static void usage(void);
  static void validateDirectoryOption(char **dirpath,
  				   char *envVarName, char *cmdLineOption, char *description);
- static void get_pkglibdirs(void);
- static char *get_pkglibdir(const char *bindir);
  
  
  UserOpts	user_opts;
--- 19,24 ----
*************** parseCommandLine(int argc, char *argv[])
*** 213,220 ****
  							"old cluster data resides");
  	validateDirectoryOption(&new_cluster.pgdata, "NEWDATADIR", "-D",
  							"new cluster data resides");
- 
- 	get_pkglibdirs();
  }
  
  
--- 211,216 ----
*************** validateDirectoryOption(char **dirpath, 
*** 314,357 ****
  #endif
  		(*dirpath)[strlen(*dirpath) - 1] = 0;
  }
- 
- 
- static void
- get_pkglibdirs(void)
- {
- 	/*
- 	 * we do not need to know the libpath in the old cluster, and might not
- 	 * have a working pg_config to ask for it anyway.
- 	 */
- 	old_cluster.libpath = NULL;
- 	new_cluster.libpath = get_pkglibdir(new_cluster.bindir);
- }
- 
- 
- static char *
- get_pkglibdir(const char *bindir)
- {
- 	char		cmd[MAXPGPATH];
- 	char		bufin[MAX_STRING];
- 	FILE	   *output;
- 	int			i;
- 
- 	snprintf(cmd, sizeof(cmd), "\"%s/pg_config\" --pkglibdir", bindir);
- 
- 	if ((output = popen(cmd, "r")) == NULL)
- 		pg_log(PG_FATAL, "Could not get pkglibdir data: %s\n",
- 			   getErrorText(errno));
- 
- 	fgets(bufin, sizeof(bufin), output);
- 
- 	if (output)
- 		pclose(output);
- 
- 	/* Remove trailing newline */
- 	i = strlen(bufin) - 1;
- 
- 	if (bufin[i] == '\n')
- 		bufin[i] = '\0';
- 
- 	return pg_strdup(bufin);
- }
--- 310,312 ----
diff --git a/contrib/pg_upgrade/pg_upgrade.h b/contrib/pg_upgrade/pg_upgrade.h
new file mode 100644
index a3a0856..c27b58a
*** a/contrib/pg_upgrade/pg_upgrade.h
--- b/contrib/pg_upgrade/pg_upgrade.h
*************** typedef struct
*** 185,191 ****
  	uint32		major_version;	/* PG_VERSION of cluster */
  	char		major_version_str[64];	/* string PG_VERSION of cluster */
  	Oid			pg_database_oid;	/* OID of pg_database relation */
- 	char	   *libpath;		/* pathname for cluster's pkglibdir */
  	char	   *tablespace_suffix;		/* directory specification */
  } ClusterInfo;
  
--- 185,190 ----
