# Infinite loop during postgres upgrade

**URL:** <https://meta.discourse.org/t/infinite-loop-during-postgres-upgrade/91767>\
**Category:** Self-hosting\
**Created:** [July 7, 2018, 10:39am UTC](https://meta.discourse.org/t/infinite-loop-during-postgres-upgrade/91767 "2018-07-07T10:39:33Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![lavamind](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lavamind/32/237909_2.png) [@lavamind](https://meta.discourse.org/u/lavamind)\
**Post date:** [July 30, 2025, 3:16pm UTC](https://meta.discourse.org/t/infinite-loop-during-postgres-upgrade/91767/8 "2025-07-30T15:16:13Z")

</div>

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:

```plaintext
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.

---

_[View the full topic](https://meta.discourse.org/t/infinite-loop-during-postgres-upgrade/91767)._
