#include "utils/acl.h"
 #include "utils/flatfiles.h"
 #include "utils/guc.h"
+#include "utils/pg_locale.h"
 #include "utils/plancache.h"
 #include "utils/portal.h"
 #include "utils/relcache.h"
        collate = NameStr(dbform->datcollate);
        ctype = NameStr(dbform->datctype);
 
-       if (setlocale(LC_COLLATE, collate) == NULL)
+       if (pg_perm_setlocale(LC_COLLATE, collate) == NULL)
                ereport(FATAL,
                        (errmsg("database locale is incompatible with operating system"),
                         errdetail("The database was initialized with LC_COLLATE \"%s\", "
                                           " which is not recognized by setlocale().", collate),
                         errhint("Recreate the database with another locale or install the missing locale.")));
 
-       if (setlocale(LC_CTYPE, ctype) == NULL)
+       if (pg_perm_setlocale(LC_CTYPE, ctype) == NULL)
                ereport(FATAL,
                        (errmsg("database locale is incompatible with operating system"),
                         errdetail("The database was initialized with LC_CTYPE \"%s\", "