I hit this problem during the latest upgrade from PotsgreSQL 13 to 15.
In our deployment, our/shared/postgres_data
directory is mounted on a faster NVMe storage device, so moving it failed with a Device or resource busy
error message.
We fixed this by patching the postgres template as such:
diff --git a/templates/postgres.template.yml b/templates/postgres.template.yml
index c24bfe6..03813c4 100644
--- a/templates/postgres.template.yml
+++ b/templates/postgres.template.yml
@@ -139,8 +139,10 @@ run:
exit 1
fi
- mv /shared/postgres_data /shared/postgres_data_old
- mv /shared/postgres_data_new /shared/postgres_data
+ mkdir /shared/postgres_data_old
+ mv /shared/postgres_data/* /shared/postgres_data_old
+ mv /shared/postgres_data_new/* /shared/postgres_data
+ rmdir /shared/postgres_data_new
Instead of attempting to manipulate the directory itself, just move the contents around.
Please consider integrating this change to improve the reliability of database upgrades.