During development, I have been using the attached patch to simulate
libc collation versions on macOS. It just uses the internal major OS
version number. I don't know to what the extend the libc locales on
macOS are maintained or updated at all, so I don't know what practical
effect this would have. Again, it's mainly for development. If there
is interest from others, I think we could add this, maybe disabled by
default, or we just keep it in the mailing list archives for interested
parties.From 5e6f1a94a839981755f0380960511e60aba2b8d2 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Tue, 1 Feb 2022 16:07:29 +0100
Subject: [PATCH] Collation version tracking for macOS
---
src/backend/utils/adt/pg_locale.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/src/backend/utils/adt/pg_locale.c
b/src/backend/utils/adt/pg_locale.c
index 871a710967..f8e57ee236 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -74,6 +74,10 @@
#include <gnu/libc-version.h>
#endif
+#ifdef __APPLE__
+#include <sys/sysctl.h>
+#endif
+
#ifdef WIN32
#include <shlwapi.h>
#endif
@@ -1696,6 +1700,28 @@ get_collation_actual_version(char collprovider, const
char *collcollate)
else
ereport(ERROR,
(errmsg("could not load locale \"%s\"",
collcollate)));
+#elif defined(__APPLE__)
+ /*
+ * The POSIX-level locales on macOS are mostly useless for real
work,
+ * and they also don't appear to change much or at all.
However, at
+ * least for development it is useful to have some version
tracking
+ * mechanism on this platform. For lack of better ideas, we
just
+ * record the internal major operating system version.
+ */
+ {
+ char str[256];
+ size_t len = sizeof(str);
+ char *p;
+
+ if (sysctlbyname("kern.osrelease", str, &len, NULL, 0)
!= 0)
+ ereport(ERROR,
+ (errmsg("could not get OS
release: %m")));
+ /* value is three numbers like "12.3.4", we take only
the first one */
+ p = strchr(str, '.');
+ if (p)
+ *p = '\0';
+ collversion = pstrdup(str);
+ }
#elif defined(WIN32) && _WIN32_WINNT >= 0x0600
/*
* If we are targeting Windows Vista and above, we can ask for
a name
--
2.35.1