Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install postgis into another schema, note the public one #372

Open
mcherb opened this issue Dec 27, 2023 · 4 comments
Open

Install postgis into another schema, note the public one #372

mcherb opened this issue Dec 27, 2023 · 4 comments
Labels

Comments

@mcherb
Copy link

mcherb commented Dec 27, 2023

Hi,

In my production environment, postgis is installed into a schema called postgis. Now I'm using postgis/postgis:10-3.0 but by default this image install postgis into the public schema.

Is there a way to make this schema controlled by a environment variable ?

@ImreSamu
Copy link
Member

ImreSamu commented Dec 27, 2023

Is there a way to make this schema controlled by a environment variable ?

I'm not entirely sure I understand your issue,
but if you want to customize the PostGIS initialization script (/docker-entrypoint-initdb.d/10_postgis.sh),
you can use your own custom script by mapping it in a Docker file like this:

  • -v $(pwd)/10_postgis.sh:/docker-entrypoint-initdb.d/10_postgis.sh

Additionally, you might need to modify it to correctly use the 'CREATE EXTENSION' command as described here:

And this is the the contents of postgis/postgis:10-3.0 - /docker-entrypoint-initdb.d/10_postgis.sh:

$ docker run -it --rm  postgis/postgis:10-3.0 cat /docker-entrypoint-initdb.d/10_postgis.sh

#!/bin/sh

set -e

# Perform all actions as $POSTGRES_USER
export PGUSER="$POSTGRES_USER"

# Create the 'template_postgis' template db
"${psql[@]}" <<- 'EOSQL'
CREATE DATABASE template_postgis IS_TEMPLATE true;
EOSQL

# Load PostGIS into both template_database and $POSTGRES_DB
for DB in template_postgis "$POSTGRES_DB"; do
	echo "Loading PostGIS extensions into $DB"
	"${psql[@]}" --dbname="$DB" <<-'EOSQL'
		CREATE EXTENSION IF NOT EXISTS postgis;
		CREATE EXTENSION IF NOT EXISTS postgis_topology;
		CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;
		CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder;
EOSQL
done

@ImreSamu
Copy link
Member

related:

https://gis.stackexchange.com/questions/87212/add-postgis-spatial-functions-to-a-custom-schema-other-than-public-in-postgres

@mcherb
Copy link
Author

mcherb commented Dec 27, 2023

Thanks for your replay :)

@stmtk1
Copy link

stmtk1 commented Jan 6, 2024

In this image, the environment variables POSTGRES_DB, POSTGRES_USER and POSTGRES_PASSWORD can be used to change the database name, user name and password name, but not the schema name. So we want to be able to change the schema name using the new environment variable POSTGRES_SCHEMA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants