Restoring the pg_dump from the postgres-s3-backups tool
cstoneham
PROOP

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

49 Replies

cstoneham
PROOP

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


2 years ago

what version of postgres are your backups made from?


cstoneham
PROOP

2 years ago

1219439909815713800


2 years ago

is your backup service running the latest commit?


btraut
PRO

2 years 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.


btraut
PRO

2 years ago

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


2 years ago

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


btraut
PRO

2 years 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.


2 years ago

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


btraut
PRO

2 years 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.


btraut
PRO

2 years ago

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


2 years ago

what is your version of pg_restore?


btraut
PRO

2 years 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.


2 years ago

does your app use anything timescale related?


btraut
PRO

2 years ago

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


2 years ago

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


btraut
PRO

2 years ago

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


2 years ago

how large are you database backup tarballs?


btraut
PRO

2 years ago

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


btraut
PRO

2 years ago

10gb 😬


2 years ago

what command have you ran to restore the backup?


btraut
PRO

2 years ago

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


2 years ago

are you both pro?


btraut
PRO

2 years 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
PRO

2 years ago

Looks like.

1219445480539558000


2 years ago

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


btraut
PRO

2 years ago

Gotchya gotchya.


2 years ago

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


2 years 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


2 years ago

the backup template makes tar.gz files


2 years ago

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


btraut
PRO

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


2 years 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
PRO

2 years 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;

2 years ago

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


btraut
PRO

2 years 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.


2 years 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
PRO

2 years ago

Yup. Running now.


btraut
PRO

2 years ago

Much appreciated!


btraut
PRO

2 years ago

Plausible that it's working.

1219778849391251500


2 years ago

thats very promising


btraut
PRO

2 years 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!


btraut
PRO

2 years 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.


2 years 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
PRO

2 years ago

Yeah, that's a great idea.


2 years ago

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


btraut
PRO

2 years ago

15.07gb


btraut
PRO

2 years ago

my backup tar was 10.69gb


2 years ago

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


Loading...