vw_james encountered a failed Discourse upgrade due to a UniqueViolation error during migration, specifically a duplicate username constraint. Attempts to access PostgreSQL via psql failed, indicating the database service was down. merefield guided vw_james through troubleshooting: restarting the container, checking service status, and confirming PostgreSQL wasn’t running. Logs revealed a version mismatch — data initialized by PostgreSQL 13 was incompatible with the installed version 12.3. merefield suggested renaming data directories outside the container: swapping postgres_data_old to postgres_data and postgres_data to postgres_data_new, then restarting PostgreSQL inside the container. This restored the site with the old data. Jos, replying on behalf of vw_james, confirmed the fix worked. merefield noted the file rename could also be done inside the container since the path is mounted. The issue stemmed from an incomplete PostgreSQL 13 upgrade, and further steps will be needed for a clean upgrade later.
I tried to upgrade discourse and got the following message -
I, [2021-01-21T18:39:25.045454 #1] INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate'
2021-01-21 18:39:32.724 UTC [4051] discourse@discourse LOG: duration: 336.116 ms statement: UPDATE users
SET locale = 'en_GB'
WHERE locale = 'en'
2021-01-21 18:39:33.373 UTC [4051] discourse@discourse ERROR: duplicate key value violates unique constraint "index_users_on_username_lower"
2021-01-21 18:39:33.373 UTC [4051] discourse@discourse DETAIL: Key (username_lower)=(xyz123) already exists.
2021-01-21 18:39:33.373 UTC [4051] discourse@discourse STATEMENT: UPDATE users
SET locale = 'en'
WHERE locale = 'en_US'
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
I tried to do ./launcher enter app and su postgres -c 'psql discourse', got the following error -
psql: error: could not connect to server: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432”?
root@ip–app:/var/www/discourse# cat /var/log/postgresql/postgresql-12-main.log
2021-01-21 18:12:04.965 UTC [623] FATAL: database files are incompatible with server
2021-01-21 18:12:04.965 UTC [623] DETAIL: The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 12.3 (Debian 12.3-1.pgdg100+1).
pg_ctl: could not start server
Examine the log output.