I’m having trouble finding documentation in any web searches on how to upgrade the database version being used. I have attempted to increase my postgresql version number in my docker-compose.yml, but it always breaks gitea. I’ve been successful testing upgrading gitea itself this way, but not with upgrading postgresql.
Postgres containers cannot be updated as easily as other containers. At least not if the major version changes. To update Postgres to a new major version, you must first make a dump of the DB, then start the new Postgres version and then import the dump of the old version. It is best to create a new volume for the new DB container. Then you still have the old one available as a backup / fallback solution.
This has less to do with Gitea. Gitea runs smoothly with the current Postgres version 16.
It appears to have worked to upgrade the postgresql version running, but after I login to my gitea instance the dashboard is empty and it was not before the upgrade. When I stop/start it again to use the older postgresql, there is no issue with the dashboard. Any ideas?
I had to make the following changes to get this working for gitea, as the above tool is expecting a specific directory structure for it to function correctly:
Had to create create ~/gitea/postgres/9.6/data and rsync ~/gitea/postgres/* to it and then make sure the permissions remained the same:
# chown -R systemd-coredump:systemd-coredump 9.6/
# chmod 700 9.6
# chmod 700 9.6/data
Then had to change docker-compose.yml from what it is to point to this new directory:
“- ./postgres/9.6/data:/var/lib/postgresql/data”
I then started the gitea and postgresql dockers to verify that they were still functioning with this new directory structure, which they were.
I then ran the tool to migrate psql 9.6 to 15. You can change the old and new postgresql versions in the command to whichever you are upgrading to & from.
Next modify the pg_hba.conf file for psql 15 with config I had in 9.6 as follows:
Commented out the last three config lines already in pg_hba.conf
Added the last line of the 9.6 config file to the 15 config file of host all all all md5
Then docker pull "postgres:15" to pull down the new postgresql docker version.
Then edit your docker-compose.yml as follows:
“image: postgres:9.6” becomes 15 instead of 9.6
“- ./postgres/9.6/data:/var/lib/postgresql/data” becomes 15 instead of 9.6
Now start it up and your gitea will be running the newer version (15) via docker. If it does not work for some reason, then troubleshoot accordingly by running the following: docker logs --tail 100 gitea_db_1
In a nutshell, you add a new service to your docker-compose file with the postgres image that you wanna migrate to and a new managed volume. Then you dump your tables from your old db and read them into the new db. You switch over to the new postgres by updating the postgres container’s hostname in your gitea configuration (.env) as well as other references. The docker-compose file looks like this: