{"id":13451462,"url":"https://github.com/tianon/docker-postgres-upgrade","last_synced_at":"2025-05-14T19:05:48.138Z","repository":{"id":44546302,"uuid":"59611649","full_name":"tianon/docker-postgres-upgrade","owner":"tianon","description":"a PoC for using \"pg_upgrade\" inside Docker -- learn from it, adapt it for your needs; don't expect it to work as-is!","archived":false,"fork":false,"pushed_at":"2025-02-22T17:38:28.000Z","size":153,"stargazers_count":1173,"open_issues_count":17,"forks_count":118,"subscribers_count":32,"default_branch":"master","last_synced_at":"2025-04-13T13:19:20.408Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://hub.docker.com/r/tianon/postgres-upgrade/","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tianon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-24T22:01:03.000Z","updated_at":"2025-04-11T17:08:10.000Z","dependencies_parsed_at":"2024-01-29T06:14:29.000Z","dependency_job_id":"677487f0-8d6e-424c-a68f-de3803a31733","html_url":"https://github.com/tianon/docker-postgres-upgrade","commit_stats":{"total_commits":95,"total_committers":9,"mean_commits":"10.555555555555555","dds":"0.11578947368421055","last_synced_commit":"90e1aff3859c27e692aaf7cfb63cb2e6ac944868"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tianon%2Fdocker-postgres-upgrade","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tianon%2Fdocker-postgres-upgrade/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tianon%2Fdocker-postgres-upgrade/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tianon%2Fdocker-postgres-upgrade/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tianon","download_url":"https://codeload.github.com/tianon/docker-postgres-upgrade/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717284,"owners_count":21150400,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T07:00:54.212Z","updated_at":"2025-04-13T13:19:26.622Z","avatar_url":"https://github.com/tianon.png","language":"Shell","funding_links":[],"categories":["Dockerfile","Shell","others"],"sub_categories":[],"readme":"# `pg_upgrade`, Docker style\n\nThis is a PoC for using `pg_upgrade` inside Docker -- learn from it, adapt it for your needs; don't expect it to work as-is!\n\n(Source for this image is available at [https://github.com/tianon/docker-postgres-upgrade](https://github.com/tianon/docker-postgres-upgrade).)\n\nTags of this image are of the format `OLD-to-NEW`, where `OLD` represents the version of PostgreSQL you are _currently_ running, and `NEW` represents the version of PostgreSQL you would like to upgrade to.\n\nIn order to get good performance, it is recommended to run this image with `docker run image --link` (see [`pg_upgrade` documentation](https://www.postgresql.org/docs/9.5/static/pgupgrade.html) for more details).\n\nFor this to be feasible, your directory structure should look something like this: (if yours does not, either adjust it, or scroll down to see the alternate pattern for running this image)\n\n```console\n$ find DIR -mindepth 2 -maxdepth 2\nDIR/OLD/data\nDIR/NEW/data\n\n$ docker run --rm \\\n\t-v DIR:/var/lib/postgresql \\\n\ttianon/postgres-upgrade:OLD-to-NEW \\\n\t--link\n\n...\n```\n\nMore concretely, assuming `OLD` of `9.4`, `NEW` of `9.5`, and `DIR` of `/mnt/bigdrive/postgresql`:\n\n```console\n$ find /mnt/bigdrive/postgresql -mindepth 2 -maxdepth 2\n/mnt/bigdrive/postgresql/9.4/data\n/mnt/bigdrive/postgresql/9.5/data\n\n$ docker run --rm \\\n\t-v /mnt/bigdrive/postgresql:/var/lib/postgresql \\\n\ttianon/postgres-upgrade:9.4-to-9.5 \\\n\t--link\n\n...\n```\n\n(which assumes that your previous `postgres:9.4` instance was running with `-v /mnt/bigdrive/postgresql/9.4/data:/var/lib/postgresql/data`, and your new `postgres:9.5` instance will run with `-v /mnt/bigdrive/postgresql/9.5/data:/var/lib/postgresql/data`)\n\n---\n\nIf your two directories (denoted below as `PGDATAOLD` and `PGDATANEW`) do not follow this structure, then the following may also be used (but will be slower):\n\n```console\n$ docker run --rm \\\n\t-v PGDATAOLD:/var/lib/postgresql/OLD/data \\\n\t-v PGDATANEW:/var/lib/postgresql/NEW/data \\\n\ttianon/postgres-upgrade:OLD-to-NEW\n\n...\n```\n\nMore concretely, assuming `OLD` of `9.4`, `NEW` of `9.5`, `PGDATAOLD` of `/mnt/bigdrive/postgresql-9.4`, and `PGDATANEW` of `/mnt/bigdrive/postgresql-9.5`:\n\n```console\n$ docker run --rm \\\n\t-v /mnt/bigdrive/postgresql-9.4:/var/lib/postgresql/9.4/data \\\n\t-v /mnt/bigdrive/postgresql-9.5:/var/lib/postgresql/9.5/data \\\n\ttianon/postgres-upgrade:9.4-to-9.5\n\n...\n```\n\n(which assumes that your previous `postgres:9.4` instance was running with `-v /mnt/bigdrive/postgresql-9.4:/var/lib/postgresql/data`, and your new `postgres:9.5` instance will run with `-v /mnt/bigdrive/postgresql-9.5:/var/lib/postgresql/data`)\n\n---\n\nPutting it all together:\n\n```console\n$ mkdir -p postgres-upgrade-testing\n$ cd postgres-upgrade-testing\n$ OLD='9.4'\n$ NEW='9.5'\n\n$ docker pull \"postgres:$OLD\"\n$ docker run -dit \\\n\t--name postgres-upgrade-testing \\\n\t-e POSTGRES_PASSWORD=password \\\n\t-v \"$PWD/$OLD/data\":/var/lib/postgresql/data \\\n\t\"postgres:$OLD\"\n$ sleep 5\n$ docker logs --tail 100 postgres-upgrade-testing\n\n$ # let's get some testing data in there\n$ docker exec -it \\\n\t-u postgres \\\n\tpostgres-upgrade-testing \\\n\tpgbench -i -s 10\n\n$ docker stop postgres-upgrade-testing\n$ docker rm postgres-upgrade-testing\n\n$ docker run --rm \\\n\t-v \"$PWD\":/var/lib/postgresql \\\n\t\"tianon/postgres-upgrade:$OLD-to-$NEW\" \\\n\t--link\n\n$ docker pull \"postgres:$NEW\"\n$ docker run -dit \\\n\t--name postgres-upgrade-testing \\\n\t-e POSTGRES_PASSWORD=password \\\n\t-v \"$PWD/$NEW/data\":/var/lib/postgresql/data \\\n\t\"postgres:$NEW\"\n$ sleep 5\n$ docker logs --tail 100 postgres-upgrade-testing\n\n$ # can now safely remove \"$OLD\"\n$ sudo rm -rf \"$OLD\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftianon%2Fdocker-postgres-upgrade","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftianon%2Fdocker-postgres-upgrade","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftianon%2Fdocker-postgres-upgrade/lists"}