16
16
#include "pg_upgrade.h"
17
17
18
18
static void check_new_cluster_is_empty (void );
19
- static void check_databases_are_compatible (void );
20
- static void check_locale_and_encoding (DbInfo * olddb , DbInfo * newdb );
21
- static bool equivalent_locale (int category , const char * loca , const char * locb );
22
19
static void check_is_install_user (ClusterInfo * cluster );
23
20
static void check_proper_datallowconn (ClusterInfo * cluster );
24
21
static void check_for_prepared_transactions (ClusterInfo * cluster );
@@ -33,7 +30,6 @@ static void check_for_jsonb_9_4_usage(ClusterInfo *cluster);
33
30
static void check_for_pg_role_prefix (ClusterInfo * cluster );
34
31
static void check_for_new_tablespace_dir (ClusterInfo * new_cluster );
35
32
static void check_for_user_defined_encoding_conversions (ClusterInfo * cluster );
36
- static char * get_canonical_locale_name (int category , const char * locale );
37
33
38
34
39
35
/*
@@ -194,7 +190,6 @@ check_new_cluster(void)
194
190
get_db_and_rel_infos (& new_cluster );
195
191
196
192
check_new_cluster_is_empty ();
197
- check_databases_are_compatible ();
198
193
199
194
check_loadable_libraries ();
200
195
@@ -349,94 +344,6 @@ check_cluster_compatibility(bool live_check)
349
344
}
350
345
351
346
352
- /*
353
- * check_locale_and_encoding()
354
- *
355
- * Check that locale and encoding of a database in the old and new clusters
356
- * are compatible.
357
- */
358
- static void
359
- check_locale_and_encoding (DbInfo * olddb , DbInfo * newdb )
360
- {
361
- if (olddb -> db_encoding != newdb -> db_encoding )
362
- pg_fatal ("encodings for database \"%s\" do not match: old \"%s\", new \"%s\"" ,
363
- olddb -> db_name ,
364
- pg_encoding_to_char (olddb -> db_encoding ),
365
- pg_encoding_to_char (newdb -> db_encoding ));
366
- if (!equivalent_locale (LC_COLLATE , olddb -> db_collate , newdb -> db_collate ))
367
- pg_fatal ("lc_collate values for database \"%s\" do not match: old \"%s\", new \"%s\"" ,
368
- olddb -> db_name , olddb -> db_collate , newdb -> db_collate );
369
- if (!equivalent_locale (LC_CTYPE , olddb -> db_ctype , newdb -> db_ctype ))
370
- pg_fatal ("lc_ctype values for database \"%s\" do not match: old \"%s\", new \"%s\"" ,
371
- olddb -> db_name , olddb -> db_ctype , newdb -> db_ctype );
372
- if (olddb -> db_collprovider != newdb -> db_collprovider )
373
- pg_fatal ("locale providers for database \"%s\" do not match: old \"%s\", new \"%s\"" ,
374
- olddb -> db_name ,
375
- collprovider_name (olddb -> db_collprovider ),
376
- collprovider_name (newdb -> db_collprovider ));
377
- if ((olddb -> db_iculocale == NULL && newdb -> db_iculocale != NULL ) ||
378
- (olddb -> db_iculocale != NULL && newdb -> db_iculocale == NULL ) ||
379
- (olddb -> db_iculocale != NULL && newdb -> db_iculocale != NULL && strcmp (olddb -> db_iculocale , newdb -> db_iculocale ) != 0 ))
380
- pg_fatal ("ICU locale values for database \"%s\" do not match: old \"%s\", new \"%s\"" ,
381
- olddb -> db_name ,
382
- olddb -> db_iculocale ? olddb -> db_iculocale : "(null)" ,
383
- newdb -> db_iculocale ? newdb -> db_iculocale : "(null)" );
384
- }
385
-
386
- /*
387
- * equivalent_locale()
388
- *
389
- * Best effort locale-name comparison. Return false if we are not 100% sure
390
- * the locales are equivalent.
391
- *
392
- * Note: The encoding parts of the names are ignored. This function is
393
- * currently used to compare locale names stored in pg_database, and
394
- * pg_database contains a separate encoding field. That's compared directly
395
- * in check_locale_and_encoding().
396
- */
397
- static bool
398
- equivalent_locale (int category , const char * loca , const char * locb )
399
- {
400
- const char * chara ;
401
- const char * charb ;
402
- char * canona ;
403
- char * canonb ;
404
- int lena ;
405
- int lenb ;
406
-
407
- /*
408
- * If the names are equal, the locales are equivalent. Checking this first
409
- * avoids calling setlocale() in the common case that the names are equal.
410
- * That's a good thing, if setlocale() is buggy, for example.
411
- */
412
- if (pg_strcasecmp (loca , locb ) == 0 )
413
- return true;
414
-
415
- /*
416
- * Not identical. Canonicalize both names, remove the encoding parts, and
417
- * try again.
418
- */
419
- canona = get_canonical_locale_name (category , loca );
420
- chara = strrchr (canona , '.' );
421
- lena = chara ? (chara - canona ) : strlen (canona );
422
-
423
- canonb = get_canonical_locale_name (category , locb );
424
- charb = strrchr (canonb , '.' );
425
- lenb = charb ? (charb - canonb ) : strlen (canonb );
426
-
427
- if (lena == lenb && pg_strncasecmp (canona , canonb , lena ) == 0 )
428
- {
429
- pg_free (canona );
430
- pg_free (canonb );
431
- return true;
432
- }
433
-
434
- pg_free (canona );
435
- pg_free (canonb );
436
- return false;
437
- }
438
-
439
-
440
347
static void
441
348
check_new_cluster_is_empty (void )
442
349
{
@@ -460,35 +367,6 @@ check_new_cluster_is_empty(void)
460
367
}
461
368
}
462
369
463
- /*
464
- * Check that every database that already exists in the new cluster is
465
- * compatible with the corresponding database in the old one.
466
- */
467
- static void
468
- check_databases_are_compatible (void )
469
- {
470
- int newdbnum ;
471
- int olddbnum ;
472
- DbInfo * newdbinfo ;
473
- DbInfo * olddbinfo ;
474
-
475
- for (newdbnum = 0 ; newdbnum < new_cluster .dbarr .ndbs ; newdbnum ++ )
476
- {
477
- newdbinfo = & new_cluster .dbarr .dbs [newdbnum ];
478
-
479
- /* Find the corresponding database in the old cluster */
480
- for (olddbnum = 0 ; olddbnum < old_cluster .dbarr .ndbs ; olddbnum ++ )
481
- {
482
- olddbinfo = & old_cluster .dbarr .dbs [olddbnum ];
483
- if (strcmp (newdbinfo -> db_name , olddbinfo -> db_name ) == 0 )
484
- {
485
- check_locale_and_encoding (olddbinfo , newdbinfo );
486
- break ;
487
- }
488
- }
489
- }
490
- }
491
-
492
370
/*
493
371
* A previous run of pg_upgrade might have failed and the new cluster
494
372
* directory recreated, but they might have forgotten to remove
@@ -1524,41 +1402,3 @@ check_for_user_defined_encoding_conversions(ClusterInfo *cluster)
1524
1402
else
1525
1403
check_ok ();
1526
1404
}
1527
-
1528
-
1529
- /*
1530
- * get_canonical_locale_name
1531
- *
1532
- * Send the locale name to the system, and hope we get back a canonical
1533
- * version. This should match the backend's check_locale() function.
1534
- */
1535
- static char *
1536
- get_canonical_locale_name (int category , const char * locale )
1537
- {
1538
- char * save ;
1539
- char * res ;
1540
-
1541
- /* get the current setting, so we can restore it. */
1542
- save = setlocale (category , NULL );
1543
- if (!save )
1544
- pg_fatal ("failed to get the current locale" );
1545
-
1546
- /* 'save' may be pointing at a modifiable scratch variable, so copy it. */
1547
- save = pg_strdup (save );
1548
-
1549
- /* set the locale with setlocale, to see if it accepts it. */
1550
- res = setlocale (category , locale );
1551
-
1552
- if (!res )
1553
- pg_fatal ("failed to get system locale name for \"%s\"" , locale );
1554
-
1555
- res = pg_strdup (res );
1556
-
1557
- /* restore old value. */
1558
- if (!setlocale (category , save ))
1559
- pg_fatal ("failed to restore old locale \"%s\"" , save );
1560
-
1561
- pg_free (save );
1562
-
1563
- return res ;
1564
- }
0 commit comments