kartoza / docker-postgis

Dockerfile for postgis
GNU General Public License v2.0
648 stars 317 forks source link

Can't create multiple schemas #453

Closed jyrkka closed 11 months ago

jyrkka commented 11 months ago

What is the bug or the crash?

Documentation says that SCHEMA_NAME variable should accept comma separated value of schema names which should be created during initialization. But when when giving that value, initialization gives an error and container does not start.

Steps to reproduce the issue

docker run --rm --env-file .env kartoza/postgis:15-3.4

Content of the .env-file

SCHEMA_NAME=schema1,schema2

Docker run output:

Creating /settings directory
Creating /docker-entrypoint.initdb.d directory
Creating /ssl_certificates directory
Add rule to pg_hba: 0.0.0.0/0
Add rule to pg_hba: replication replicator 
 _  __          _                  ____             _             
| |/ /__ _ _ __| |_ ___ ______ _  |  _ \  ___   ___| | _____ _ __ 
| ' // _` | '__| __/ _ \_  / _` | | | | |/ _ \ / __| |/ / _ \ '__|
| . \ (_| | |  | || (_) / / (_| | | |_| | (_) | (__|   <  __/ |   
|_|\_\__,_|_|   \__\___/___\__,_| |____/ \___/ \___|_|\_\___|_|   

 ____           _    ____ ___ ____  
|  _ \ ___  ___| |_ / ___|_ _/ ___| 
| |_) / _ \/ __| __| |  _ | |\___ \ 
|  __/ (_) \__ \ |_| |_| || | ___) |
|_|   \___/|___/\__|\____|___|____/ 

[Entrypoint] GENERATED Postgres  PASSWORD:  aW6SQFfIC7HkkTsD8BOX 
[Entrypoint] GENERATED Replication  PASSWORD:  RZ0uIbPbk22wBhWz9VIDGd 
[Entrypoint] Setup master database 
Creating /opt/archivedir directory
/var/run/postgresql:5432 - no response
2023-10-02 07:26:00.557 UTC [118] LOG:  starting PostgreSQL 15.4 (Debian 15.4-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2023-10-02 07:26:00.557 UTC [118] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2023-10-02 07:26:00.580 UTC [118] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-10-02 07:26:00.617 UTC [125] LOG:  database system was shut down at 2023-08-31 16:54:46 UTC
2023-10-02 07:26:00.635 UTC [118] LOG:  database system is ready to accept connections
2023-10-02 07:26:00.635 UTC [128] FATAL:  database "gis" does not exist
2023-10-02 07:26:00.643 UTC [118] LOG:  background worker "pg_cron launcher" (PID 128) exited with exit code 1
/var/run/postgresql:5432 - accepting connections
postgres ready
Creating user docker
CREATE ROLE
Creating user replicator
2023-10-02 07:26:01.645 UTC [150] FATAL:  database "gis" does not exist
2023-10-02 07:26:01.646 UTC [118] LOG:  background worker "pg_cron launcher" (PID 150) exited with exit code 1
CREATE ROLE
 [Entrypoint] Create database  gis  
CREATE EXTENSION
 [Entrypoint] Enabling extension  postgis  in the database :  gis 
CREATE EXTENSION
 [Entrypoint] Enabling extension  hstore  in the database :  gis 
CREATE EXTENSION
 [Entrypoint] Enabling extension  postgis_topology  in the database :  gis 
CREATE EXTENSION
 [Entrypoint] Enabling extension  postgis_raster  in the database :  gis 
CREATE EXTENSION
 [Entrypoint] Enabling extension  pgrouting  in the database :  gis 
2023-10-02 07:26:02.649 UTC [176] LOG:  pg_cron scheduler started
CREATE EXTENSION
 [Entrypoint] loading legacy sql in database  gis  
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE OPERATOR CLASS
 [Entrypoint] Creating schema  schema1 schema2  in database  gis 
2023-10-02 07:26:02.914 UTC [189] docker@gis ERROR:  syntax error at or near "schema2" at character 38
2023-10-02 07:26:02.914 UTC [189] docker@gis STATEMENT:   CREATE SCHEMA IF NOT EXISTS schema1 schema2;
ERROR:  syntax error at or near "schema2"
LINE 1:  CREATE SCHEMA IF NOT EXISTS schema1 schema2;

Versions

15-3.4

Additional context

No response

NyakudyaA commented 11 months ago

It must be a bug, Can you remove the line https://github.com/kartoza/docker-postgis/blob/develop/scripts/setup-database.sh#L143 and add the following.

IFS=','
read -a schema_arr <<< "$SCHEMA_NAME"
for schema in "${schema_arr[@]}";do

Then build locally. If it works you can do a PR