Setting Postgres extensions via POSTGRESQL_EXTENSIONS env

Open
#669 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
docker, postgresql
Domain
databases, devops

Research direction

Start with the PostgreSQL 15 logic in root/usr/share/container-scripts/postgresql/common.sh around lines 491-498, then inspect the extension test in test/run_test around lines 1079-1088. Reproduce the issue using the provided podman command and verify whether POSTGRESQL_EXTENSIONS is processed during initialization. Done means the reported pg_trgm setup behavior is explained and the test or initialization behavior is corrected.

Written by the indexing model from the issue text.

Description

Hey Gang!

I'm attempting to start Postgres-15 with an extension: POSTGRESQL_EXTENSIONS="pg_trgm" but it does not seem to work as expected

The shell script here seems to be where the action happens:
https://github.com/sclorg/postgresql-container/blob/4d36fddfb7afb5bbb3e1eaa78c3c132f5ee807cb/15/root/usr/share/container-scripts/postgresql/common.sh#L491-L498

For context, I'm setting up a Quay instance with Postgres and that requires the pg_trgm extension.

Steps to reproduce:

##
## Setup storage and fix permissions
##
sudo mkdir -pv /mnt/quay/postgres-data
sudo setfacl -m u:26:-wx /mnt/quay/postgres-data

##
## Run the container
##
sudo podman pod create \
  --name quay-pod \
  -p 80:8080 \
  -p 443:8443

sudo podman run \
  --name quay_postgres \
  --pod quay-pod \
  --rm -d \
  -e POSTGRESQL_USER=quayuser \
  -e POSTGRESQL_PASSWORD=quaypass \
  -e POSTGRESQL_DATABASE=quay \
  -e POSTGRESQL_ADMIN_PASSWORD=adminpass \
  -e POSTGRESQL_EXTENSIONS="pg_trgm " \
  -v /mnt/quay/postgres-data:/var/lib/pgsql/data:Z \
  quay.io/fedora/postgresql-15

##
## The verification step will show if the "pg_trgm" extension was installed.
##
sudo podman exec -it quay_postgres  psql -U quayuser -d quay -c "\dx pg_trgm"

     List of installed extensions
 Name | Version | Schema | Description 
------+---------+--------+-------------
(0 rows)

The pg_trgm extension does in fact work if setup after the container is running.

sudo podman exec -it quay_postgres psql -U quayuser -d quay -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
sudo podman exec -it quay_postgres  psql -U quayuser -d quay -c "\dx pg_trgm"

CREATE EXTENSION
                                  List of installed extensions
  Name   | Version | Schema |                            Description
---------+---------+--------+-------------------------------------------------------------------
 pg_trgm | 1.6     | public | text similarity measurement and index searching based on trigrams
(1 row)

So it appears the feature to run extensions from the environment variable is not working, at least not in this case.
I see there are tests for the feature:
https://github.com/sclorg/postgresql-container/blob/4d36fddfb7afb5bbb3e1eaa78c3c132f5ee807cb/test/run_test#L1079-L1088
But I'm not sure how well that test works, and I've not tried running the test myself (not yet).

Can somebody chime in and say if the issue is legit?
Thanks in advance!

Dominant language
PLpgSQL
Stars
178
Forks
220
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sclorg/postgresql-container

All issues in sclorg/postgresql-container

Similar issues

More Databases issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.