Path: redb/redb.Postgres/Data/PostgresServerVersion.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Postgres/Data/PostgresServerVersion.cs ---- using System; using System.Globalization; namespace redb.Postgres.Data; /// /// The lowest PostgreSQL server redb runs on, checked before any schema work. 15: the schema creates /// IX__list_items_unique with NULLS NOT DISTINCT, which older servers reject as a syntax error in the middle of /// the creation script. The service checks at initialization (), redb init before it /// sends the script. /// internal static class PostgresServerVersion { /// The lowest supported major version. public const int RequiredMajor = 15; /// Returns the server version as one integer (150004 for 15.4), on every server since 8.2. public const string Query = "SHOW server_version_num"; /// /// The message for a server older than , or null when the server is new enough. /// is the answer of . /// public static string? FindProblem(string? versionNum) { if (!int.TryParse(versionNum?.Trim(), NumberStyles.None, CultureInfo.InvariantCulture, out var number)) { return $"redb needs PostgreSQL {RequiredMajor} or newer, and the server version could not be read " + $"(server_version_num returned '{versionNum}')."; } if (number >= RequiredMajor * 10000) return null; return $"redb needs PostgreSQL {RequiredMajor} or newer; this server is PostgreSQL {Display(number)} " + $"(server_version_num {number}). Upgrade the server: the schema uses unique indexes with NULLS NOT " + "DISTINCT, which PostgreSQL has from version 15 on."; } /// Throws with the message of . public static void EnsureSupported(string? versionNum) { var problem = FindProblem(versionNum); if (problem != null) throw new NotSupportedException(problem); } // 10 and later: major * 10000 + minor. Before 10: major * 10000 + second * 100 + minor (90624 = 9.6.24). private static string Display(int number) => number >= 100000 ? $"{number / 10000}.{number % 10000}" : $"{number / 10000}.{number / 100 % 100}.{number % 100}"; }