3
3
* show.c: show backup information.
4
4
*
5
5
* 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
7
7
*
8
8
*-------------------------------------------------------------------------
9
9
*/
12
12
13
13
#include <time.h>
14
14
#include <dirent.h>
15
+ #include <locale.h>
15
16
#include <sys/stat.h>
16
17
17
18
#include "utils/json.h"
@@ -71,6 +72,24 @@ static PQExpBufferData show_buf;
71
72
static bool first_instance = true;
72
73
static int32 json_level = 0 ;
73
74
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
+
74
93
/*
75
94
* Entry point of pg_probackup SHOW subcommand.
76
95
*/
@@ -88,6 +107,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
88
107
requested_backup_id != INVALID_BACKUP_ID )
89
108
elog (ERROR , "You cannot specify --archive and (-i, --backup-id) options together" );
90
109
110
+ set_output_numeric_locale (LOCALE_ENV );
91
111
/*
92
112
* if instance is not specified,
93
113
* show information about all instances in this backup catalog
@@ -110,6 +130,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
110
130
show_instance (instanceState , INVALID_BACKUP_ID , true);
111
131
}
112
132
show_instance_end ();
133
+ set_output_numeric_locale (LOCALE_PROBACKUP );
113
134
114
135
return 0 ;
115
136
}
@@ -128,6 +149,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
128
149
show_instance (instanceState , requested_backup_id , false);
129
150
130
151
show_instance_end ();
152
+ set_output_numeric_locale (LOCALE_PROBACKUP );
131
153
132
154
return 0 ;
133
155
}
@@ -141,6 +163,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
141
163
else
142
164
show_backup (instanceState , requested_backup_id );
143
165
166
+ set_output_numeric_locale (LOCALE_PROBACKUP );
144
167
return 0 ;
145
168
}
146
169
}
@@ -1045,8 +1068,9 @@ show_archive_json(const char *instance_name, uint32 xlog_seg_size,
1045
1068
appendPQExpBuffer (buf , "%lu" , tlinfo -> size );
1046
1069
1047
1070
json_add_key (buf , "zratio" , json_level );
1071
+
1048
1072
if (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 ;
1050
1074
appendPQExpBuffer (buf , "%.2f" , zratio );
1051
1075
1052
1076
if (tlinfo -> closest_backup != NULL )
0 commit comments