Backstory: I had a debian 11 VPS. I installed the postgresql program from the debian 11 apt repo, back a few months ago. Back then, it was postgres 13 on the debian stable repos.
Fast forward couple months: debian 12 comes out. I do a “apt dist-upgrade” and in-place upgrade my VPS from debian 11 to debian 12. Along with this upgrade, comes postgresql 15 installed.
Now, fast forward couple more months: lemmy 0.18.3 comes out. I do not upgrade (I am on lemmy 0.18.2—afaik).
Fast forward some time, too: lemmy 0.18.4 comes out. I decide to upgrade to 0.18.4 from my existing 0.18.2.
I pull the git repo. Compile it locally. It goes well, no errors in the compilation process. I stop the lemmy systemd service, then I “mv” the compiled “lemmy_server” to /usr/bin dir.
I try to restart the now-upgraded lemmy systemd service. However, the systemd service fails.
I check the sudo journalctl -fu lemmy
and I see the following error message:
lemmy_server[17631]: thread 'main' panicked at 'Couldn't run DB Migrations: Failed to run 2023-07-08-101154_fix_soft_delete_aggregates with: syntax error at or near "trigger"', crates/db_schema/src/utils.rs:221:25
I report this issue here: https://github.com/LemmyNet/lemmy/issues/3756#issuecomment-1686439103
However, after a few back and forths and internet search, I conclude that somewhere between lemmy 0.18.3 and 0.18.4, lemmy stops supporting psql <15. So, my existing DB is not compatible.
Upon my investigation on my VPS setup, I concluded that psql 15 is running, however, lemmy is using the psql 13 tables (I do not know if this is the correct term).
Now my question: is there a way to import the lemmy data I had in the psql 13 tables to a new psql 15 table (or database, I don’t know the term).
To make things hairier: I also run a dendrite server on the same VPS, and the dendrite server is using the psql 15 with psql 13 tables on the same database as the lemmy one.
The dendrite database is controlled by a psql user named “dendrite” and the lemmy database is controlled by a psql user named “lemmy” . I hope this makes differentiation between two databases possible. And so I do not harm my existing dendrite database.
Any recommendations about my options here?
ok, so you have a choice… we have to figure out the syntax of the port number in config file, or you introduce a LEMMY_DATABASE_URL in your lemmy.service file.
I would go with introducing LEMMY_DATABASE_URL in my lemmy.service file. However, is doing that going to expose my lemmy database password to the lemmy.service file?
yes, the password will need to be in the LEMMY_DATABASE_URL… but a lemmy.service should be secure… ? I mean it’s kind of thing the system using during boot.
yeah it is secure, as the root user password is required to do anything with that file. Alright, let’s do this.
So the next step is the backup, did you do the backup of lemmy data from 13? And spot-check that it looks like your data?
it’s plain text, I suggest grep against it for something you know is in there… that you created? Just to be sure when we do a restore against port 5433 we aren’t overwriting good data ;)
I grepped the exported sql file. I identified a long blog post of mine. So others should be there, too.
Ok, so now we restore to 15… double-check we have the port right for this…
Ok, so there is one issue we might run into. the lemmy user probably doesn’t exist on the PostgreSQL 15.3 install - so try these from the from-scratch install documentation:
Then to do the restore:
sudo -iu postgres /usr/lib/postgresql/15/bin/psql --port=5433 --file lemmy_databackup.sql
The restore may end up creating the lemmy user and a password for it, I’m not sure… so if you used different passwords for 13 and 15 it might have gone back to the 13 password for that user. Haven’t tested.