Postgres Transaction Isolation
About bugs you can avoid with the right transaction isolation level.
2021-11-25
A managed RDS is not exactly cheap. And I like my pet projects to be cheap. Thatโs how I ran into the problem of making scheduled backups of a Postgres DB. I canโt be the only one, so here is one way of solving it with a docker image.
Within the running container this happens:
pg_dump
creates a dumpaws-cli
uploads the dump to s3cron
schedules a job with the two steps above to run every x minutes/houres/etc.Pretty straight forward. But there is a catch.
The pg_dump
command may not work across Postgres versions. Meaning you would want the pg_dump
command to match the version of the Postgres database you pull a dump from.
Therefore building this image requires the build arg POSTGRES_IMAGE_TAG
.
Here is an example of how building the image could look like for Postgres v13.5:
docker build --build-arg "POSTGRES_IMAGE_TAG=13.5" -t pg_dump_s3 .
Internally it pulls the official Postgres image matching the provided tag. Here is a list of available tags for official Postgres images.
Note that this docker image does not work for all of them. E.g. *-alpine
images donโt work. But there is at least one that does for every major version from v9 to v14. Have a look at this list of tested tags.
See the README for detailed information on how to build the image and run the container.
Feel free to open PRs or issues ๐
More Posts