Fast snapshot and restoring for postgres [blog]

I’ve been using postgres a lot lately for projects, but when dealing with large dataset changes and testing, it’s not a quick process to reset the state to start again.
I stumbled upon stellar which appears to do exactly this job, but I had a couple of gotchas so figured I’d capture it here.


This content originally appeared on remy sharp's b:log and was authored by remy sharp's b:log

I've been using postgres a lot lately for projects, but when dealing with large dataset changes and testing, it's not a quick process to reset the state to start again.

I stumbled upon stellar which appears to do exactly this job, but I had a couple of gotchas so figured I'd capture it here.

Installing stellar

Start with the install which requires Python's pip tool:

pip install stellar

The next command should be the init command, but this failed to complete and notified me that I needed to install psycopg2, but pip install psycopg2 fails hard (for me) with large screens of errors.

The psycopg2 package needed to know where I was keeping postgres, so this fixed it (hat-tip to Nevelina A. on twitter):

$ PATH=$PATH:/Applications/Postgres.app/Contents/Versions/12/bin/
$ pip install psycopg2

Obviously make sure you're adding your own current version of postgres to the path (I happened to be on 12).

Once that was done the initialisation can run:

stellar init

I was prompted with some options and filled them out. Next is to actually snapshot - giving my snapshot the name of first (not the best of names I know):

stellar snapshot first

This also failed. Two more changes required:

In the stallar.yaml file that's been generated in the local directory, the url: postgresql:// property needed to add my username to access the database, so changing to the following fixed it for me:

url: postgresql://remy@localhost:5432/template1

Lastly I kept getting an error reading There is 1 other session using the database - this wasn't the case, and the fix was more installs, specifically the following:

pip install SQLAlchemy==1.2.5 SQLAlchemy-Utils==0.33.1

Once these last bits are in place, the snapshot completes.

To restore I can then run:

stellar restore first

And I'd strongly recommend visually confirming this works, but these were the only hoops I had to jump through and now going to the reset state is pretty fast and helping speed up my dev process.

Originally published on Remy Sharp's b:log


This content originally appeared on remy sharp's b:log and was authored by remy sharp's b:log


Print Share Comment Cite Upload Translate Updates
APA

remy sharp's b:log | Sciencx (2021-06-18T00:00:00+00:00) Fast snapshot and restoring for postgres [blog]. Retrieved from https://www.scien.cx/2021/06/18/fast-snapshot-and-restoring-for-postgres-blog/

MLA
" » Fast snapshot and restoring for postgres [blog]." remy sharp's b:log | Sciencx - Friday June 18, 2021, https://www.scien.cx/2021/06/18/fast-snapshot-and-restoring-for-postgres-blog/
HARVARD
remy sharp's b:log | Sciencx Friday June 18, 2021 » Fast snapshot and restoring for postgres [blog]., viewed ,<https://www.scien.cx/2021/06/18/fast-snapshot-and-restoring-for-postgres-blog/>
VANCOUVER
remy sharp's b:log | Sciencx - » Fast snapshot and restoring for postgres [blog]. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/18/fast-snapshot-and-restoring-for-postgres-blog/
CHICAGO
" » Fast snapshot and restoring for postgres [blog]." remy sharp's b:log | Sciencx - Accessed . https://www.scien.cx/2021/06/18/fast-snapshot-and-restoring-for-postgres-blog/
IEEE
" » Fast snapshot and restoring for postgres [blog]." remy sharp's b:log | Sciencx [Online]. Available: https://www.scien.cx/2021/06/18/fast-snapshot-and-restoring-for-postgres-blog/. [Accessed: ]
rf:citation
» Fast snapshot and restoring for postgres [blog] | remy sharp's b:log | Sciencx | https://www.scien.cx/2021/06/18/fast-snapshot-and-restoring-for-postgres-blog/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.