awm
awm

Reputation: 2768

Artifactory upgrade fail, postgres 9.5 -> 9.6 upgrade instructions needed

I had planned an upgrade of artifactory from 6.7.5 to 6.8.1. As part of the upgrade I checked jfrog's repo on github and it looks like they have a new recommended nginx and postgres version.

The current docker-compose is using postgres 9.5 and the new default version if 9.6. Simply pulling down postgres 9.6 however does not do an inplace upgrade.

FATAL: database files are incompatible with server DETAIL: The data directory was initialized by PostgreSQL version 9.5, which is not compatible with this version 9.6.11.

The upgrade instructions do not mention anything about how to do the upgrade.

Upvotes: 1

Views: 564

Answers (2)

raspy
raspy

Reputation: 4261

I have been able to upgrade database using following approach:

  1. Dump all database to an SQL script using old database image; store it in a volume for future import:
# Override PostgreSQL image used to export using old binaries
printf "version: '2.1'\nservices:\n  postgresql:\n    image: docker.bintray.io/postgres:9.5.2\n" > image_override.yml
started_container=$(docker-compose -f artifactory-pro.yml -f image_override.yml run -d -v sql_dump_volume:/tmp/dump --no-deps postgresql)

# Dump database to a text file in a volume (to make it available for import)
docker exec "${started_container}" bash -c "until pg_isready -q; do sleep 1; done"
docker exec "${started_container}" bash -c "pg_dumpall --clean --if-exists --username=\${POSTGRES_USER} > /tmp/dump/dump.sql"
docker stop "${started_container}"
docker rm --force "${started_container}"
  1. Back up old database directory and prepare a new one:
mv -fv /data/postgresql /data/postgresql.old
mkdir -p /data/postgresql
chown --reference=/data/postgresql.old /data/postgresql
chmod --reference=/data/postgresql.old /data/postgresql
  1. Run a new database image with mounting dump script from step 1. It processes SQL scripts upon startup when setting up a new database, provided it's started as postgres something. We just don't need to leave the server running afterwards, so I provided --version to make entrypoint execute, import the data and quit:
docker-compose -f artifactory-pro.yml run --rm --no-deps -e POSTGRES_DB=postgres -e POSTGRES_USER=root -v sql_dump_volume:/docker-entrypoint-initdb.d postgresql postgres --version

After all this is done, I was able to start Artifactory normally with docker-compose -f artifactory-pro.yml up -d and it started up normally, applying rest of schema and file upgrade procedure as usual.

I have also prepared a script that basically does the above steps along with some additional checks and cleanup. Feel free to use if you find it useful.

Upvotes: 0

Mohammad Tibi
Mohammad Tibi

Reputation: 229

The examples provided in github (https://github.com/jfrog/artifactory-docker-examples) are just examples. Using them in production could cause issues and backwards compatibility is not guaranteed.

To get over the PostgreSQL matter when upgrading, I would suggest:

  1. $ docker-compose -f yml-file-name.yml stop
  2. edit the yml-file-name.yml and change the docker.bintray.io/postgres:9.6.11 to docker.bintray.io/postgres:9.5.2
  3. $ docker-compose -f yml-file-name.yml up -d

Artifactory should be upgraded after following this, however it will keep using the previous version of the PostgreSQL DB

Upvotes: 1

Related Questions