postgis / docker-postgis

Docker image for PostGIS
https://hub.docker.com/r/postgis/postgis/
MIT License
1.39k stars 466 forks source link

Version 14-3.4: Error command not found in initdb-postgis.sh #358

Closed uync-beetech closed 1 year ago

uync-beetech commented 1 year ago

/docker-entrypoint-initdb.d/10_postgis.sh: line 16: --dbname=template_postgis: command not found PostgreSQL Database directory appears to contain a database; Skipping initialization

ImreSamu commented 1 year ago

Thank you for reporting this issue!

To better assist you, could you provide more details about:

Could you also execute the following commands and attach the logs as output? This will help in identifying the root cause:

docker --version
docker pull postgis/postgis:14-3.4
docker images | grep 14-3.4
docker run --name postgistest1434 -v postgistest1434:/var/lib/postgresql/data -e POSTGRES_PASSWORD=gis123 -d postgis/postgis:14-3.4
docker logs postgistest1434
docker exec -ti postgistest1434 psql -U postgres
uync-beetech commented 1 year ago

Thank you for reporting this issue!

To better assist you, could you provide more details about:

  • Your operating system and its version
  • The Docker version you are using
  • A brief description of what you were trying to achieve when you encountered the error
  • Additionally, if you start with an empty database directory, are you able to reproduce the issue?
  • Any other relevant information that might help prevent similar issues in the future would also be appreciated.

Could you also execute the following commands and attach the logs as output? This will help in identifying the root cause:

docker --version
docker pull postgis/postgis:14-3.4
docker images | grep 14-3.4
docker run --name postgistest1434 -v postgistest1434:/var/lib/postgresql/data -e POSTGRES_PASSWORD=gis123 -d postgis/postgis:14-3.4
docker logs postgistest1434
docker exec -ti postgistest1434 psql -U postgres

Thank you for reply, My info:

Run log:

