From 1fa786fa2924468a15567d1bfd127afdb269f7a9 Mon Sep 17 00:00:00 2001 From: Andrew Pogrebnoy Date: Tue, 15 Apr 2025 10:53:59 +0300 Subject: [PATCH] Don't rewrite _map files on the save_principal_key redo We create a new WAL key during the extension init, which happens before the redo. This means that in case of a crash, pg_tde_save_principal_key_redo was rewriting a WAL _map file and destroying a newly created key. Since we emit an XLog record after the key was successfully written to the file (the file was created), we can safely assume that we should not change the file if it exists. --- contrib/pg_tde/src/access/pg_tde_tdemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/pg_tde/src/access/pg_tde_tdemap.c b/contrib/pg_tde/src/access/pg_tde_tdemap.c index 715c9a8d1ea..7994b5cfaf1 100644 --- a/contrib/pg_tde/src/access/pg_tde_tdemap.c +++ b/contrib/pg_tde/src/access/pg_tde_tdemap.c @@ -309,7 +309,7 @@ pg_tde_save_principal_key_redo(const TDESignedPrincipalKeyInfo *signed_key_info) LWLockAcquire(tde_lwlock_enc_keys(), LW_EXCLUSIVE); - map_fd = pg_tde_open_file_write(db_map_path, signed_key_info, true, &curr_pos); + map_fd = pg_tde_open_file_write(db_map_path, signed_key_info, false, &curr_pos); close(map_fd); LWLockRelease(tde_lwlock_enc_keys());