dokku / dokku-postgres

a postgres plugin for dokku
MIT License
484 stars 97 forks source link

Configure timeout for container creation #321

Open SteelAlloy opened 2 months ago

SteelAlloy commented 2 months ago

If you're using Dokku - especially for commercial purposes - consider donating to project development via OpenCollective or Patreon. Funds go to general development, support, and infrastructure costs.

If you'd like to sponsor specific functionality, see the project's Sponsoring document.

If you need support for a version of Dokku that is more than a year old, your issue may be closed without an answer. Please upgrade to a recent version before filing an issue.

Description of problem

For some reason, my system is quite slow and container creation is taking more than 30sec for postgres to be up and running.

When cloning a database, the data is not copied. When creating a database, I need to manually enter the container and run CREATE DATABASE test_new_db

This 30sec threshold is a serious issue for me and the default timeout of https://hub.docker.com/r/dokku/wait.

By adding a bigger value (60s for instance), my container is fully functional.

-  if ! suppress_output "$DOCKER_BIN" container run "${LINK_CONTAINER_DOCKER_ARGS[@]}" "$PLUGIN_WAIT_IMAGE" -c "$network_alias:$PLUGIN_DATASTORE_WAIT_PORT"; then
+  if ! suppress_output "$DOCKER_BIN" container run "${LINK_CONTAINER_DOCKER_ARGS[@]}" "$PLUGIN_WAIT_IMAGE" -c "$network_alias:$PLUGIN_DATASTORE_WAIT_PORT" -t 60; then

How reproducible

Need a slow system

Steps to Reproduce

  1. Create or clone a db

Actual Results

root@dokku:~ # dokku postgres:create test-new-db
       Waiting for container to be ready
Waiting for dokku-postgres-test-new-db:5432  ...............................  ERROR: unable to connect
=====> Start of test-new-db container output
       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
=====> End of test-new-db container output

Expected Results

root@dokku:~ # dokku postgres:create test-new-db
       Waiting for container to be ready
       Creating container database
       Securing connection to database
=====> Postgres container created: test-new-db
=====> test-new-db postgres service information
       Config dir:          /var/lib/dokku/services/postgres/test-new-db/data
       Config options:
       Data dir:            /var/lib/dokku/services/postgres/test-new-db/data
       Dsn:                 postgres://postgres:5dd8840fd30418b23cc3a914bcb6d0c0@dokku-postgres-test-new-db:5432/test_new_db
       Exposed ports:       -
       Id:                  d343731c4a6cb2b0c3186770c6526655e529700729a0ba331228cd804ff9e526
       Internal ip:         172.17.0.5
       Initial network:
       Links:               -
       Post create network:
       Post start network:
       Service root:        /var/lib/dokku/services/postgres/test-new-db
       Status:              running
       Version:             postgres:16.3

Environment Information

output of dokku postgres:logs test-new-db

Nothing intersting here, since there isn't any error. The plugin just doesn't wait long enough

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
initdb: warning: enabling "trust" authentication for local connections
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: hint: 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....2024-07-30 19:08:00.451 UTC [49] LOG:  starting PostgreSQL 16.3 (Debian 16.3-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2024-07-30 19:08:00.452 UTC [49] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2024-07-30 19:08:00.549 UTC [52] LOG:  database system was shut down at 2024-07-30 19:07:59 UTC
2024-07-30 19:08:00.590 UTC [49] LOG:  database system is ready to accept connections
 done
server started

/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*

2024-07-30 19:08:00.925 UTC [49] LOG:  received fast shutdown request
waiting for server to shut down...2024-07-30 19:08:00.938 UTC [49] LOG:  aborting any active transactions
.2024-07-30 19:08:00.941 UTC [49] LOG:  background worker "logical replication launcher" (PID 55) exited with exit code 1
2024-07-30 19:08:00.942 UTC [50] LOG:  shutting down
2024-07-30 19:08:00.955 UTC [50] LOG:  checkpoint starting: shutdown immediate
2024-07-30 19:08:01.065 UTC [50] LOG:  checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.032 s, sync=0.001 s, total=0.124 s; sync files=2, longest=0.001 s, average=0.001 s; distance=0 kB, estimate=0 kB; lsn=0/14EA208, redo lsn=0/14EA208
2024-07-30 19:08:01.160 UTC [49] LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

2024-07-30 19:08:01.258 UTC [1] LOG:  starting PostgreSQL 16.3 (Debian 16.3-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2024-07-30 19:08:01.258 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2024-07-30 19:08:01.258 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2024-07-30 19:08:01.267 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2024-07-30 19:08:01.314 UTC [63] LOG:  database system was shut down at 2024-07-30 19:08:01 UTC
2024-07-30 19:08:01.370 UTC [1] LOG:  database system is ready to accept connections

How (deb/make) and where (AWS, VirtualBox, physical, etc.) was Dokku installed?:

deb, self hosted on bare metal

Additional information

A plugin setting to allow a bigger value for the timeout would solve the issue I think ?