Hi,

When the Postgres major version is updated, CI fails with [1]:

2026-07-02 17:01:01.938 UTC [828] FATAL:  incompatible library
"D:/a/postgresql/postgresql/build/tmp_install/usr/local/pgsql/lib/utf8_and_win.dll":
version mismatch
2026-07-02 17:01:01.938 UTC [828] DETAIL:  Server is version 20,
library is version 19.

This happens because the GitHub Actions ccache is restored across a
version bump, so objects built against the previous version can be
reused, producing libraries that no longer match the server version.

Here is an attempt to solve this problem by namespacing ccache by
Postgres major version. I added a 'PG_MAJOR_VERSION' variable to the
CI file and used that as a prefix to ccache key. I made this
'PG_MAJOR_VERSION' variable automatically updated by
'version_stamp.pl' script.

Another solution could be reading the version from build files (e.g
meson.build), but then this read needs to be done at each CI run.

[1] 
https://github.com/postgresql-cfbot/postgresql/actions/runs/28606913807/job/84829900634

-- 
Regards,
Nazir Bilal Yavuz
Microsoft
From d79d51ebf5fa30a20d76e2cb812abed5d684f571 Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <[email protected]>
Date: Fri, 3 Jul 2026 17:12:01 +0300
Subject: [PATCH v1] ci: namespace ccache by PostgreSQL major version

Add a PG_MAJOR_VERSION variable to the CI workflow and have
version_stamp.pl keep it in sync. The ccache cache keys include it, so
bumping the version starts from a fresh cache instead of reusing stale
objects from the previous major version.

Reported-by: Robert Haas <[email protected]>
---
 .github/workflows/pg-ci.yml | 15 +++++++++++----
 src/tools/version_stamp.pl  |  3 +++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/pg-ci.yml b/.github/workflows/pg-ci.yml
index 5bc5292d2a5..d1ef90ab3f6 100644
--- a/.github/workflows/pg-ci.yml
+++ b/.github/workflows/pg-ci.yml
@@ -136,6 +136,13 @@ env:
 
   ON_DEFAULT_BRANCH: ${{github.event.repository.default_branch == github.ref_name }}
 
+  # Used to namespace the ccache caches, so that a new major version starts
+  # from a fresh cache rather than reusing stale objects built against the
+  # previous major version.
+  #
+  # Don't set manually, it is automatically set by 'version_stamp.pl' script.
+  PG_MAJOR_VERSION: "20"
+
   # Note that we need to be careful to use a separator that can't be in branch
   # names, otherwise e.g. caches for 'master' might be restored on the
   # 'master-pending' branch.
@@ -306,8 +313,8 @@ jobs:
         uses: actions/cache/restore@v5
         with:
           path: ${{ env.CCACHE_DIR }}
-          key: ccache${{env.CACHE_PREFIX_DEFAULT}}${{env.CACHE_SUFFIX}}
-          restore-keys: ccache${{env.CACHE_PREFIX_DEFAULT}}
+          key: ccache:v${{env.PG_MAJOR_VERSION}}${{env.CACHE_PREFIX_DEFAULT}}${{env.CACHE_SUFFIX}}
+          restore-keys: ccache:v${{env.PG_MAJOR_VERSION}}${{env.CACHE_PREFIX_DEFAULT}}
 
       - &ccache_restore_branch_step
         name: "ccache: Restore for branch ${{ github.ref_name }}"
@@ -315,8 +322,8 @@ jobs:
         uses: actions/cache/restore@v5
         with:
           path: ${{ env.CCACHE_DIR }}
-          key: ccache${{env.CACHE_PREFIX_BRANCH}}${{env.CACHE_SUFFIX}}
-          restore-keys: ccache${{env.CACHE_PREFIX_BRANCH}}
+          key: ccache:v${{env.PG_MAJOR_VERSION}}${{env.CACHE_PREFIX_BRANCH}}${{env.CACHE_SUFFIX}}
+          restore-keys: ccache:v${{env.PG_MAJOR_VERSION}}${{env.CACHE_PREFIX_BRANCH}}
 
       - &linux_prepare_workspace_step
         name: Prepare workspace
diff --git a/src/tools/version_stamp.pl b/src/tools/version_stamp.pl
index 8f94e9e2886..c1891e34092 100755
--- a/src/tools/version_stamp.pl
+++ b/src/tools/version_stamp.pl
@@ -98,6 +98,9 @@ sed_file("configure.ac",
 sed_file("meson.build",
 	qq{-e "/^project(/,/^)/ s/ version: '[0-9a-z.]*',/ version: '$fullversion',/"}
 );
+sed_file(".github/workflows/pg-ci.yml",
+	"-e 's/^\\( *PG_MAJOR_VERSION: *\"\\)[0-9]*\"/\\1$majorversion\"/'"
+);
 
 print "Stamped these files with version number $fullversion:\n$fixedfiles";
 print "Don't forget to run autoconf $aconfver before committing.\n";
-- 
2.47.3

Reply via email to