2023-09-11 18:18:53 jacic_be-postgres-1 | The files belonging to this database system will be owned by user "postgres". 2023-09-11 18:18:53 jacic_be-postgres-1 | This user must also own the server process. 2023-09-11 18:18:53 jacic_be-postgres-1 | 2023-09-11 18:18:53 jacic_be-postgres-1 | initdb: could not find suitable text search configuration for locale "ja_JP.UTF-8" 2023-09-11 18:18:53 jacic_be-postgres-1 | The database cluster will be initialized with locales 2023-09-11 18:18:53 jacic_be-postgres-1 | COLLATE: C 2023-09-11 18:18:53 jacic_be-postgres-1 | CTYPE: ja_JP.UTF-8 2023-09-11 18:18:53 jacic_be-postgres-1 | MESSAGES: C 2023-09-11 18:18:53 jacic_be-postgres-1 | MONETARY: C 2023-09-11 18:18:53 jacic_be-postgres-1 | NUMERIC: C 2023-09-11 18:18:53 jacic_be-postgres-1 | TIME: C 2023-09-11 18:18:53 jacic_be-postgres-1 | The default text search configuration will be set to "simple". 2023-09-11 18:18:53 jacic_be-postgres-1 | 2023-09-11 18:18:53 jacic_be-postgres-1 | Data page checksums are disabled. 2023-09-11 18:18:53 jacic_be-postgres-1 | 2023-09-11 18:18:53 jacic_be-postgres-1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok 2023-09-11 18:18:53 jacic_be-postgres-1 | creating subdirectories ... ok 2023-09-11 18:18:53 jacic_be-postgres-1 | selecting dynamic shared memory implementation ... posix 2023-09-11 18:18:53 jacic_be-postgres-1 | selecting default max_connections ... 100 2023-09-11 18:18:53 jacic_be-postgres-1 | selecting default shared_buffers ... 128MB 2023-09-11 18:18:53 jacic_be-postgres-1 | selecting default time zone ... Asia/Tokyo 2023-09-11 18:18:53 jacic_be-postgres-1 | creating configuration files ... ok 2023-09-11 18:18:53 jacic_be-postgres-1 | running bootstrap script ... ok 2023-09-11 18:18:54 jacic_be-postgres-1 | performing post-bootstrap initialization ... ok 2023-09-11 18:18:54 jacic_be-postgres-1 | syncing data to disk ... ok 2023-09-11 18:18:54 jacic_be-postgres-1 | 2023-09-11 18:18:54 jacic_be-postgres-1 | 2023-09-11 18:18:54 jacic_be-postgres-1 | Success. You can now start the database server using: 2023-09-11 18:18:54 jacic_be-postgres-1 | 2023-09-11 18:18:54 jacic_be-postgres-1 | pg_ctl -D /var/lib/postgresql/data -l logfile start 2023-09-11 18:18:54 jacic_be-postgres-1 | 2023-09-11 18:18:54 jacic_be-postgres-1 | initdb: warning: enabling "trust" authentication for local connections 2023-09-11 18:18:54 jacic_be-postgres-1 | You can change this by editing pg_hba.conf or using the option -A, or 2023-09-11 18:18:54 jacic_be-postgres-1 | --auth-local and --auth-host, the next time you run initdb. 2023-09-11 18:18:54 jacic_be-postgres-1 | waiting for server to start....2023-09-11 20:18:54.570 JST [49] LOG: starting PostgreSQL 14.9 (Debian 14.9-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit 2023-09-11 18:18:54 jacic_be-postgres-1 | 2023-09-11 20:18:54.575 JST [49] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" 2023-09-11 18:18:54 jacic_be-postgres-1 | 2023-09-11 20:18:54.597 JST [50] LOG: database system was shut down at 2023-09-11 20:18:54 JST 2023-09-11 18:18:54 jacic_be-postgres-1 | 2023-09-11 20:18:54.605 JST [49] LOG: database system is ready to accept connections 2023-09-11 18:18:54 jacic_be-postgres-1 | done 2023-09-11 18:18:54 jacic_be-postgres-1 | server started 2023-09-11 18:18:54 jacic_be-postgres-1 | CREATE DATABASE 2023-09-11 18:18:54 jacic_be-postgres-1 | 2023-09-11 18:18:54 jacic_be-postgres-1 | 2023-09-11 18:18:54 jacic_be-postgres-1 | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/10_postgis.sh 2023-09-11 18:18:54 jacic_be-postgres-1 | Loading PostGIS extensions into template_postgis 2023-09-11 18:18:54 jacic_be-postgres-1 | /docker-entrypoint-initdb.d/10_postgis.sh: line 16: --dbname=template_postgis: command not found 2023-09-11 18:18:55 jacic_be-postgres-1 | 2023-09-11 18:18:55 jacic_be-postgres-1 | PostgreSQL Database directory appears to contain a database; Skipping initialization 2023-09-11 18:18:55 jacic_be-postgres-1 | 2023-09-11 18:18:55 jacic_be-postgres-1 | 2023-09-11 20:18:55.850 JST [1] LOG: starting PostgreSQL 14.9 (Debian 14.9-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit 2023-09-11 18:18:55 jacic_be-postgres-1 | 2023-09-11 20:18:55.851 JST [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 2023-09-11 18:18:55 jacic_be-postgres-1 | 2023-09-11 20:18:55.851 JST [1] LOG: listening on IPv6 address "::", port 5432 2023-09-11 18:18:55 jacic_be-postgres-1 | 2023-09-11 20:18:55.862 JST [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" 2023-09-11 18:18:55 jacic_be-postgres-1 | 2023-09-11 20:18:55.876 JST [27] LOG: database system was interrupted; last known up at 2023-09-11 20:18:54 JST 2023-09-11 18:18:55 jacic_be-postgres-1 | 2023-09-11 20:18:55.992 JST [27] LOG: database system was not properly shut down; automatic recovery in progress 2023-09-11 18:18:56 jacic_be-postgres-1 | 2023-09-11 20:18:55.999 JST [27] LOG: redo starts at 0/16FBA20 2023-09-11 18:18:56 jacic_be-postgres-1 | 2023-09-11 20:18:55.999 JST [27] LOG: invalid record length at 0/16FBB18: wanted 24, got 0 2023-09-11 18:18:56 jacic_be-postgres-1 | 2023-09-11 20:18:55.999 JST [27] LOG: redo done at 0/16FBAD0 system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s 2023-09-11 18:18:56 jacic_be-postgres-1 | 2023-09-11 20:18:56.061 JST [1] LOG: database system is ready to accept connections 2023-09-11 18:19:25 jacic_be-postgres-1 | 2023-09-11 20:19:25.789 JST [37] ERROR: type "geometry" does not exist 2023-09-11 18:19:25 jacic_be-postgres-1 | 2023-09-11 20:19:25.789 JST [37] STATEMENT: CREATE EXTENSION IF NOT EXISTS postgis_topology

I hope to receive a response from you soon.

ImreSamu commented 1 year ago

HI @uync-beetech

I've tested the issue in various environments:

Unfortunately, I was unable to reproduce the reported error in any of these cases. In each scenario, I used the image from Docker Hub:

Regarding your notes:

But it return error at line 16 in https://github.com/postgis/docker-postgis/blob/master/14-3.4/initdb-postgis.sh

It seems that your database encountered an issue ( ~ crashed ) before the PostGIS initialization process, which is unexpected.

2023-09-11 18:18:55 jacic_be-postgres-1 | 2023-09-11 20:18:55.876 JST [27] LOG: database system was interrupted; last known up at 2023-09-11 20:18:54 JST
2023-09-11 18:18:55 jacic_be-postgres-1 | 2023-09-11 20:18:55.992 JST [27] LOG: database system was not properly shut down; automatic recovery in progress
2023-09-11 18:18:56 jacic_be-postgres-1 | 2023-09-11 20:18:55.999 JST [27] LOG: redo starts at 0/16FBA20
2023-09-11 18:18:56 jacic_be-postgres-1 | 2023-09-11 20:18:55.999 JST [27] LOG: invalid record length at 0/16FBB18: wanted 24, got 0
2023-09-11 18:18:56 jacic_be-postgres-1 | 2023-09-11 20:18:55.999 JST [27] LOG: redo done at 0/16FBAD0 system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
2023-09-11 18:18:56 jacic_be-postgres-1 | 2023-09-11 20:18:56.061 JST [1] LOG: database system is ready to accept connections

I tried this configs: https://github.com/postgis/docker-postgis/tree/master/14-3.4

Does this mean you also built the Docker image yourself and did not use the one available on Docker Hub? If so, I would recommend doing this in WSL2 using git clone to ensure Linux-specific file settings are preserved.

Can you replicate the issue using the following images and with entirely empty database directories?

If you initialize the postgis/postgis:14-3.4 with three separate empty directories, does the test fail in all three attempts, or does the error occur sporadically?

Could you also document all the Docker run parameters you're using? For example, I can see the locale "ja_JP.UTF-8" from the logs, but there might be other parameters you're applying.

My log:

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 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    pg_ctl -D /var/lib/postgresql/data -l logfile start

initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
waiting for server to start....2023-09-14 03:38:42.350 UTC [47] LOG:  starting PostgreSQL 14.9 (Debian 14.9-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2023-09-14 03:38:42.354 UTC [47] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-09-14 03:38:42.359 UTC [48] LOG:  database system was shut down at 2023-09-14 03:38:42 UTC
2023-09-14 03:38:42.364 UTC [47] LOG:  database system is ready to accept connections
 done
server started

/usr/local/bin/docker-entrypoint.sh: sourcing /docker-entrypoint-initdb.d/10_postgis.sh
CREATE DATABASE
Loading PostGIS extensions into template_postgis
CREATE EXTENSION
CREATE EXTENSION
You are now connected to database "template_postgis" as user "postgres".
CREATE EXTENSION
CREATE EXTENSION
Loading PostGIS extensions into postgres
CREATE EXTENSION
CREATE EXTENSION
You are now connected to database "postgres" as user "postgres".
CREATE EXTENSION
CREATE EXTENSION

waiting for server to shut down...2023-09-14 03:38:45.527 UTC [47] LOG:  received fast shutdown request
.2023-09-14 03:38:45.528 UTC [47] LOG:  aborting any active transactions
2023-09-14 03:38:45.529 UTC [47] LOG:  background worker "logical replication launcher" (PID 54) exited with exit code 1
2023-09-14 03:38:45.530 UTC [49] LOG:  shutting down
2023-09-14 03:38:45.624 UTC [47] LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

2023-09-14 03:38:45.651 UTC [1] LOG:  starting PostgreSQL 14.9 (Debian 14.9-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2023-09-14 03:38:45.651 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2023-09-14 03:38:45.651 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2023-09-14 03:38:45.653 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-09-14 03:38:45.658 UTC [69] LOG:  database system was shut down at 2023-09-14 03:38:45 UTC
2023-09-14 03:38:45.662 UTC [1] LOG:  database system is ready to accept connections

Based on the current information, I'm unable to determine the discrepancy since I can't reproduce the problem in my environment.

Thank you for your understanding and collaboration!

duccioa commented 1 year ago

My problem was resolved by adding this line to the Dockerfile:

RUN chmod -x /docker-entrypoint-initdb.d/10_postgis.sh

Found it here

uync-beetech commented 1 year ago

My problem was resolved by adding this line to the Dockerfile:

RUN chmod -x /docker-entrypoint-initdb.d/10_postgis.sh

Found it here

Thank bro, It has helped me solve this issue.