Setting up Postgres container with persistent storage/host path storage

System info:

  • Scale Cobia
  • Official postgres:16.3 image running as custom app
  • UID/GID for postgres, has ownership over the dataset being used

Does anyone run a Postgres database instance and able to mount the db data to a Host Path successfully?

Need some help with my Homelab setup. Having an issue where it’s mounted under the directory I chose but not saving. I have some experience running containers in a Pi but moving my homelab setup to Truenas so I can use the Pi for other things. This is the last piece of the puzzle.

At the bare minimum I’d like to setup persistent data in case I need to restart the container.

I tried using /var/ as the mount path and other variations based on where the database data is stored using SHOW data_directory; in pgAdmin.

Or is the way to approach this to just use pgAdmin to create backups and restore whenever I restart the Postgres container?

image

i just started using Truenas scale, I was surprised to see no data base option at all in the apps… I wanted to install Postgres as well. I will be following this thread I hope someone who knows will come forward with a fix for this.

I don’t use postgres, but have Mariadb as a custom app serving something like 9 devices here. So, the doc for that is here:

You have some environment variables to set according to that doc, set them in the custom app config. According to that doc, you also need a hostpath for /var/lib/postgresql/data to Scale storage directory (your /mnt/Database/postgres) for persistence. And /mnt/Database/postgres directory needs to be owned by whatever user id is the postgres user in the container. So, permissions is a key thing here as it can’t access the storage otherwise and it will remain empty.