Ad Widget

Collapse

Upgrading Zabbix Postgres Db within a PodMan Container

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sj200449
    Junior Member
    • Mar 2023
    • 13

    #1

    Upgrading Zabbix Postgres Db within a PodMan Container

    Hi,

    Does anyone have a method worked out for transferring and upgrading the version of Postgres used by a Zabbix system that is within a container?

    I have the following containers within a Pod

    docker.io/zabbix/zabbix-agent2:alpine-6.4-latest zabbix-agent
    docker.io/library/postgres:14-alpine zabbix-db
    docker.io/zabbix/zabbix-server-pgsql:alpine-6.4-latest zabbix-server
    docker.io/zabbix/zabbix-web-nginx-pgsql:alpine-6.4-latest zabbix-web

    I can stop the whole Pod and alter the quadlets for the zabbix images to be 7.4 for example then restart the Pod and its all fine.

    However for postgres , when I

    Have only the Postgres container running
    Take a pgdump with custom format of the zabbix database within the postgres container
    Transfer the resultant dump file to a new host with new containers [even with same version of image file]
    Stop new Pod and start only the Db container
    Do a pgrestore from transferred dump file

    It always complains of pre-existing items when trying to create the new database - even if I use --clean and --create on the pgrestore command

    I'm aware of the Postgres path changes in version 18 that effect the bound volume in Postgres container , but this is even going to the same version (14) in a pre-upgrade test.

    Im wondering if I actually need to delete the pg data directory so it doesn't think there is an already initialised db present.

    Anyway, I've tried various combinations of those 5 basic steps above and always find errors upon the restore bit - even with a psql run , or pgdumpall/pgrestoreall but pgdump/pgrestore with specific db seems to get further

    Sorry for the lack of specific commands and verbatim output - there was a lot of it and I thought I would ask the simple question first - does anyone have a tried method for moving from one container hosting server to another and subsequently an upgrade.

    Thanks for taking time to read.

    -Stephen.
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4991

    #2
    Originally posted by sj200449
    Im wondering if I actually need to delete the pg data directory so it doesn't think there is an already initialised db present.
    .
    I have never done it (and I keep away from containers as far as I can.. ) ... but first search on the topic say you ened to rename your data directory and create new one..
    https://helgeklein.com/blog/upgradin...ker-container/
    1. Stop the application container to prevent DB writes.
    2. Create a full DB dump.
    3. Stop the PostgreSQL container.
    4. Rename (backup) the old DB data directory and create a new empty one in its place.
    5. Increment the PostgreSQL version number in your Docker compose file and pull the new image.
    6. Start the updated PostgreSQL container.
    7. Import the DB dump.
    8. Start the application container.
    9. Clean up.

    Comment

    • sj200449
      Junior Member
      • Mar 2023
      • 13

      #3
      Thanks for response , I shall have a read of that link.

      I have found the --data-only option to pg_restore for db that are already initialised , I might try that.

      Comment

      • sj200449
        Junior Member
        • Mar 2023
        • 13

        #4
        Still getting restore errors and a db mismatch alas.

        Take a copy:

        # podman exec -i zabbix-docker-postgres-server-1 bash -c \
        'pg_dump --format=custom --user=zabbix zabbix' > pgdump14.bak

        --format is custom as per most zabbix pgdumps Ive read

        --user is needed as root doesn't exist inside container

        Redirection is used rather than --file to avoid worrying about bound volume
        size for the dump file, redirection not inside container

        (upon restore --data-only if already initialised perhaps?)

        Resultant file is also smaller than tar format tried originally

        # ls -ltr
        -rw-r--r-- 1 root root 7576250368 Oct 14 15:01 pgdump14.tar
        -rw-r--r-- 1 root root 2323813278 Oct 18 14:41 pgdump14.bak

        Going to try restore without the --data-only option which is a new
        discovery.

        For simple transfer with no upgrade of db (yes to zabbix bits though they are 7.4 now)

        cp bak file into data dir on bound volume
        chown to 70 70 - just same as other pg files in dir - uid mapping does that as no uid match inside container to outside

        ensure only db container is running

        # podman exec -i zabbix-db bash -c 'pg_restore --clean --user=zabbix \
        --dbname=zabbix /var/lib/postgresql/data/pgdump14.bak'

        Still get several errors like

        pg_restore: error: could not execute query: ERROR: \
        relation "users" already exists

        But let it finish, it may not matter

        stop the pod
        start the pod

        Still seeing error on web page:

        The Zabbix database version does not match current requirements. Your
        database version: 6050012. Required version: 7040000. Please contact
        your system administrator.

        Together with recurring erors in a follow of journalctl for db

        2026-10-19 17:43:57.844 UTC [226] ERROR: relation "history_bin" already exists

        Comment

        Working...