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?

  • RoundSparrow@lemmy.mlM
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    1 year ago

    So I mentioned in the other comment about being sure you fully path your binaries…

    This assumes your lemmy_server is shut down, it won’t start… so make sure the service isn’t trying to auto-restart or anything.

    /usr/lib/postgresql/15/bin/pg_dumpall is the command we want to run to do a backup from 13.

    sudo -iu postgres /usr/lib/postgresql/15/bin/pg_dumpall --port=5432 > /someplace_with_space/lemmy_databackup.sql

    This assumes we verify 5432 is your PostgreSQL 13 port… and Lemmy 0.18.2 data is there.

    EDIT: wait a minute, I’m editing this comment right now

    Re-thinking, you have two databases for two different apps intermingled, so we don’t want pg_dumpall - as it will give you both.

    sudo -iu postgres /usr/lib/postgresql/15/bin/pg_dump --port=5432 lemmy > /someplace_with_space/lemmy_databackup.sql

    That will give us just lemmy database. Let me know if you get a backup. I suggest you spot=check it and see if it has your recent data in it. Maybe grep the file for something you know you recently posted.

    • Anark Karabey@monero.townOP
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      This assumes we verify 5432 is your PostgreSQL 13 port

      Can we double check this now? I can run some netstat commands.

      sudo -iu postgres /usr/lib/postgresql/15/bin/pg_dump --port=5432 lemmy > /someplace_with_space/lemmy_databackup.sql
      

      The “lemmy” part in this command specifies only the “lemmy” psql user’s data, am I right?

      • RoundSparrow@lemmy.mlM
        link
        fedilink
        arrow-up
        2
        ·
        edit-2
        1 year ago

        The “lemmy” part in this command specifies only the “lemmy” psql user’s data, am I right?

        Yes and no. That isn’t the username, that’s the ‘database’ name. I suggest you spot-check the output file and see if it has your recent data in it. Maybe grep the file for something you know you recently posted.

        • Anark Karabey@monero.townOP
          link
          fedilink
          English
          arrow-up
          2
          ·
          1 year ago

          Before I do the pg_dump, here’s the output of netstat:

          $ sudo netstat -plnt | grep postgres
          tcp        0      0 127.0.0.1:5433          0.0.0.0:*               LISTEN      730/postgres
          tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      735/postgres
          tcp6       0      0 ::1:5433                :::*                    LISTEN      730/postgres
          tcp6       0      0 ::1:5432                :::*                    LISTEN      735/postgres
          

          How can we further verify that the port 5432 is the running psql 15?

          • RoundSparrow@lemmy.mlM
            link
            fedilink
            arrow-up
            1
            ·
            1 year ago

            sudo -iu postgres /usr/lib/postgresql/15/bin/psql --port=5432 --command='select version();'

            Will tell us 5432… and run again with --port=5433

            The version 15 binary should be OK to talk to version 13 back-end AFAIK.

            • Anark Karabey@monero.townOP
              link
              fedilink
              arrow-up
              2
              ·
              1 year ago
              $ sudo -iu postgres /usr/lib/postgresql/15/bin/psql --port=5432 --command='select version();'
                                                                         version
              -----------------------------------------------------------------------------------------------------------------------------
               PostgreSQL 13.11 (Debian 13.11-0+deb11u1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
              (1 row)
              
              ```
              
              Does this output mean that the binary 15 is talking to the 13 backend?
                • Anark Karabey@monero.townOP
                  link
                  fedilink
                  arrow-up
                  2
                  ·
                  1 year ago
                  $ sudo -iu postgres /usr/lib/postgresql/15/bin/psql --port=5433 --command='select version();'
                                                                        version
                  -------------------------------------------------------------------------------------------------------------------
                   PostgreSQL 15.3 (Debian 15.3-0+deb12u1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
                  (1 row)
                  
      • RoundSparrow@lemmy.mlM
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        Can we double check this now? I can run some netstat commands.

        sudo -iu postgres /usr/lib/postgresql/15/bin/psql --port=5432 --command='select version();'