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

Fix search_path race by separating commands way #297

Closed

Conversation

sanak
Copy link

@sanak sanak commented Jun 6, 2022

Closes #296

@ImreSamu (CC: @strk)
I create this PR with the following steps, so could you check this ?

Note that my environment is macOS Monterey M1 (Apple Silicon) with zsh, so I couldn't execute make test due to No.3 error.

  1. Apply include postgis_raster extension in 3+ images and templates #266 description's following diff.

    The following diff is my suggestion, but I am not sure whether the sessions are separated and original Reconnect after creating extension, to fix search_path race #290 issue will be solved by this.

    --- a/initdb-postgis.sh
    +++ b/initdb-postgis.sh
            "${psql[@]}" --dbname="$DB" <<-'EOSQL'
                    CREATE EXTENSION IF NOT EXISTS postgis;
                    CREATE EXTENSION IF NOT EXISTS postgis_topology;
    -               -- Reconnect to update pg_setting.resetval
    -               -- See https://github.com/postgis/docker-postgis/issues/288
    -               \c
    +EOSQL
    +
    +       "${psql[@]}" --dbname="$DB" <<-'EOSQL'
                    CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;
                    CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder;
     EOSQL
  2. Execute make update to apply above changes to all.
  3. Execute make test with setting environment variables, but encounter the following bash error.
    % export VERSION=14-3.2
    % export VARIANT=default
    % make test
    docker build --pull -t postgis/postgis:14-3.2 14-3.2
    :
    testing postgis/postgis:14-3.2
     'utc' [1/3]...passed
     'no-hard-coded-passwords' [2/3].../Users/sanak/official-images/test/tests/no-hard-coded-passwords/run.sh: line 12: declare: -A: invalid option
    declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
    failed
    :
  4. Build image from command line.
    % docker build --pull --no-cache -t postgis/postgis:14-3.2 14-3.2
  5. Check whether search_path is still valid.
    % docker run --name some-postgis -e POSTGRES_PASSWORD=mysecretpassword -d postgis/postgis:14-3.2
    % docker exec -ti some-postgis psql -U postgres
    psql (14.3 (Debian 14.3-1.pgdg110+1))
    Type "help" for help.
    
    postgres=# show search_path;
               search_path            
    ----------------------------------
     "$user", public, topology, tiger
    (1 row)
  6. Check whether reconnecting is not happen. (Comparing with "fix search_path race" v2 - with make update #292 (comment) - debian log)
    /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
    CREATE EXTENSION
    CREATE EXTENSION
    Loading PostGIS extensions into postgres
    CREATE EXTENSION
    CREATE EXTENSION
    CREATE EXTENSION
    CREATE EXTENSION
    
    waiting for server to shut down....2022-06-06 09:33:26.107 UTC [48] LOG:  received fast shutdown request

Copy link
Member

@strk strk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The effects of the change are STILL a "reconnection", so why dropping the comment ? I'd keep the comment to make sure it doesn't break in the future.

Also, you did not specify WHY the \c reconnection failed for you (did it fail for you?). Asking an already running process to reconnect would be faster than quitting the process and starting a new one...

@sanak
Copy link
Author

sanak commented Jun 6, 2022

@strk Thanks for the comments.

The effects of the change are STILL a "reconnection", so why dropping the comment ? I'd keep the comment to make sure it doesn't break in the future.

Okay, sure.
Sorry for dropping the comment... 🙇

Also, you did not specify WHY the \c reconnection failed for you (did it fail for you?). Asking an already running process to reconnect would be faster than quitting the process and starting a new one...

The reproducible step is a bit complex, but it is as follows.

  1. Clone docker-gtt (https://github.com/gtt-project/docker-gtt) working branch (feature/simplify-docker-settings) on the PR (Simplify Docker settings gtt-project/docker-gtt#53)
    git clone [email protected]:gtt-project/docker-gtt.git -b feature/simplify-docker-settings
    cd docker-gtt
  2. Copy .env.example to .env, then execute docker-compose up.
    copy .env.example .env
    docker-compose up
  3. Confirm that redmine service's migration process starts before postgis service's database init process.
    redmine_1  | Unknown database adapter `postgis` found in config/database.yml, use Gemfile.local to load your own database gems
    redmine_1  | Your Gemfile lists the gem puma (>= 0) more than once.
    redmine_1  | You should probably keep only one of them.
    redmine_1  | Remove any duplicate entries and specify the gem only once.
    redmine_1  | While it's not a problem now, it could cause errors if you change the version of one of them later.
    redmine_1  | Your Gemfile lists the gem immutable-struct (>= 0) more than once.
    redmine_1  | You should probably keep only one of them.
    redmine_1  | Remove any duplicate entries and specify the gem only once.
    redmine_1  | While it's not a problem now, it could cause errors if you change the version of one of them later.
    redmine_1  | The Gemfile's dependencies are satisfied
    redmine_1  | Unknown database adapter `postgis` found in config/database.yml, use Gemfile.local to load your own database gems
    postgis_1  | The files belonging to this database system will be owned by user "postgres".
    postgis_1  | This user must also own the server process.
    postgis_1  | 
    postgis_1  | The database cluster will be initialized with locale "en_US.utf8".
    postgis_1  | The default database encoding has accordingly been set to "UTF8".
    postgis_1  | The default text search configuration will be set to "english".
    postgis_1  | 
    postgis_1  | Data page checksums are disabled.
    postgis_1  | 
    postgis_1  | fixing permissions on existing directory /var/lib/postgresql/data ... ok
    postgis_1  | creating subdirectories ... ok
    postgis_1  | selecting dynamic shared memory implementation ... posix
    postgis_1  | selecting default max_connections ... 100
    postgis_1  | selecting default shared_buffers ... 128MB
    postgis_1  | selecting default time zone ... Etc/UTC
    postgis_1  | creating configuration files ... ok
    postgis_1  | running bootstrap script ... ok
    redmine_1  | Unknown database adapter `postgis` found in config/database.yml, use Gemfile.local to load your own database gems
    redmine_1  | rake aborted!
    redmine_1  | ActiveRecord::ConnectionNotEstablished: could not connect to server: Connection refused
    redmine_1  | 	Is the server running on host "postgis" (172.24.0.2) and accepting
    redmine_1  | 	TCP/IP connections on port 5432?
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/postgresql_adapter.rb:83:in `rescue in new_client'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/postgresql_adapter.rb:77:in `new_client'
    redmine_1  | /usr/local/bundle/gems/activerecord-postgis-adapter-7.1.1/lib/active_record/connection_adapters/postgis/create_connection.rb:41:in `postgis_connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_handling.rb:283:in `connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <top (required)>'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/railties/databases.rake:90:in `each'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <top (required)>'
    redmine_1  | 
    redmine_1  | Caused by:
    redmine_1  | PG::ConnectionBad: could not connect to server: Connection refused
    redmine_1  | 	Is the server running on host "postgis" (172.24.0.2) and accepting
    redmine_1  | 	TCP/IP connections on port 5432?
    redmine_1  | /usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `initialize'
    redmine_1  | /usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `new'
    redmine_1  | /usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `connect'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/postgresql_adapter.rb:78:in `new_client'
    redmine_1  | /usr/local/bundle/gems/activerecord-postgis-adapter-7.1.1/lib/active_record/connection_adapters/postgis/create_connection.rb:41:in `postgis_connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/connection_handling.rb:283:in `connection'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <top (required)>'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/railties/databases.rake:90:in `each'
    redmine_1  | /usr/local/bundle/gems/activerecord-6.1.4.7/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <top (required)>'
    redmine_1  | Tasks: TOP => db:migrate
    redmine_1  | (See full trace by running task with --trace)
    redmine_1  | W, [2022-06-06T14:17:28.623475 #10]  WARN -- : Creating scope :system. Overwriting existing method Enumeration.system.
    redmine_1  | W, [2022-06-06T14:17:28.657263 #10]  WARN -- : Creating scope :sorted. Overwriting existing method User.sorted.
    docker-gtt_redmine_1 exited with code 1
    postgis_1  | performing post-bootstrap initialization ... ok
    postgis_1  | syncing data to disk ... ok
    postgis_1  | 
    postgis_1  | initdb: warning: enabling "trust" authentication for local connections
    postgis_1  | You can change this by editing pg_hba.conf or using the option -A, or
    postgis_1  | --auth-local and --auth-host, the next time you run initdb.
    postgis_1  | 
    postgis_1  | Success. You can now start the database server using:
    postgis_1  | 
    postgis_1  |     pg_ctl -D /var/lib/postgresql/data -l logfile start
    postgis_1  | 
    postgis_1  | waiting for server to start....2022-06-06 14:17:30.098 UTC [125] LOG:  starting PostgreSQL 14.3 (Debian 14.3-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
    postgis_1  | 2022-06-06 14:17:30.102 UTC [125] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
    postgis_1  | 2022-06-06 14:17:30.122 UTC [129] LOG:  database system was shut down at 2022-06-06 14:17:29 UTC
    postgis_1  | 2022-06-06 14:17:30.136 UTC [125] LOG:  database system is ready to accept connections
    postgis_1  |  done
    postgis_1  | server started
    postgis_1  | CREATE DATABASE
    postgis_1  | 
    postgis_1  | 
    postgis_1  | /usr/local/bin/docker-entrypoint.sh: sourcing /docker-entrypoint-initdb.d/10_postgis.sh
    postgis_1  | CREATE DATABASE
    postgis_1  | Loading PostGIS extensions into template_postgis
    postgis_1  | CREATE EXTENSION
    postgis_1  | CREATE EXTENSION
    postgis_1  | You are now connected to database "template_postgis" as user "gtt".
    postgis_1  | CREATE EXTENSION
    postgis_1  | CREATE EXTENSION
    postgis_1  | Loading PostGIS extensions into gtt
    postgis_1  | CREATE EXTENSION
    postgis_1  | CREATE EXTENSION
    postgis_1  | You are now connected to database "gtt" as user "gtt".
    postgis_1  | CREATE EXTENSION
    postgis_1  | CREATE EXTENSION
    postgis_1  | 
    postgis_1  | 2022-06-06 14:17:42.134 UTC [125] LOG:  received fast shutdown request
    postgis_1  | 2022-06-06 14:17:42.135 UTC [125] LOG:  aborting any active transactions
    postgis_1  | waiting for server to shut down....2022-06-06 14:17:42.143 UTC [125] LOG:  background worker "logical replication launcher" (PID 140) exited with exit code 1
    postgis_1  | 2022-06-06 14:17:42.146 UTC [131] LOG:  shutting down
    postgis_1  | 2022-06-06 14:17:42.292 UTC [125] LOG:  database system is shut down
    postgis_1  |  done
    postgis_1  | server stopped
    postgis_1  | 
    postgis_1  | PostgreSQL init process complete; ready for start up.
    postgis_1  | 
    postgis_1  | 2022-06-06 14:17:42.437 UTC [1] LOG:  starting PostgreSQL 14.3 (Debian 14.3-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
    postgis_1  | 2022-06-06 14:17:42.440 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
    postgis_1  | 2022-06-06 14:17:42.440 UTC [1] LOG:  listening on IPv6 address "::", port 5432
    postgis_1  | 2022-06-06 14:17:42.443 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
    postgis_1  | 2022-06-06 14:17:42.463 UTC [185] LOG:  database system was shut down at 2022-06-06 14:17:42 UTC
    postgis_1  | 2022-06-06 14:17:42.478 UTC [1] LOG:  database system is ready to accept connections
    
  4. Stop the docker-compose by Ctrl+C key, then remove DockerHub docker image and build docker image from this PR's branch, then above error wasn't happen.
    docker-compose down -v
    docker image ls
    docker image rm (postgis/postgis:14-3.2 image id)
    # Build postgis/postgis:14-3.2 docker image locally
    docker-compose up
    redmine_1  | Unknown database adapter `postgis` found in config/database.yml, use Gemfile.local to load your own database gems
    redmine_1  | Your Gemfile lists the gem puma (>= 0) more than once.
    redmine_1  | You should probably keep only one of them.
    redmine_1  | Remove any duplicate entries and specify the gem only once.
    redmine_1  | While it's not a problem now, it could cause errors if you change the version of one of them later.
    redmine_1  | Your Gemfile lists the gem immutable-struct (>= 0) more than once.
    redmine_1  | You should probably keep only one of them.
    redmine_1  | Remove any duplicate entries and specify the gem only once.
    redmine_1  | While it's not a problem now, it could cause errors if you change the version of one of them later.
    redmine_1  | The Gemfile's dependencies are satisfied
    postgis_1  | syncing data to disk ... initdb: warning: enabling "trust" authentication for local connections
    postgis_1  | You can change this by editing pg_hba.conf or using the option -A, or
    postgis_1  | --auth-local and --auth-host, the next time you run initdb.
    postgis_1  | ok
    postgis_1  | 
    postgis_1  | 
    postgis_1  | Success. You can now start the database server using:
    postgis_1  | 
    postgis_1  |     pg_ctl -D /var/lib/postgresql/data -l logfile start
    postgis_1  | 
    postgis_1  | waiting for server to start....2022-06-06 14:23:34.812 UTC [49] LOG:  starting PostgreSQL 14.3 (Debian 14.3-1.pgdg110+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
    postgis_1  | 2022-06-06 14:23:34.814 UTC [49] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
    postgis_1  | 2022-06-06 14:23:34.818 UTC [50] LOG:  database system was shut down at 2022-06-06 14:23:34 UTC
    postgis_1  | 2022-06-06 14:23:34.822 UTC [49] LOG:  database system is ready to accept connections
    redmine_1  | Unknown database adapter `postgis` found in config/database.yml, use Gemfile.local to load your own database gems
    postgis_1  |  done
    postgis_1  | server started
    postgis_1  | CREATE DATABASE
    postgis_1  | 
    postgis_1  | 
    postgis_1  | /usr/local/bin/docker-entrypoint.sh: sourcing /docker-entrypoint-initdb.d/10_postgis.sh
    postgis_1  | CREATE DATABASE
    postgis_1  | Loading PostGIS extensions into template_postgis
    postgis_1  | CREATE EXTENSION
    postgis_1  | CREATE EXTENSION
    postgis_1  | CREATE EXTENSION
    postgis_1  | CREATE EXTENSION
    postgis_1  | Loading PostGIS extensions into gtt
    redmine_1  | Unknown database adapter `postgis` found in config/database.yml, use Gemfile.local to load your own database gems
    postgis_1  | CREATE EXTENSION
    postgis_1  | CREATE EXTENSION
    postgis_1  | CREATE EXTENSION
    postgis_1  | CREATE EXTENSION
    postgis_1  | 
    postgis_1  | waiting for server to shut down...2022-06-06 14:23:36.315 UTC [49] LOG:  received fast shutdown request
    postgis_1  | .2022-06-06 14:23:36.316 UTC [49] LOG:  aborting any active transactions
    postgis_1  | 2022-06-06 14:23:36.319 UTC [49] LOG:  background worker "logical replication launcher" (PID 56) exited with exit code 1
    postgis_1  | 2022-06-06 14:23:36.320 UTC [51] LOG:  shutting down
    postgis_1  | 2022-06-06 14:23:36.421 UTC [49] LOG:  database system is shut down
    postgis_1  |  done
    postgis_1  | server stopped
    postgis_1  | 
    postgis_1  | PostgreSQL init process complete; ready for start up.
    postgis_1  | 
    postgis_1  | 2022-06-06 14:23:36.530 UTC [1] LOG:  starting PostgreSQL 14.3 (Debian 14.3-1.pgdg110+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
    postgis_1  | 2022-06-06 14:23:36.530 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
    postgis_1  | 2022-06-06 14:23:36.530 UTC [1] LOG:  listening on IPv6 address "::", port 5432
    postgis_1  | 2022-06-06 14:23:36.532 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
    postgis_1  | 2022-06-06 14:23:36.535 UTC [74] LOG:  database system was shut down at 2022-06-06 14:23:36 UTC
    postgis_1  | 2022-06-06 14:23:36.539 UTC [1] LOG:  database system is ready to accept connections
    redmine_1  | W, [2022-06-06T14:23:37.508553 #11]  WARN -- : Creating scope :system. Overwriting existing method Enumeration.system.
    redmine_1  | W, [2022-06-06T14:23:37.538897 #11]  WARN -- : Creating scope :sorted. Overwriting existing method User.sorted.
    redmine_1  | I, [2022-06-06T14:23:37.807782 #11]  INFO -- : Migrating to Setup (1)
    redmine_1  | == 1 Setup: migrating =========================================================
    redmine_1  | -- create_table("attachments", {:force=>true, :id=>:integer})
    redmine_1  |    -> 0.0049s
    :
    redmine_1  | Unknown database adapter `postgis` found in config/database.yml, use Gemfile.local to load your own database gems
    redmine_1  | => Booting Puma
    redmine_1  | => Rails 6.1.4.7 application starting in production 
    redmine_1  | => Run `bin/rails server --help` for more startup options
    redmine_1  | W, [2022-06-06T14:23:42.871831 #1]  WARN -- : Creating scope :system. Overwriting existing method Enumeration.system.
    redmine_1  | W, [2022-06-06T14:23:42.892371 #1]  WARN -- : Creating scope :sorted. Overwriting existing method User.sorted.
    redmine_1  | W, [2022-06-06T14:23:43.090894 #1]  WARN -- : Creating scope :sorted. Overwriting existing method Group.sorted.
    redmine_1  | Puma starting in single mode...
    redmine_1  | * Puma version: 5.6.4 (ruby 3.1.2-p20) ("Birdie's Version")
    redmine_1  | *  Min threads: 0
    redmine_1  | *  Max threads: 5
    redmine_1  | *  Environment: production
    redmine_1  | *          PID: 1
    redmine_1  | * Listening on http://0.0.0.0:3000
    redmine_1  | Use Ctrl-C to stop
    

Another solution is docker-compose.yml side's workaround as I mentioned in #296, but it is not handy and needs to wait for last postgis_tiger_geocoder extension which is not necessary in our use case.

docker-compose.yml side workaround is possible by waiting for last postgis_tiger_geocoder extension like as follows, but this is not handy.

     volumes:
       - postgis:/var/lib/postgresql/data
+    healthcheck:
+      test: "pg_isready && psql -c \"\\dx\" | grep postgis_tiger_geocoder"
+      interval: 10s
+      timeout: 2s
+      retries: 5
+      start_period: 10s
 
   redmine:
     :
     depends_on:
-      - postgis
+      postgis:
+        condition: service_healthy

@ImreSamu
Copy link
Member

ImreSamu commented Jun 6, 2022

@sanak:

imho: there is a related upstream issue: docker-library/postgres#146
and as I understand, the problem is a little complex.

the current upstream best practice : the best way to test if the container is "ready" is to connect to it using its external IP address (it does not listen externally until the initialization process is fully complete).
like - using the external IP ( -h ) everywhere : pg_isready -h $(hostname -i) or psql -h postgres or ....

@strk
Copy link
Member

strk commented Jun 6, 2022 via email

@sanak
Copy link
Author

sanak commented Jun 7, 2022

@ImreSamu
Okay, thanks for the information.
I will try to use external IP in docker-gtt - docker-compose.yml side.

@strk

I'm not understanding how this "waiting for service" is at all related
to using \c in the SQL stream. The long explanation did not explain
why \c could not be used.

Okay, sure.
I actually don't know why the error happen when using \c, and investigating the cause may take a certain time, so I will try @ImreSamu's advice at first.
Sorry for bothering you.

@sanak
Copy link
Author

sanak commented Jun 7, 2022

@ImreSamu
Thanks!
Using external IP in docker-gtt - docker-compose.yml healthcheck solved the issue.
commit diff: gtt-project/docker-gtt@6bbff06

I close this PR with issue #296.

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

Successfully merging this pull request may close these issues.

Reconnecting database during init process makes a dependency service management harder in "docker-compose.yml"
3 participants