Skip to content

Commit 8bfc96d

Browse files
committed
Fix possible _keys file loss during key rotation
There is no reason to do durable_unlink before durable_rename. Rename can handle existing file. But with this sequence, the cluster may endup in unrecoverable state should server crash in-between this two ops, as there is going to be no "_keys" at all. The current sequence may also cause an issue the backup: <durable_unlink>, <pg_basebackup gets a file list>, <durable_rename>. And no "_keys" file in the backup as the result.
1 parent 415cb8d commit 8bfc96d

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

contrib/pg_tde/src/access/pg_tde_tdemap.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,9 @@ pg_tde_perform_rotate_key(const TDEPrincipalKey *principal_key, const TDEPrincip
297297
CloseTransientFile(new_fd);
298298

299299
/*
300-
* Do the final steps - replace the current _map with the file with new
300+
* Do the final step - replace the current _map with the file with new
301301
* data
302302
*/
303-
durable_unlink(old_path, ERROR);
304303
durable_rename(new_path, old_path, ERROR);
305304

306305
/*

contrib/pg_tde/src/access/pg_tde_xlog_keys.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,10 +718,9 @@ pg_tde_perform_rotate_server_key(const TDEPrincipalKey *principal_key,
718718
CloseTransientFile(new_fd);
719719

720720
/*
721-
* Do the final steps - replace the current WAL key file with the file
721+
* Do the final step - replace the current WAL key file with the file
722722
* with new data.
723723
*/
724-
durable_unlink(get_wal_key_file_path(), ERROR);
725724
durable_rename(tmp_path, get_wal_key_file_path(), ERROR);
726725

727726
/*

0 commit comments

Comments
 (0)