@ -16,9 +16,6 @@
# include "pg_upgrade.h"
static void check_new_cluster_is_empty ( void ) ;
static void check_databases_are_compatible ( void ) ;
static void check_locale_and_encoding ( DbInfo * olddb , DbInfo * newdb ) ;
static bool equivalent_locale ( int category , const char * loca , const char * locb ) ;
static void check_is_install_user ( ClusterInfo * cluster ) ;
static void check_proper_datallowconn ( ClusterInfo * cluster ) ;
static void check_for_prepared_transactions ( ClusterInfo * cluster ) ;
@ -33,7 +30,6 @@ static void check_for_jsonb_9_4_usage(ClusterInfo *cluster);
static void check_for_pg_role_prefix ( ClusterInfo * cluster ) ;
static void check_for_new_tablespace_dir ( ClusterInfo * new_cluster ) ;
static void check_for_user_defined_encoding_conversions ( ClusterInfo * cluster ) ;
static char * get_canonical_locale_name ( int category , const char * locale ) ;
/*
@ -194,7 +190,6 @@ check_new_cluster(void)
get_db_and_rel_infos ( & new_cluster ) ;
check_new_cluster_is_empty ( ) ;
check_databases_are_compatible ( ) ;
check_loadable_libraries ( ) ;
@ -349,94 +344,6 @@ check_cluster_compatibility(bool live_check)
}
/*
* check_locale_and_encoding ( )
*
* Check that locale and encoding of a database in the old and new clusters
* are compatible .
*/
static void
check_locale_and_encoding ( DbInfo * olddb , DbInfo * newdb )
{
if ( olddb - > db_encoding ! = newdb - > db_encoding )
pg_fatal ( " encodings for database \" %s \" do not match: old \" %s \" , new \" %s \" " ,
olddb - > db_name ,
pg_encoding_to_char ( olddb - > db_encoding ) ,
pg_encoding_to_char ( newdb - > db_encoding ) ) ;
if ( ! equivalent_locale ( LC_COLLATE , olddb - > db_collate , newdb - > db_collate ) )
pg_fatal ( " lc_collate values for database \" %s \" do not match: old \" %s \" , new \" %s \" " ,
olddb - > db_name , olddb - > db_collate , newdb - > db_collate ) ;
if ( ! equivalent_locale ( LC_CTYPE , olddb - > db_ctype , newdb - > db_ctype ) )
pg_fatal ( " lc_ctype values for database \" %s \" do not match: old \" %s \" , new \" %s \" " ,
olddb - > db_name , olddb - > db_ctype , newdb - > db_ctype ) ;
if ( olddb - > db_collprovider ! = newdb - > db_collprovider )
pg_fatal ( " locale providers for database \" %s \" do not match: old \" %s \" , new \" %s \" " ,
olddb - > db_name ,
collprovider_name ( olddb - > db_collprovider ) ,
collprovider_name ( newdb - > db_collprovider ) ) ;
if ( ( olddb - > db_iculocale = = NULL & & newdb - > db_iculocale ! = NULL ) | |
( olddb - > db_iculocale ! = NULL & & newdb - > db_iculocale = = NULL ) | |
( olddb - > db_iculocale ! = NULL & & newdb - > db_iculocale ! = NULL & & strcmp ( olddb - > db_iculocale , newdb - > db_iculocale ) ! = 0 ) )
pg_fatal ( " ICU locale values for database \" %s \" do not match: old \" %s \" , new \" %s \" " ,
olddb - > db_name ,
olddb - > db_iculocale ? olddb - > db_iculocale : " (null) " ,
newdb - > db_iculocale ? newdb - > db_iculocale : " (null) " ) ;
}
/*
* equivalent_locale ( )
*
* Best effort locale - name comparison . Return false if we are not 100 % sure
* the locales are equivalent .
*
* Note : The encoding parts of the names are ignored . This function is
* currently used to compare locale names stored in pg_database , and
* pg_database contains a separate encoding field . That ' s compared directly
* in check_locale_and_encoding ( ) .
*/
static bool
equivalent_locale ( int category , const char * loca , const char * locb )
{
const char * chara ;
const char * charb ;
char * canona ;
char * canonb ;
int lena ;
int lenb ;
/*
* If the names are equal , the locales are equivalent . Checking this first
* avoids calling setlocale ( ) in the common case that the names are equal .
* That ' s a good thing , if setlocale ( ) is buggy , for example .
*/
if ( pg_strcasecmp ( loca , locb ) = = 0 )
return true ;
/*
* Not identical . Canonicalize both names , remove the encoding parts , and
* try again .
*/
canona = get_canonical_locale_name ( category , loca ) ;
chara = strrchr ( canona , ' . ' ) ;
lena = chara ? ( chara - canona ) : strlen ( canona ) ;
canonb = get_canonical_locale_name ( category , locb ) ;
charb = strrchr ( canonb , ' . ' ) ;
lenb = charb ? ( charb - canonb ) : strlen ( canonb ) ;
if ( lena = = lenb & & pg_strncasecmp ( canona , canonb , lena ) = = 0 )
{
pg_free ( canona ) ;
pg_free ( canonb ) ;
return true ;
}
pg_free ( canona ) ;
pg_free ( canonb ) ;
return false ;
}
static void
check_new_cluster_is_empty ( void )
{
@ -460,35 +367,6 @@ check_new_cluster_is_empty(void)
}
}
/*
* Check that every database that already exists in the new cluster is
* compatible with the corresponding database in the old one .
*/
static void
check_databases_are_compatible ( void )
{
int newdbnum ;
int olddbnum ;
DbInfo * newdbinfo ;
DbInfo * olddbinfo ;
for ( newdbnum = 0 ; newdbnum < new_cluster . dbarr . ndbs ; newdbnum + + )
{
newdbinfo = & new_cluster . dbarr . dbs [ newdbnum ] ;
/* Find the corresponding database in the old cluster */
for ( olddbnum = 0 ; olddbnum < old_cluster . dbarr . ndbs ; olddbnum + + )
{
olddbinfo = & old_cluster . dbarr . dbs [ olddbnum ] ;
if ( strcmp ( newdbinfo - > db_name , olddbinfo - > db_name ) = = 0 )
{
check_locale_and_encoding ( olddbinfo , newdbinfo ) ;
break ;
}
}
}
}
/*
* A previous run of pg_upgrade might have failed and the new cluster
* directory recreated , but they might have forgotten to remove
@ -1524,41 +1402,3 @@ check_for_user_defined_encoding_conversions(ClusterInfo *cluster)
else
check_ok ( ) ;
}
/*
* get_canonical_locale_name
*
* Send the locale name to the system , and hope we get back a canonical
* version . This should match the backend ' s check_locale ( ) function .
*/
static char *
get_canonical_locale_name ( int category , const char * locale )
{
char * save ;
char * res ;
/* get the current setting, so we can restore it. */
save = setlocale ( category , NULL ) ;
if ( ! save )
pg_fatal ( " failed to get the current locale " ) ;
/* 'save' may be pointing at a modifiable scratch variable, so copy it. */
save = pg_strdup ( save ) ;
/* set the locale with setlocale, to see if it accepts it. */
res = setlocale ( category , locale ) ;
if ( ! res )
pg_fatal ( " failed to get system locale name for \" %s \" " , locale ) ;
res = pg_strdup ( res ) ;
/* restore old value. */
if ( ! setlocale ( category , save ) )
pg_fatal ( " failed to restore old locale \" %s \" " , save ) ;
pg_free ( save ) ;
return res ;
}