R
Railway•3mo ago
cstoneham

Restoring the pg_dump from the postgres-s3-backups tool

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?
GitHub
GitHub - railwayapp-templates/postgres-s3-backups: A simple Node ap...
A simple Node app to automatically backup PostgreSQL databases to an S3 bucket - railwayapp-templates/postgres-s3-backups
Solution:
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 - ignore errors and wait...
Jump to solution
46 Replies
Percy
Percy•3mo ago
Project ID: N/A
cstoneham
cstoneham•3mo 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?
Brody
Brody•3mo ago
what version of postgres are your backups made from?
cstoneham
cstoneham•3mo ago
No description
Brody
Brody•3mo ago
is your backup service running the latest commit?
btraut
btraut•3mo 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. btw, project id is b08731c2-2a20-4ba4-b7b2-a97b42af589f
Brody
Brody•3mo ago
the backup service that made these backups, just trying to gather information so i can give you the best answer i can
btraut
btraut•3mo 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.
Brody
Brody•3mo ago
okay thanks, what is the source image of the database you are trying to restore to?
btraut
btraut•3mo 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. I also tried installing timescaledb and timescaledb-toolkit locally via homebrew, but there's version issues between postgres 15 & 16
Brody
Brody•3mo ago
what is your version of pg_restore?
btraut
btraut•3mo 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.
Brody
Brody•3mo ago
does your app use anything timescale related?
btraut
btraut•3mo ago
To my knowledge, not at all. But it seems all of our pg_dumps have the timescale context baked into them.
Brody
Brody•3mo ago
they would, but since you dont need anything timescale related you can ignore any such errors
btraut
btraut•3mo ago
Hmm. But I end up with 0 records. The schema is restored, but no rows.
Brody
Brody•3mo ago
how large are you database backup tarballs?
btraut
btraut•3mo ago
tbh, I don't even know what timescale is. We use a pretty barebones postgres setup. 10gb 😬
Brody
Brody•3mo ago
what command have you ran to restore the backup?
btraut
btraut•3mo ago
pg_restore -d "postgresql://username:password@localhost:5432/postgres" -F t backup-2024-03-13T06-45-00-104Z.tar
Brody
Brody•3mo ago
are you both pro?
btraut
btraut•3mo 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.
btraut
btraut•3mo ago
Looks like.
No description
Brody
Brody•3mo ago
just asking so i know that you arent trying to restore a 10gb dump to a 5gb database haha
btraut
btraut•3mo ago
Gotchya gotchya.
Brody
Brody•3mo ago
look like i have a small backup laying around, ill try some commands to see what works
Solution
Brody
Brody•3mo 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 - ignore errors and wait
Attacler/Bart
Attacler/Bart•3mo ago
do you have a tar or tar.gz? otherwise you might need to extract it and put it into a folder and use that folder in the restore command
Brody
Brody•3mo ago
the backup template makes tar.gz files
Brody
Brody•3mo ago
you where able to restore a what 40gb backup? and theirs is only 10gb
btraut
btraut•3mo 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?
Brody
Brody•3mo ago
What version of pg_restore are you using
pg_restore (PostgreSQL) 16.0
are you restoring to another database hosted on Railway?
yes
btraut
btraut•3mo 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;
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;
Brody
Brody•3mo ago
does it stop itself, or have you been stopping it thinking its not doing anything?
btraut
btraut•3mo 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.
Brody
Brody•3mo 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?
btraut
btraut•3mo ago
Yup. Running now. Much appreciated!
btraut
btraut•3mo ago
Plausible that it's working.
No description
Brody
Brody•3mo ago
thats very promising
btraut
btraut•3mo 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! 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.
Brody
Brody•3mo 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
btraut
btraut•3mo ago
Yeah, that's a great idea.
Brody
Brody•3mo ago
just curious what was the final in use size of the volume?
btraut
btraut•3mo ago
15.07gb my backup tar was 10.69gb
Brody
Brody•3mo ago
that's checks out, glad you where able to get this sorted!
Want results from more Discord servers?
Add your server
More Posts