Restoring the pg_dump from the postgres-s3-backups tool

cstonehamPRO

a year ago

We have a bunch of database dumps via this tool: https://github.com/railwayapp-templates/postgres-s3-backups

We're trying to figure out how to actually get the restore to work, does anyone have detailed directions?

0 Replies

cstonehamPRO

a year ago

So the issue we're facing is that we're not sure which pg_restore tool to use. If it's a local postgres installed via homebrew, I'm having a hard time getting timescale and timescale-toolkit installed. Should I be doing this inside of a dockerized postgres/timescale container? Or is there a way to restore directly to a railway instance?


a year ago

what version of postgres are your backups made from?


cstonehamPRO

a year ago

1219439909815713800


a year ago

is your backup service running the latest commit?


AnonymousTRIAL

a year ago

What do you mean by backup service? We're trying to use pg_restore either on a local machine (postgres installed via homebrew) or via a docker container. In any case, it looks like it needs timescaledb and timescaledb-toolkit installed to restore properly.


AnonymousTRIAL

a year ago

btw, project id is b08731c2-2a20-4ba4-b7b2-a97b42af589f


a year ago

the backup service that made these backups, just trying to gather information so i can give you the best answer i can


AnonymousTRIAL

a year ago

Ah, I see. We made the backups via an instance of https://github.com/railwayapp-templates/postgres-s3-backups with the latest commit. The postgres instance is also really up to date. I ran Railway's migration tool earlier this year to upgrade the postgres version and data store.


a year ago

okay thanks, what is the source image of the database you are trying to restore to?


AnonymousTRIAL

a year ago

Honestly, I've tried a whole bunch of options. I've tried another railway postgresql instance which presumably should be the same as the original data source. I've also tried restoring to a homebrew install of postresql@15 and postgresql@16 and a timescaledb docker image (https://hub.docker.com/layers/timescale/timescaledb/latest-pg16/images/sha256-d669a599ce935613c3e322fc56678b76762e53a9f8dac22a86a04c07cb0a4285?context=explore). In all cases, it seems I need both timescaledb and timescaledb-toolkit installed, and none of those destinations have it installed out of the box.


AnonymousTRIAL

a year ago

I also tried installing timescaledb and timescaledb-toolkit locally via homebrew, but there's version issues between postgres 15 & 16


a year ago

what is your version of pg_restore?


AnonymousTRIAL

a year ago

Depends on which. 🙂 With homebrew 15, it's 15.x and it was giving me an error about incompatible headers. When I installed homebrew's postgresql@16, I think it was pg_restore 16.2, but it might've been different.

The timescaledb docker image has pg_restore 16.2.


a year ago

does your app use anything timescale related?


AnonymousTRIAL

a year ago

To my knowledge, not at all. But it seems all of our pg_dumps have the timescale context baked into them.


a year ago

they would, but since you dont need anything timescale related you can ignore any such errors


AnonymousTRIAL

a year ago

Hmm. But I end up with 0 records. The schema is restored, but no rows.


a year ago

how large are you database backup tarballs?


AnonymousTRIAL

a year ago

tbh, I don't even know what timescale is. We use a pretty barebones postgres setup.


AnonymousTRIAL

a year ago

10gb 😬


a year ago

what command have you ran to restore the backup?


AnonymousTRIAL

a year ago

pg_restore -d "postgresql://username:password@localhost:5432/postgres" -F t backup-2024-03-13T06-45-00-104Z.tar


a year ago

are you both pro?


AnonymousTRIAL

a year ago

Is that a Railway thing? @cstoneham is the account creator, and I'm pretty sure it's a pro account. I'm his cofounder and an Owner on the account.


AnonymousTRIAL

a year ago

Looks like.

1219445480539558000


a year ago

just asking so i know that you arent trying to restore a 10gb dump to a 5gb database haha


AnonymousTRIAL

a year ago

Gotchya gotchya.


a year ago

look like i have a small backup laying around, ill try some commands to see what works


a year ago

this is what worked for me and my small backup -

  • un-gzip the tarball to end up with a backup_filename.tar file

  • run pg_restore --dbname=${DATABASE_URL} --format=tar < backup_filename.tar

  • wait


a year ago

the backup template makes tar.gz files


a year ago

you where able to restore a what 40gb backup? and theirs is only 10gb


AnonymousTRIAL

a year ago

This doesn't actually seem to work through the issues that I'm facing. What version of pg_restore are you using, and are you restoring to another database hosted on Railway?


a year ago

What version of pg_restore are you using
pg_restore (PostgreSQL) 16.0

are you restoring to another database hosted on Railway?
yes


AnonymousTRIAL

a year ago

I'm trying this right now. I'm getting pages and pages of this vomit, but maybe it'll work anyway?

pg_restore: error: could not execute query: ERROR:  schema "_timescaledb_cache" does not exist
Command was: COPY _timescaledb_cache.cache_inval_bgw_job  FROM stdin;
pg_restore: error: could not execute query: ERROR:  schema "_timescaledb_cache" does not exist
Command was: COPY _timescaledb_cache.cache_inval_extension  FROM stdin;
pg_restore: error: could not execute query: ERROR:  schema "_timescaledb_cache" does not exist
Command was: COPY _timescaledb_cache.cache_inval_hypertable  FROM stdin;

a year ago

does it stop itself, or have you been stopping it thinking its not doing anything?


AnonymousTRIAL

a year ago

I've been trying so many combinations of pg_restore versions and attempts to install timescale that I'm not 100% sure if I've done this test yet.


a year ago

10gb is a big backup, it took several seconds to restore my 108kb backup, i think you should just let it run, whats the worst that can happen?


AnonymousTRIAL

a year ago

Yup. Running now.


AnonymousTRIAL

a year ago

Much appreciated!


AnonymousTRIAL

a year ago

Plausible that it's working.

1219778849391251500


a year ago

thats very promising


AnonymousTRIAL

a year ago

Update here: it took quite a while on my current internet connection, but I was able to successfully restore the backup using your method!


AnonymousTRIAL

a year ago

For future readers:

I had to install pg_restore 16.x on my machine (I used homebrew's postgresql@16) and restore to another railway postgresql instance. I was never able to restore to a local db.


a year ago

awesome! maybe next time you need to restore a backup you could temporarily rent a VPS? that's why I would do since I only have 9mbps up


AnonymousTRIAL

a year ago

Yeah, that's a great idea.


a year ago

just curious what was the final in use size of the volume?


AnonymousTRIAL

a year ago

15.07gb


AnonymousTRIAL

a year ago

my backup tar was 10.69gb


a year ago

that's checks out, glad you where to get this sorted!