Actualizar Postgres con espacio realmente limitado

The documented procedure on the forums 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, @Falco suggested using the --link option to do the upgrade in-place using hard links. The docker container 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:

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

 

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

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.

1 me gusta

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 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?

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.

1 me gusta

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.

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.

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.

1 me gusta

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.

1 me gusta

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.

1 me gusta

Yup, as I originally suggested here Discourse on postgres 12 breaks upgrades - #8 by merefield

I’d just bite the bullet?

1 me gusta

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

¿Alguna vez lo actualizaste @Wingtip?

1 me gusta

Otra forma de resolver el problema de la actualización con espacio limitado es hacer una copia de seguridad, eliminar el directorio de postgres con rm -r, reconstruir y luego restaurar la copia de seguridad. Hice esto en un sitio la semana pasada.

2 Me gusta

¿No ocupará la copia de seguridad casi tanto espacio como la duplicación del directorio de datos (o incluso más, ya que también necesita comprimir)?

1 me gusta

No, nunca lo actualicé. Eliminar la base de datos y restaurar la copia de seguridad suena bastante arriesgado. Básicamente, necesitamos que la actualización in situ funcione.

Estamos ejecutando Ubuntu 18.04, que dejará de tener soporte en 2023, así que supongo que en ese momento no tendremos más remedio que migrar a un nuevo host de todos modos, y planeamos afrontar el problema entonces, montar un nuevo host con Ubuntu 22.04 LTS y restaurar desde la copia de seguridad.

Hmm. Podría ser un fracaso. Creo que con el modelo de respaldo, una de las copias está comprimida, ¿lo que podría marcar la diferencia? Y el sitio en el que lo hice tenía copias de seguridad en S3. Y era un sitio de prueba, por lo que las apuestas eran bajas si había algún problema.

Excepto que las copias de seguridad se usan mucho más a menudo en muchas más situaciones que la actualización in situ. Lo considero mucho más seguro.

1 me gusta

Quizás, pero no tengo mucha experiencia con postgres y no me siento cómodo haciéndolo. Restaurar todo el sitio desde una copia de seguridad en una VM completamente diferente, eso sí me siento cómodo haciéndolo, sin embargo, significaría perder publicaciones durante las horas que lleve restaurar, así que tampoco estoy muy entusiasmado con eso. Pero como 18.04 está dejando de recibir soporte, no tendré muchas opciones el próximo año.

1 me gusta

A menos que tu base de datos sea de decenas de gigabytes, no tardará horas. Y pondrás el foro en modo de solo lectura antes de hacer una copia de seguridad y restaurar, por lo que no perderás ninguna publicación. No es tan difícil de hacer con prácticamente ningún tiempo de inactividad, solo tiempo de solo lectura.

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

No lo pondría en modo de solo lectura, pondría un aviso diciendo a la gente que sus publicaciones de hoy son efímeras. Mejor dejar que hablen de ello aunque esas publicaciones se pierdan, en mi opinión.

1 me gusta

Para entonces, también tendrás acceso al chat integrado de Discourse, una función que se lanzará en la versión 2.9 (posiblemente desactivada por defecto, pero en beta y compatible para su uso).

3 Me gusta