33 * show.c: show backup information.
44 *
55 * Portions Copyright (c) 2009-2011, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
6- * Portions Copyright (c) 2015-2019 , Postgres Professional
6+ * Portions Copyright (c) 2015-2022 , Postgres Professional
77 *
88 *-------------------------------------------------------------------------
99 */
1212
1313#include <time.h>
1414#include <dirent.h>
15+ #include <locale.h>
1516#include <sys/stat.h>
1617
1718#include "utils/json.h"
@@ -71,6 +72,24 @@ static PQExpBufferData show_buf;
7172static bool first_instance = true;
7273static int32 json_level = 0 ;
7374
75+ typedef enum {
76+ LOCALE_PROBACKUP ,
77+ LOCALE_ENV
78+ }output_numeric_locale ;
79+
80+ static void set_output_numeric_locale (output_numeric_locale loc ) {
81+ const char * l = loc == LOCALE_PROBACKUP ?"C" : (const char * )getenv ("LC_NUMERIC" );
82+ // Setting environment-specified locale
83+ #ifdef HAVE_USELOCALE
84+ uselocale (newlocale (LC_NUMERIC_MASK ,l , (locale_t )0 ));
85+ #else
86+ #ifdef HAVE__CONFIGTHREADLOCALE
87+ _configthreadlocale (_ENABLE_PER_THREAD_LOCALE );
88+ #endif
89+ setlocale (LC_NUMERIC ,l );
90+ #endif
91+ }
92+
7493/*
7594 * Entry point of pg_probackup SHOW subcommand.
7695 */
@@ -88,6 +107,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
88107requested_backup_id != INVALID_BACKUP_ID )
89108elog (ERROR ,"You cannot specify --archive and (-i, --backup-id) options together" );
90109
110+ set_output_numeric_locale (LOCALE_ENV );
91111/*
92112 * if instance is not specified,
93113 * show information about all instances in this backup catalog
@@ -110,6 +130,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
110130show_instance (instanceState ,INVALID_BACKUP_ID , true);
111131}
112132show_instance_end ();
133+ set_output_numeric_locale (LOCALE_PROBACKUP );
113134
114135return 0 ;
115136}
@@ -128,6 +149,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
128149show_instance (instanceState ,requested_backup_id , false);
129150
130151show_instance_end ();
152+ set_output_numeric_locale (LOCALE_PROBACKUP );
131153
132154return 0 ;
133155}
@@ -141,6 +163,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
141163else
142164show_backup (instanceState ,requested_backup_id );
143165
166+ set_output_numeric_locale (LOCALE_PROBACKUP );
144167return 0 ;
145168}
146169}
@@ -1045,8 +1068,9 @@ show_archive_json(const char *instance_name, uint32 xlog_seg_size,
10451068appendPQExpBuffer (buf ,"%lu" ,tlinfo -> size );
10461069
10471070json_add_key (buf ,"zratio" ,json_level );
1071+
10481072if (tlinfo -> size != 0 )
1049- zratio = ((float )xlog_seg_size * tlinfo -> n_xlog_files ) /tlinfo -> size ;
1073+ zratio = ((float )xlog_seg_size * tlinfo -> n_xlog_files ) /tlinfo -> size ;
10501074appendPQExpBuffer (buf ,"%.2f" ,zratio );
10511075
10521076if (tlinfo -> closest_backup != NULL )