# Upgrade Postgres with REALLY limited space

**URL:** https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937
**Category:** Self-hosting
**Tags:** server-resources
**Created:** [August 27, 2021, 5:42pm UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937 "2021-08-27T17:42:10Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![Wingtip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wingtip/32/102039_2.png) [@Wingtip](https://meta.discourse.org/u/Wingtip)
#### Post date: [August 27, 2021, 5:42pm UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/1 "2021-08-27T17:42:11Z")

</div>

The [documented procedure on the forums](https://meta.discourse.org/t/postgresql-13-update/172563) lists two methods of upgrading Postgres.

1. Just let Discourse handle it. This requires _3 times_ the disk space. So if your DB is 100GB, you would need an additional 200GB _free_ to do the upgrade. Obviously a huge problem for people with large installs.
2. Follow their “manual update” procedure. This requires _2 times_ the disk space, so if your DB is 100GB you would need an additional 100GB free. This is also a big problem for some.

In [this post](https://meta.discourse.org/t/discourse-on-postgres-12-breaks-upgrades/201814/15), @Falco suggested using the `--link` option to do the upgrade in-place using hard links. The [docker container](https://github.com/tianon/docker-postgres-upgrade) they suggest using supports that argument, but Discourse devs don’t suggest using it in the post.

So my question is this, should option 3 be:

1. Run the command below, which will require a _very small_ amount of additional disk space. So if your DB is 100GB, it might require, say, an additional 10GB? And if so, is this a recommended procedure by the Discourse devs, and has anyone actually done it before and lived to tell the tale?

**New** command to upgrade in-place:

```plaintext
docker run --rm \
	-v DIR:/var/discourse/shared/standalone/postgres_data:/var/lib/postgresql \
	tianon/postgres-upgrade:12-to-13 \
	--link

```

&nbsp;

Compared to the **old** command to upgrade into a new directory (requiring double the space):

```plaintext
docker run --rm \
	-v /var/discourse/shared/standalone/postgres_data:/var/lib/postgresql/12/data \
	-v /var/discourse/shared/standalone/postgres_data_new:/var/lib/postgresql/13/data \
	tianon/postgres-upgrade:12-to-13

```

P.S.: I would have just replied to that PG13 upgrade thread, but it deletes posts after 7 days. Why do you have it configured that way? I know there was a lot of discussion when this first came up that would have been useful for reference.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [August 27, 2021, 7:12pm UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/2 "2021-08-27T19:12:25Z")

</div>

> [@Wingtip](#):
>
> Run the command below, which will require a _very small_ amount of additional disk space. So if your DB is 100GB, it might require, say, an additional 10GB? And if so, is this a recommended procedure by the Discourse devs, and has anyone actually done it before and lived to tell the tale?

If they have, they didn’t mention it here. Mostly instrucions here try to be as foolproof as possible and require as little system adminstration knowledge as possible. Most people here woud rather do something the safest, most tested way possible than some way designed to save a very few dollars.

If it works for you, you can update [PostgreSQL 13 update](https://meta.discourse.org/t/postgresql-13-update/172563) accordingly, but before you do, do you feel comfortable recommending to someone who doesn’t know what bash is that they do it that way? You’re sure that it won’t hose their database and their site will be ruined forever?

> [@Wingtip](#):
>
> I would have just replied to that PG13 upgrade thread, but it deletes posts after 7 days. Why do you have it configured that way? I know there was a lot of discussion when this first came up that would have been useful for reference.

The idea is that if some other good information is presented that it be added to the OP rather than asking people to read through year’s worth of posts that are likely to be unhelpful or wrong.

---

<div class="post-metadata">

### Author: ![Wingtip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wingtip/32/102039_2.png) [@Wingtip](https://meta.discourse.org/u/Wingtip)
#### Post date: [August 28, 2021, 11:45am UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/3 "2021-08-28T11:45:57Z")

</div>

No I’m not sure, I don’t have much experience with postgres and was hoping one of the discourse devs could provide some assurances it would work.

Even if it _does_ work I also wouldn’t recommend it as the default upgrade procedure as the old way keeps a separate copy of the DB for rollback. If it works it would be a great option for space-constrained environments though.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [August 28, 2021, 1:04pm UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/4 "2021-08-28T13:04:30Z")

</div>

Another easy way is to spin up a new server, migrate the data, and turn off the old one. If you must use the old one, do the upgrade on a temporary server, so a fresh install on the original server (which probably needs an OS upgrade) and move it back.

That’s safe, easy, and well documented. Hundreds of people have done that.

---

<div class="post-metadata">

### Author: ![Wingtip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wingtip/32/102039_2.png) [@Wingtip](https://meta.discourse.org/u/Wingtip)
#### Post date: [August 28, 2021, 1:21pm UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/5 "2021-08-28T13:21:39Z")

</div>

Yes, but that would take a day or two. During that time we could either a) tell users their posts during this period will be lost or b) set the forum read-only. Neither is a great solution.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [August 29, 2021, 12:07pm UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/6 "2021-08-29T12:07:01Z")

</div>

I don’t think that the server would be down a whole lot longer than during the rebuild. And if you move to the new server and stay there, you can leave the old server in read only mode while you make the move. If downtime is your concern then moving to a new server will be much, much better.

---

<div class="post-metadata">

### Author: ![Wingtip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wingtip/32/102039_2.png) [@Wingtip](https://meta.discourse.org/u/Wingtip)
#### Post date: [August 29, 2021, 1:30pm UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/7 "2021-08-29T13:30:04Z")

</div>

We have a pretty big forum, but I’ve never tried restoring a backup so I don’t know how long it would take. We would indeed stay on the new host if we did it. I would like to avoid that due to the extra work/annoyance if possible.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [August 30, 2021, 6:29am UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/8 "2021-08-30T06:29:03Z")

</div>

> [@pfaffman](#):
>
> Another easy way is to spin up a new server, migrate the data, and turn off the old one

Yup, as I originally suggested here [Discourse on postgres 12 breaks upgrades - #8 by merefield](https://meta.discourse.org/t/discourse-on-postgres-12-breaks-upgrades/201814/8)

I’d just bite the bullet?

---

<div class="post-metadata">

### Author: ![Wingtip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wingtip/32/102039_2.png) [@Wingtip](https://meta.discourse.org/u/Wingtip)
#### Post date: [August 30, 2021, 11:47am UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/9 "2021-08-30T11:47:25Z")

</div>

All my posts here have been in an ongoing attempt to avoid doing that.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [February 13, 2022, 2:05am UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/10 "2022-02-13T02:05:06Z")

</div>

Did you ever get this upgraded @Wingtip?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 13, 2022, 11:36am UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/11 "2022-02-13T11:36:53Z")

</div>

Another way to solve the upgrade with limited space issue is to make a backup, `rm - r` the postgres directory, rebuild, and then restore the backup. I did this on a site last week.

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [February 13, 2022, 12:43pm UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/12 "2022-02-13T12:43:02Z")

</div>

Won’t the backup take up almost as much space as duplicating the data directory does (or even more since it needs to compress as well) ?

---

<div class="post-metadata">

### Author: ![Wingtip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wingtip/32/102039_2.png) [@Wingtip](https://meta.discourse.org/u/Wingtip)
#### Post date: [February 13, 2022, 3:40pm UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/13 "2022-02-13T15:40:27Z")

</div>

Nope, never got it upgraded. Deleting the DB and restoring the backup sounds pretty risky. We need the upgrade in-place to work, basically.

We’re running ubuntu 18.04 which hits desupport in 2023 so I figure at that point we’ll have no choice but to migrate to a new host anyway, and plan to bite the bullet then, build-out a new host running 22.04 LTS, and restore from backup.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 13, 2022, 8:24pm UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/14 "2022-02-13T20:24:52Z")

</div>

Hmm. Could be a wash. I think with the backup model one of the copies is compressed,which could make a difference? And the site that I did it on had backups on S3. And it was a test site so the stakes were low if there was a problem.

> [@Wingtip](#):
>
> Deleting the DB and restoring the backup sounds pretty risky.

Except backups are used lots more often in lots more situations than the upgrade in place. I consider it much safer.

---

<div class="post-metadata">

### Author: ![Wingtip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wingtip/32/102039_2.png) [@Wingtip](https://meta.discourse.org/u/Wingtip)
#### Post date: [February 13, 2022, 9:06pm UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/15 "2022-02-13T21:06:34Z")

</div>

Perhaps, but I don’t have a lot of expertise with postgres and don’t feel comfortable doing it. Restoring the whole site from backup on an entirely different VM, that I do feel comfortable doing, however it would mean losing posts for however many hours is takes to restore so I’m not super enthusiastic about that either. But since 18.04 is being desupported I won’t have much choice next year.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 13, 2022, 9:40pm UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/16 "2022-02-13T21:40:15Z")

</div>

> [@Wingtip](#):
>
> it would mean losing posts for however many hours is takes to restore

Unless your database is tens of gigabytes, it won’t take hours. And you’ll put the forum in read only mode before you backup and restore, so you won’t lose any posts. It’s not that hard to do with virtually no down time, just read only time.

---

<div class="post-metadata">

### Author: ![Wingtip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wingtip/32/102039_2.png) [@Wingtip](https://meta.discourse.org/u/Wingtip)
#### Post date: [February 13, 2022, 9:55pm UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/17 "2022-02-13T21:55:21Z")

</div>

```plaintext
root@forum-app:/shared/postgres_data# du -sh
97G .

```

I wouldn’t put it in read-only, I would put up a banner telling people their posts today are ephemeral. Better to let them chat about it even if those posts would be lost, in my view.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [February 21, 2022, 4:12am UTC](https://meta.discourse.org/t/upgrade-postgres-with-really-limited-space/201937/18 "2022-02-21T04:12:25Z")

</div>

By then you will have access to built-in Discourse chat as well, that’s a feature which will ship in 2.9 (possibly default off, but in beta and supported for use).
