Deploying Postgres database on azure Container Instance?
Asked Answered
M

1

6

I am trying to deploy PostgresDatabase on azure container instance. To deploy on docker using bind mount(since Azure container Instance only support bind mount) i am using the below command, and it is deployed on docker. docker run -d -p 5434:5432 --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -e PGDATA=/var/lib/postgresql/data/pgdata -v /home/ubuntu/volum:/var/lib/postgresql/data postgres

If i do something similar for deploying on Azure container Instance

az container create \
    --resource-group $ACI_PERS_RESOURCE_GROUP \
    --name postgreariesdb25-1 \
    --location eastus \
    --image postgres \
    --dns-name-label $ACI_DNS_LABEL \
    --environment-variables POSTGRES_PASSWORD=mysecretpassword PGDATA=/var/lib/postgresql/data/pgdata  \
    --ports 5432  \
    --azure-file-volume-account-name $ACI_PERS_STORAGE_ACCOUNT_NAME \
    --azure-file-volume-account-key $STORAGE_KEY \
    --azure-file-volume-share-name $ACI_PERS_SHARE_NAME \
    --azure-file-volume-mount-path /var/lib/postgresql/data

I am getting the below message inside logs of Azure Container

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data/pgdata ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 20
selecting default shared_buffers ... 400kB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
2020-11-24 05:23:39.218 UTC [85] FATAL:  data directory "/var/lib/postgresql/data/pgdata" has wrong ownership
2020-11-24 05:23:39.218 UTC [85] HINT:  The server must be started by the user that owns the data directory.
child process exited with exit code 1
initdb: removing contents of data directory "/var/lib/postgresql/data/pgdata"
running bootstrap script ... 

Volume Mount is required to have data in case of container restart.

Menedez answered 24/11, 2020 at 5:54 Comment(4)
Container instances are mostly suited for short running operations, dont deploy a database using ACIBosworth
Any updates on this question? Does it solve your problem?Notepaper
Not yet, have tried Azure Database for PostgreSQL server but there is some different issue in using thatMenedez
What do you mean by trying Azure Database for PostgreSQL server? Your question is on deploying the Postgresql database on ACI.Notepaper
N
8

This is a known error for mounting Azure File Share to Azure Container Instance. Currently, it does not support to change the ownership of the mount point. If you do not want to use other services, then you need to create a script to move the data to the mount point and the mount point should be a new folder that does not exist in the image. For you, the mount point /var/lib/postgresql/data exists in the image and contains the files that Postgresql depends on, then this point cannot be the mount point.

Notepaper answered 25/11, 2020 at 2:54 Comment(6)
Thanks, changing the mount point to something random like /var/lib/postgresql/foobar worked for me.Ealing
@Ealing does your approach still maintain persistence of the database in your data share location? My tests show that changing the mount point to /var/lib/postgresql/foobar lead the file share going empty. What am I missing?Aerometry
Charles Xu, could you flesh out your suggestion above a little more? Where would we create the script to do the moving? Thanks!Aerometry
@Aerometry - While this worked during testing, we did not pursue Azure Containers Instances further and switched to Amazon ECS.Ealing
Is this answer still valid in 2023? :) Having the same problem.Acrylonitrile
Same problem with Azure Container Apps in 2024.Stifling

© 2022 - 2024 — McMap. All rights reserved.