dokku / dokku-postgres

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

Database is not created with --custom-env=LC_ALL=C #239

Open timaschew opened 2 years ago

timaschew commented 2 years ago

Description of problem

Database is not created

How reproducible

always with --custom-env "LC_ALL=C args

Steps to Reproduce

  1. dokku postgres:create test-db-2 --custom-env "LC_ALL=C
  2. dokku postgres:info test-db-2 and look database which is shown in the Dsn: /test-db-2
  3. dokku postgres:enter test-db-2
  4. psql -U postgres
  5. \l

The output is different compared when --custom-env is not passed, the database test-db-2 is missing

Actual Results

                             List of databases
   Name    |  Owner   | Encoding  | Collate | Ctype |   Access privileges
-----------+----------+-----------+---------+-------+-----------------------
 postgres  | postgres | SQL_ASCII | C       | C     |
 template0 | postgres | SQL_ASCII | C       | C     | =c/postgres          +
           |          |           |         |       | postgres=CTc/postgres
 template1 | postgres | SQL_ASCII | C       | C     | =c/postgres          +
           |          |           |         |       | postgres=CTc/postgres
(3 rows)

Expected Results

                                 List of databases
   Name    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges
-----------+----------+----------+------------+------------+-----------------------
 postgres  | postgres | UTF8     | en_US.utf8 | en_US.utf8 |
 template0 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
           |          |          |            |            | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
           |          |          |            |            | postgres=CTc/postgres
 test_db_2 | postgres | UTF8     | en_US.utf8 | en_US.utf8 |
(4 rows)

Environment Information

N/A

dokku report APP_NAME output

N/A

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

vServer / Debian Buster / installed via wget https://raw.githubusercontent.com/dokku/dokku/v0.25.5/bootstrap.sh;

Additional information

dokku version 0.25.4 postgres 1.14.1 enabled dokku postgres service plugin

dokku report

-----> uname: Linux v220210114110140000 5.10.0-8-amd64 #1 SMP Debian 5.10.46-5 (2021-09-23) x86_64 GNU/Linux
-----> memory:
                      total        used        free      shared  buff/cache   available
       Mem:            7957         599        1193         120        6163        7166
       Swap:              0           0           0
-----> docker version:
       Client: Docker Engine - Community
        Version:           20.10.8
        API version:       1.41
        Go version:        go1.16.6
        Git commit:        3967b7d
        Built:             Fri Jul 30 19:54:22 2021
        OS/Arch:           linux/amd64
        Context:           default
        Experimental:      true

       Server: Docker Engine - Community
        Engine:
         Version:          20.10.8
         API version:      1.41 (minimum version 1.12)
         Go version:       go1.16.6
         Git commit:       75249d8
         Built:            Fri Jul 30 19:52:31 2021
         OS/Arch:          linux/amd64
         Experimental:     false
        containerd:
         Version:          1.4.10
         GitCommit:        8848fdb7c4ae3815afcc990a8a99d663dda1b590
        runc:
         Version:          1.0.2
         GitCommit:        v1.0.2-0-g52b36a2
        docker-init:
         Version:          0.19.0
         GitCommit:        de40ad0
-----> docker daemon info:
       Client:
        Context:    default
        Debug Mode: true
        Plugins:
         app: Docker App (Docker Inc., v0.9.1-beta3)
         buildx: Build with BuildKit (Docker Inc., v0.6.1-docker)
         scan: Docker Scan (Docker Inc., v0.8.0)

       Server:
        Containers: 9
         Running: 9
         Paused: 0
         Stopped: 0
        Images: 79
        Server Version: 20.10.8
        Storage Driver: overlay2
         Backing Filesystem: extfs
         Supports d_type: true
         Native Overlay Diff: true
         userxattr: false
        Logging Driver: json-file
        Cgroup Driver: systemd
        Cgroup Version: 2
        Plugins:
         Volume: local
         Network: bridge host ipvlan macvlan null overlay
         Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
        Swarm: inactive
        Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
        Default Runtime: runc
        Init Binary: docker-init
        containerd version: 8848fdb7c4ae3815afcc990a8a99d663dda1b590
        runc version: v1.0.2-0-g52b36a2
        init version: de40ad0
        Security Options:
         apparmor
         seccomp
          Profile: default
         cgroupns
        Kernel Version: 5.10.0-8-amd64
        Operating System: Debian GNU/Linux 11 (bullseye)
        OSType: linux
        Architecture: x86_64
        CPUs: 2
        Total Memory: 7.771GiB
        Name: v220210114110140000
        ID: PXLC:23R5:4TFC:SVEZ:V63E:CLZD:YRZC:4YB2:BB6G:OVJ4:AD64:3UUA
        Docker Root Dir: /var/lib/docker
        Debug Mode: false
        Registry: https://index.docker.io/v1/
        Labels:
        Experimental: false
        Insecure Registries:
         127.0.0.0/8
        Live Restore Enabled: false

-----> git version: git version 2.30.2
-----> sigil version: 0.6.0
-----> herokuish version:
       herokuish: 0.5.30
       buildpacks:
         heroku-buildpack-multi     v1.0.0
         heroku-buildpack-ruby      v228
         heroku-buildpack-nodejs    v185
         heroku-buildpack-clojure   v87
         heroku-buildpack-python    v197
         heroku-buildpack-java      v69
         heroku-buildpack-gradle    v35
         heroku-buildpack-scala     v90
         heroku-buildpack-play      v26
         heroku-buildpack-php       v196
         heroku-buildpack-go        v153
         buildpack-nginx            v14
         buildpack-null             v3
-----> dokku version: dokku version 0.25.4
-----> plugn version: plugn: 0.6.1
-----> dokku plugins:
         00_dokku-standard    0.25.4 enabled    dokku core standard plugin
         20_events            0.25.4 enabled    dokku core events logging plugin
         app-json             0.25.4 enabled    dokku core app-json plugin
         apps                 0.25.4 enabled    dokku core apps plugin
         builder              0.25.4 enabled    dokku core builder plugin
         builder-dockerfile   0.25.4 enabled    dokku core builder-dockerfile plugin
         builder-herokuish    0.25.4 enabled    dokku core builder-herokuish plugin
         builder-null         0.25.4 enabled    dokku core builder-null plugin
         builder-pack         0.25.4 enabled    dokku core builder-pack plugin
         buildpacks           0.25.4 enabled    dokku core buildpacks plugin
         certs                0.25.4 enabled    dokku core certificate management plugin
         checks               0.25.4 enabled    dokku core checks plugin
         common               0.25.4 enabled    dokku core common plugin
         config               0.25.4 enabled    dokku core config plugin
         cron                 0.25.4 enabled    dokku core cron plugin
         docker-options       0.25.4 enabled    dokku core docker-options plugin
         domains              0.25.4 enabled    dokku core domains plugin
         enter                0.25.4 enabled    dokku core enter plugin
         git                  0.25.4 enabled    dokku core git plugin
         letsencrypt          0.12.1 enabled    Automated installation of let's encrypt TLS certificates
         logs                 0.25.4 enabled    dokku core logs plugin
         network              0.25.4 enabled    dokku core network plugin
         nginx-vhosts         0.25.4 enabled    dokku core nginx-vhosts plugin
         plugin               0.25.4 enabled    dokku core plugin plugin
         postgres             1.14.1 enabled    dokku postgres service plugin
         proxy                0.25.4 enabled    dokku core proxy plugin
         ps                   0.25.4 enabled    dokku core ps plugin
         registry             0.25.4 enabled    dokku core registry plugin
         repo                 0.25.4 enabled    dokku core repo plugin
         resource             0.25.4 enabled    dokku core resource plugin
         run                  0.25.4 enabled    dokku core run plugin
         scheduler-docker-local 0.25.4 enabled    dokku core scheduler-docker-local plugin
         scheduler-null       0.25.4 enabled    dokku core scheduler-null plugin
         shell                0.25.4 enabled    dokku core shell plugin
         ssh-keys             0.25.4 enabled    dokku core ssh-keys plugin
         storage              0.25.4 enabled    dokku core storage plugin
         tags                 0.25.4 enabled    dokku core tags plugin
         tar                  0.25.4 enabled    dokku core tar plugin
         trace                0.25.4 enabled    dokku core trace plugin

docker logs dokku.postgres.test-db-2

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 "C".
The default database encoding has accordingly been set to "SQL_ASCII".
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
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.
syncing data to disk ... ok

Success. You can now start the database server using:

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

waiting for server to start....2021-10-06 06:43:23.182 UTC [50] LOG:  starting PostgreSQL 13.4 (Debian 13.4-4.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2021-10-06 06:43:23.183 UTC [50] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-10-06 06:43:23.185 UTC [51] LOG:  database system was shut down at 2021-10-06 06:43:23 UTC
2021-10-06 06:43:23.188 UTC [50] LOG:  database system is ready to accept connections
 done
server started

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

waiting for server to shut down...2021-10-06 06:43:23.296 UTC [50] LOG:  received fast shutdown request
.2021-10-06 06:43:23.297 UTC [50] LOG:  aborting any active transactions
2021-10-06 06:43:23.298 UTC [50] LOG:  background worker "logical replication launcher" (PID 57) exited with exit code 1
2021-10-06 06:43:23.298 UTC [52] LOG:  shutting down
2021-10-06 06:43:23.306 UTC [50] LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

2021-10-06 06:43:23.411 UTC [1] LOG:  starting PostgreSQL 13.4 (Debian 13.4-4.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2021-10-06 06:43:23.411 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-10-06 06:43:23.411 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2021-10-06 06:43:23.412 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-10-06 06:43:23.415 UTC [62] LOG:  database system was shut down at 2021-10-06 06:43:23 UTC
2021-10-06 06:43:23.418 UTC [1] LOG:  database system is ready to accept connections
2021-10-06 06:43:23.958 UTC [79] ERROR:  new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
2021-10-06 06:43:23.958 UTC [79] HINT:  Use the same encoding as in the template database, or use template0 as template.
2021-10-06 06:43:23.958 UTC [79] STATEMENT:  CREATE DATABASE test_db_2 ENCODING 'utf8';
2021-10-06 06:43:24.035 UTC [1] LOG:  received fast shutdown request
2021-10-06 06:43:24.036 UTC [1] LOG:  aborting any active transactions
2021-10-06 06:43:24.039 UTC [1] LOG:  background worker "logical replication launcher" (PID 68) exited with exit code 1
2021-10-06 06:43:24.039 UTC [63] LOG:  shutting down
2021-10-06 06:43:24.046 UTC [1] LOG:  database system is shut down

PostgreSQL Database directory appears to contain a database; Skipping initialization

2021-10-06 06:43:25.890 UTC [1] LOG:  starting PostgreSQL 13.4 (Debian 13.4-4.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2021-10-06 06:43:25.890 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-10-06 06:43:25.890 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2021-10-06 06:43:25.892 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-10-06 06:43:25.896 UTC [27] LOG:  database system was shut down at 2021-10-06 06:43:24 UTC
2021-10-06 06:43:25.901 UTC [1] LOG:  database system is ready to accept connections
josegonzalez commented 2 years ago

Can you show the output of dokku report as well?

Additionally, the log output of dokku --trace postgres:create test-db-1 (when test-db-1 doesn't exist of course) and the output ofdocker logs dokku.postgres.test-db-1 would be helpful.

timaschew commented 2 years ago

I've updated it. Note: in my setup the broken db is called test-db-2 (test-db-1 is ok, because it was created without --custom-env)

josegonzalez commented 2 years ago

When creating that test db via trace, can you try for a name that doesn't exist? Use the same name when fetching logs please.

timaschew commented 2 years ago

//edited: this comment is probably useless, it shows the happy path (everything works here)

dokku --trace postgres:create test-db-3

+ export DOKKU_HOST_ROOT=/home/dokku
+ DOKKU_HOST_ROOT=/home/dokku
+ export DOKKU_DISTRO
++ . /etc/os-release
++ echo debian
+ DOKKU_DISTRO=debian
+ export DOCKER_BIN=docker
+ DOCKER_BIN=docker
+ export DOKKU_IMAGE=gliderlabs/herokuish:latest-20
+ DOKKU_IMAGE=gliderlabs/herokuish:latest-20
+ export DOKKU_CNB_BUILDER=heroku/buildpacks
+ DOKKU_CNB_BUILDER=heroku/buildpacks
+ export DOKKU_LIB_ROOT=/var/lib/dokku
+ DOKKU_LIB_ROOT=/var/lib/dokku
+ export PLUGIN_PATH=/var/lib/dokku/plugins
+ PLUGIN_PATH=/var/lib/dokku/plugins
+ export PLUGIN_AVAILABLE_PATH=/var/lib/dokku/plugins/available
+ PLUGIN_AVAILABLE_PATH=/var/lib/dokku/plugins/available
+ export PLUGIN_ENABLED_PATH=/var/lib/dokku/plugins/enabled
+ PLUGIN_ENABLED_PATH=/var/lib/dokku/plugins/enabled
+ export PLUGIN_CORE_PATH=/var/lib/dokku/core-plugins
+ PLUGIN_CORE_PATH=/var/lib/dokku/core-plugins
+ export PLUGIN_CORE_AVAILABLE_PATH=/var/lib/dokku/core-plugins/available
+ PLUGIN_CORE_AVAILABLE_PATH=/var/lib/dokku/core-plugins/available
+ export PLUGIN_CORE_ENABLED_PATH=/var/lib/dokku/core-plugins/enabled
+ PLUGIN_CORE_ENABLED_PATH=/var/lib/dokku/core-plugins/enabled
+ export DOKKU_SYSTEM_GROUP=dokku
+ DOKKU_SYSTEM_GROUP=dokku
+ export DOKKU_SYSTEM_USER=dokku
+ DOKKU_SYSTEM_USER=dokku
+ export DOKKU_API_VERSION=1
+ DOKKU_API_VERSION=1
+ export DOKKU_NOT_IMPLEMENTED_EXIT=10
+ DOKKU_NOT_IMPLEMENTED_EXIT=10
+ export DOKKU_VALID_EXIT=0
+ DOKKU_VALID_EXIT=0
+ export DOKKU_PID=2016421
+ DOKKU_PID=2016421
+ export DOKKU_LOGS_DIR=/var/log/dokku
+ DOKKU_LOGS_DIR=/var/log/dokku
+ export DOKKU_LOGS_HOST_DIR=/var/log/dokku
+ DOKKU_LOGS_HOST_DIR=/var/log/dokku
+ export DOKKU_EVENTS_LOGFILE=/var/log/dokku/events.log
+ DOKKU_EVENTS_LOGFILE=/var/log/dokku/events.log
+ export DOKKU_CONTAINER_LABEL=dokku
+ DOKKU_CONTAINER_LABEL=dokku
+ export 'DOKKU_GLOBAL_BUILD_ARGS=--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=dokku'
+ DOKKU_GLOBAL_BUILD_ARGS='--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=dokku'
+ export 'DOKKU_GLOBAL_RUN_ARGS=--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=dokku'
+ DOKKU_GLOBAL_RUN_ARGS='--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=dokku'
+ source /var/lib/dokku/core-plugins/available/common/functions
++ set -eo pipefail
++ [[ -n 1 ]]
++ set -x
+ parse_args postgres:create test-db-3
+ declare 'desc=top-level cli arg parser'
+ local next_index=1
+ local skip=false
+ args=('postgres:create' 'test-db-3')
+ local args
+ local flags
+ for arg in "$@"
+ [[ false == \t\r\u\e ]]
+ case "$arg" in
+ [[ false == \t\r\u\e ]]
+ [[ postgres:create == \-\-\a\p\p ]]
+ [[ postgres:create =~ ^--.* ]]
+ next_index=2
+ for arg in "$@"
+ [[ false == \t\r\u\e ]]
+ case "$arg" in
+ [[ false == \t\r\u\e ]]
+ [[ test-db-3 == \-\-\a\p\p ]]
+ [[ test-db-3 =~ ^--.* ]]
+ next_index=3
+ [[ -z --trace ]]
+ return 0
+ args=("$@")
+ skip_arg=false
+ [[ postgres:create =~ ^--.* ]]
+ has_tty
+ declare 'desc=return 0 if we have a tty'
+ [[ '' == \t\r\u\e ]]
++ LC_ALL=C
++ /usr/bin/tty
+ [[ /dev/pts/0 == \n\o\t\ \a\ \t\t\y ]]
+ return 0
++ id -un
+ [[ dokku != \d\o\k\k\u ]]
+ [[ postgres:create =~ ^plugin:.* ]]
+ [[ postgres:create == \s\s\h\-\k\e\y\s\:\a\d\d ]]
+ [[ postgres:create == \s\s\h\-\k\e\y\s\:\r\e\m\o\v\e ]]
+ [[ -n '' ]]
+ dokku_auth postgres:create test-db-3
+ declare 'desc=calls user-auth plugin trigger'
+ export SSH_USER=admin
+ SSH_USER=admin
+ export SSH_NAME=default
+ SSH_NAME=default
++ wc -l
++ find /var/lib/dokku/plugins/enabled/20_events/user-auth
+ local user_auth_count=1
+ [[ 1 == 0 ]]
+ [[ 1 == 1 ]]
+ [[ -f /var/lib/dokku/plugins/enabled/20_events/user-auth ]]
+ return 0
+ case "$1" in
+ execute_dokku_cmd postgres:create test-db-3
+ declare 'desc=executes dokku sub-commands'
+ local PLUGIN_NAME=postgres:create
+ local PLUGIN_CMD=postgres:create
+ local implemented=0
+ local script
+ argv=('postgres:create' 'test-db-3')
+ local argv
+ case "$PLUGIN_NAME" in
++ readlink -f /var/lib/dokku/plugins/enabled/postgres
+ [[ /var/lib/dokku/plugins/available/postgres == *core-plugins* ]]
+ [[ -x /var/lib/dokku/plugins/enabled/postgres:create/subcommands/default ]]
+ [[ -x /var/lib/dokku/plugins/enabled/postgres:create/subcommands/postgres:create ]]
+ [[ -x /var/lib/dokku/plugins/enabled/postgres/subcommands/create ]]
+ [[ -n create ]]
+ /var/lib/dokku/plugins/enabled/postgres/subcommands/create postgres:create test-db-3
+ source /var/lib/dokku/plugins/enabled/common/functions
++ set -eo pipefail
++ [[ -n 1 ]]
++ set -x
++++ dirname /var/lib/dokku/plugins/enabled/postgres/subcommands/create
+++ cd /var/lib/dokku/plugins/enabled/postgres/subcommands
+++ pwd
++ dirname /var/lib/dokku/plugins/enabled/postgres/subcommands
+ source /var/lib/dokku/plugins/enabled/postgres/functions
++++ dirname /var/lib/dokku/plugins/enabled/postgres/functions
+++ cd /var/lib/dokku/plugins/enabled/postgres
+++ pwd
++ source /var/lib/dokku/plugins/enabled/postgres/config
+++++ dirname /var/lib/dokku/plugins/enabled/postgres/config
++++ cd /var/lib/dokku/plugins/enabled/postgres
++++ pwd
+++ _DIR=/var/lib/dokku/plugins/enabled/postgres
+++ export POSTGRES_IMAGE=postgres
+++ POSTGRES_IMAGE=postgres
+++ export POSTGRES_IMAGE_VERSION=13.4
+++ POSTGRES_IMAGE_VERSION=13.4
+++ export POSTGRES_ROOT=/var/lib/dokku/services/postgres
+++ POSTGRES_ROOT=/var/lib/dokku/services/postgres
+++ export POSTGRES_HOST_ROOT=/var/lib/dokku/services/postgres
+++ POSTGRES_HOST_ROOT=/var/lib/dokku/services/postgres
+++ PLUGIN_UNIMPLEMENTED_SUBCOMMANDS=()
+++ export PLUGIN_UNIMPLEMENTED_SUBCOMMANDS
+++ export PLUGIN_COMMAND_PREFIX=postgres
+++ PLUGIN_COMMAND_PREFIX=postgres
+++ export PLUGIN_CONFIG_ROOT=/var/lib/dokku/config/postgres
+++ PLUGIN_CONFIG_ROOT=/var/lib/dokku/config/postgres
+++ export PLUGIN_DATA_ROOT=/var/lib/dokku/services/postgres
+++ PLUGIN_DATA_ROOT=/var/lib/dokku/services/postgres
+++ export PLUGIN_DATA_HOST_ROOT=/var/lib/dokku/services/postgres
+++ PLUGIN_DATA_HOST_ROOT=/var/lib/dokku/services/postgres
+++ PLUGIN_DATASTORE_PORTS=('5432')
+++ export PLUGIN_DATASTORE_PORTS
+++ export PLUGIN_DATASTORE_WAIT_PORT=5432
+++ PLUGIN_DATASTORE_WAIT_PORT=5432
+++ export PLUGIN_DEFAULT_ALIAS=DATABASE
+++ PLUGIN_DEFAULT_ALIAS=DATABASE
+++ export PLUGIN_DISABLE_PULL=
+++ PLUGIN_DISABLE_PULL=
+++ export PLUGIN_DISABLE_PULL_VARIABLE=POSTGRES_DISABLE_PULL
+++ PLUGIN_DISABLE_PULL_VARIABLE=POSTGRES_DISABLE_PULL
+++ export PLUGIN_ALT_ALIAS=DOKKU_POSTGRES
+++ PLUGIN_ALT_ALIAS=DOKKU_POSTGRES
+++ export PLUGIN_IMAGE=postgres
+++ PLUGIN_IMAGE=postgres
+++ export PLUGIN_IMAGE_VERSION=13.4
+++ PLUGIN_IMAGE_VERSION=13.4
+++ export PLUGIN_SCHEME=postgres
+++ PLUGIN_SCHEME=postgres
+++ export PLUGIN_SERVICE=Postgres
+++ PLUGIN_SERVICE=Postgres
+++ export PLUGIN_VARIABLE=POSTGRES
+++ PLUGIN_VARIABLE=POSTGRES
+++ export PLUGIN_BASE_PATH=/var/lib/dokku/plugins
+++ PLUGIN_BASE_PATH=/var/lib/dokku/plugins
+++ export PLUGIN_CONFIG_SUFFIX=data
+++ PLUGIN_CONFIG_SUFFIX=data
+++ [[ -n 1 ]]
+++ export PLUGIN_BASE_PATH=/var/lib/dokku/plugins/enabled
+++ PLUGIN_BASE_PATH=/var/lib/dokku/plugins/enabled
+++ export PLUGIN_BUSYBOX_IMAGE=busybox:1.31.1-uclibc
+++ PLUGIN_BUSYBOX_IMAGE=busybox:1.31.1-uclibc
+++ export PLUGIN_AMBASSADOR_IMAGE=dokku/ambassador:0.3.3
+++ PLUGIN_AMBASSADOR_IMAGE=dokku/ambassador:0.3.3
+++ export PLUGIN_S3BACKUP_IMAGE=dokku/s3backup:0.10.3
+++ PLUGIN_S3BACKUP_IMAGE=dokku/s3backup:0.10.3
+++ export PLUGIN_WAIT_IMAGE=dokku/wait:0.4.3
+++ PLUGIN_WAIT_IMAGE=dokku/wait:0.4.3
+++ export POSTGRES_CONFIG_OPTIONS=
+++ POSTGRES_CONFIG_OPTIONS=
++ set -eo pipefail
++ [[ -n 1 ]]
++ set -x
++++ dirname /var/lib/dokku/plugins/enabled/postgres/functions
+++ cd /var/lib/dokku/plugins/enabled/postgres
+++ pwd
++ source /var/lib/dokku/plugins/enabled/postgres/common-functions
+++++ dirname /var/lib/dokku/plugins/enabled/postgres/common-functions
++++ cd /var/lib/dokku/plugins/enabled/postgres
++++ pwd
+++ source /var/lib/dokku/plugins/enabled/postgres/config
++++++ dirname /var/lib/dokku/plugins/enabled/postgres/config
+++++ cd /var/lib/dokku/plugins/enabled/postgres
+++++ pwd
++++ _DIR=/var/lib/dokku/plugins/enabled/postgres
++++ export POSTGRES_IMAGE=postgres
++++ POSTGRES_IMAGE=postgres
++++ export POSTGRES_IMAGE_VERSION=13.4
++++ POSTGRES_IMAGE_VERSION=13.4
++++ export POSTGRES_ROOT=/var/lib/dokku/services/postgres
++++ POSTGRES_ROOT=/var/lib/dokku/services/postgres
++++ export POSTGRES_HOST_ROOT=/var/lib/dokku/services/postgres
++++ POSTGRES_HOST_ROOT=/var/lib/dokku/services/postgres
++++ PLUGIN_UNIMPLEMENTED_SUBCOMMANDS=()
++++ export PLUGIN_UNIMPLEMENTED_SUBCOMMANDS
++++ export PLUGIN_COMMAND_PREFIX=postgres
++++ PLUGIN_COMMAND_PREFIX=postgres
++++ export PLUGIN_CONFIG_ROOT=/var/lib/dokku/config/postgres
++++ PLUGIN_CONFIG_ROOT=/var/lib/dokku/config/postgres
++++ export PLUGIN_DATA_ROOT=/var/lib/dokku/services/postgres
++++ PLUGIN_DATA_ROOT=/var/lib/dokku/services/postgres
++++ export PLUGIN_DATA_HOST_ROOT=/var/lib/dokku/services/postgres
++++ PLUGIN_DATA_HOST_ROOT=/var/lib/dokku/services/postgres
++++ PLUGIN_DATASTORE_PORTS=('5432')
++++ export PLUGIN_DATASTORE_PORTS
++++ export PLUGIN_DATASTORE_WAIT_PORT=5432
++++ PLUGIN_DATASTORE_WAIT_PORT=5432
++++ export PLUGIN_DEFAULT_ALIAS=DATABASE
++++ PLUGIN_DEFAULT_ALIAS=DATABASE
++++ export PLUGIN_DISABLE_PULL=
++++ PLUGIN_DISABLE_PULL=
++++ export PLUGIN_DISABLE_PULL_VARIABLE=POSTGRES_DISABLE_PULL
++++ PLUGIN_DISABLE_PULL_VARIABLE=POSTGRES_DISABLE_PULL
++++ export PLUGIN_ALT_ALIAS=DOKKU_POSTGRES
++++ PLUGIN_ALT_ALIAS=DOKKU_POSTGRES
++++ export PLUGIN_IMAGE=postgres
++++ PLUGIN_IMAGE=postgres
++++ export PLUGIN_IMAGE_VERSION=13.4
++++ PLUGIN_IMAGE_VERSION=13.4
++++ export PLUGIN_SCHEME=postgres
++++ PLUGIN_SCHEME=postgres
++++ export PLUGIN_SERVICE=Postgres
++++ PLUGIN_SERVICE=Postgres
++++ export PLUGIN_VARIABLE=POSTGRES
++++ PLUGIN_VARIABLE=POSTGRES
++++ export PLUGIN_BASE_PATH=/var/lib/dokku/plugins
++++ PLUGIN_BASE_PATH=/var/lib/dokku/plugins
++++ export PLUGIN_CONFIG_SUFFIX=data
++++ PLUGIN_CONFIG_SUFFIX=data
++++ [[ -n 1 ]]
++++ export PLUGIN_BASE_PATH=/var/lib/dokku/plugins/enabled
++++ PLUGIN_BASE_PATH=/var/lib/dokku/plugins/enabled
++++ export PLUGIN_BUSYBOX_IMAGE=busybox:1.31.1-uclibc
++++ PLUGIN_BUSYBOX_IMAGE=busybox:1.31.1-uclibc
++++ export PLUGIN_AMBASSADOR_IMAGE=dokku/ambassador:0.3.3
++++ PLUGIN_AMBASSADOR_IMAGE=dokku/ambassador:0.3.3
++++ export PLUGIN_S3BACKUP_IMAGE=dokku/s3backup:0.10.3
++++ PLUGIN_S3BACKUP_IMAGE=dokku/s3backup:0.10.3
++++ export PLUGIN_WAIT_IMAGE=dokku/wait:0.4.3
++++ PLUGIN_WAIT_IMAGE=dokku/wait:0.4.3
++++ export POSTGRES_CONFIG_OPTIONS=
++++ POSTGRES_CONFIG_OPTIONS=
+++ set -eo pipefail
+++ [[ -n 1 ]]
+++ set -x
+++ source /var/lib/dokku/plugins/available/config/functions
++++ set -eo pipefail
++++ [[ -n 1 ]]
++++ set -x
++++ source /var/lib/dokku/core-plugins/available/common/functions
+++++ set -eo pipefail
+++++ [[ -n 1 ]]
+++++ set -x
++ source /var/lib/dokku/plugins/enabled/common/functions
+++ set -eo pipefail
+++ [[ -n 1 ]]
+++ set -x
++ source /var/lib/dokku/plugins/available/config/functions
+++ set -eo pipefail
+++ [[ -n 1 ]]
+++ set -x
+++ source /var/lib/dokku/core-plugins/available/common/functions
++++ set -eo pipefail
++++ [[ -n 1 ]]
++++ set -x
++ [[ -f /var/lib/dokku/plugins/available/docker-options/functions ]]
++ source /var/lib/dokku/plugins/available/docker-options/functions
+++ set -eo pipefail
+++ [[ -n 1 ]]
+++ set -x
+++ source /var/lib/dokku/core-plugins/available/common/functions
++++ set -eo pipefail
++++ [[ -n 1 ]]
++++ set -x
+++ AVAILABLE_PHASES=(build deploy run)
+ service-create-cmd postgres:create test-db-3
+ declare 'desc=create a Postgres service'
+ argv=('postgres:create' 'test-db-3')
+ local cmd=postgres:create argv
+ [[ postgres:create == \p\o\s\t\g\r\e\s\:\c\r\e\a\t\e ]]
+ shift 1
+ CREATE_FLAGS_LIST=()
+ declare SERVICE=test-db-3 CREATE_FLAGS_LIST
+ service_create test-db-3
+ local SERVICE=test-db-3
+ is_valid_service_name test-db-3
+ declare 'desc=validate a service name'
+ declare SERVICE=test-db-3
+ [[ -z test-db-3 ]]
+ [[ test-db-3 =~ ^[A-Za-z0-9_-]+$ ]]
+ return 0
+ [[ -z test-db-3 ]]
+ [[ ! -d /var/lib/dokku/services/postgres/test-db-3 ]]
+ SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-3
+ LINKS_FILE=/var/lib/dokku/services/postgres/test-db-3/LINKS
+ service_parse_args
+ declare 'desc=cli arg parser'
+ local next_index=1
+ local skip=false
+ args=()
+ local args
+ OPTIND=1
+ getopts a:c:C:d:i:I:m:p:q:R:r:s:u: opt
+ shift 0
+ service_image_exists test-db-3
+ declare 'desc=check if the current image exists'
+ declare SERVICE=test-db-3
+ local plugin_image=postgres
+ local plugin_image_version=13.4
+ [[ -f /var/lib/dokku/services/postgres/test-db-3/IMAGE ]]
+ [[ -f /var/lib/dokku/services/postgres/test-db-3/IMAGE_VERSION ]]
+ local IMAGE=postgres:13.4
++ docker images -q postgres:13.4
+ [[ cd4b5373985e == '' ]]
+ return 0
+ plugn trigger service-action pre-create test-db-3
+ mkdir -p /var/lib/dokku/services/postgres/test-db-3
+ mkdir -p /var/lib/dokku/services/postgres/test-db-3/data
+ touch /var/lib/dokku/services/postgres/test-db-3/LINKS
++ openssl rand -hex 16
+ PASSWORD=f3933f5bed23df5baa270f62a6d8bfc6
+ [[ -n '' ]]
+ echo f3933f5bed23df5baa270f62a6d8bfc6
+ chmod 640 /var/lib/dokku/services/postgres/test-db-3/PASSWORD
+ service_commit_config test-db-3
+ declare SERVICE=test-db-3
+ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-3
+ local CONFIG_VARIABLE=POSTGRES_CONFIG_OPTIONS
+ local ENV_VARIABLE=POSTGRES_CUSTOM_ENV
+ custom_env=
+ [[ -n '' ]]
+ [[ -n '' ]]
+ echo ''
+ config_options=
+ [[ -n '' ]]
+ [[ -n '' ]]
+ echo ''
+ [[ -n '' ]]
+ [[ -n '' ]]
+ [[ -n postgres ]]
+ echo postgres
+ [[ -n 13.4 ]]
+ echo 13.4
+ write_database_name test-db-3
+ declare 'desc=write a sanitized database name'
+ declare SERVICE=test-db-3
+ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-3
+ echo test-db-3
+ tr .- _
+ plugn trigger service-action post-create test-db-3
+ service_create_container test-db-3
+ local SERVICE=test-db-3
+ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-3
+ local SERVICE_HOST_ROOT=/var/lib/dokku/services/postgres/test-db-3
++ get_service_name test-db-3
++ declare 'desc=retrieve a docker service label'
++ declare SERVICE=test-db-3
++ echo dokku.postgres.test-db-3
+ local SERVICE_NAME=dokku.postgres.test-db-3
++ service_password test-db-3
++ declare 'desc=fetch the password for a service'
++ declare SERVICE=test-db-3
++ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-3
++ local PASSWORD_FILE=/var/lib/dokku/services/postgres/test-db-3/PASSWORD
++ [[ -f /var/lib/dokku/services/postgres/test-db-3/PASSWORD ]]
++ cat /var/lib/dokku/services/postgres/test-db-3/PASSWORD
+ local PASSWORD=f3933f5bed23df5baa270f62a6d8bfc6
++ get_database_name test-db-3
++ declare 'desc=retrieve a sanitized database name'
++ declare SERVICE=test-db-3
++ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-3
++ [[ ! -f /var/lib/dokku/services/postgres/test-db-3/DATABASE_NAME ]]
++ cat /var/lib/dokku/services/postgres/test-db-3/DATABASE_NAME
+ local DATABASE_NAME=test_db_3
+ local PREVIOUS_ID
+ [[ -f /var/lib/dokku/services/postgres/test-db-3/CONFIG_OPTIONS ]]
++ cat /var/lib/dokku/services/postgres/test-db-3/CONFIG_OPTIONS
+ export CONFIG_OPTIONS=
+ CONFIG_OPTIONS=
+ [[ -f /var/lib/dokku/services/postgres/test-db-3/SERVICE_MEMORY ]]
+ [[ -n '' ]]
+ [[ -f /var/lib/dokku/services/postgres/test-db-3/SHM_SIZE ]]
+ [[ -n '' ]]
+ [[ -f /var/lib/dokku/services/postgres/test-db-3/IMAGE ]]
++ cat /var/lib/dokku/services/postgres/test-db-3/IMAGE
+ PLUGIN_IMAGE=postgres
+ [[ -f /var/lib/dokku/services/postgres/test-db-3/IMAGE_VERSION ]]
++ cat /var/lib/dokku/services/postgres/test-db-3/IMAGE_VERSION
+ PLUGIN_IMAGE_VERSION=13.4
++ docker run --name dokku.postgres.test-db-3 -v /var/lib/dokku/services/postgres/test-db-3/data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=f3933f5bed23df5baa270f62a6d8bfc6 --env-file=/var/lib/dokku/services/postgres/test-db-3/ENV -d --restart always --label dokku=service --label dokku.service=postgres postgres:13.4
+ ID=78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac
+ echo 78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac
+ dokku_log_verbose_quiet 'Waiting for container to be ready'
+ declare 'desc=log verbose formatter (with quiet option)'
+ [[ -z '' ]]
+ echo '       Waiting for container to be ready'
       Waiting for container to be ready
+ docker run --rm --link dokku.postgres.test-db-3:postgres dokku/wait:0.4.3 -p 5432
+ dokku_log_verbose_quiet 'Creating container database'
+ declare 'desc=log verbose formatter (with quiet option)'
+ [[ -z '' ]]
+ echo '       Creating container database'
       Creating container database
+ docker exec dokku.postgres.test-db-3 su - postgres -c 'createdb -E utf8 test_db_3'
+ dokku_log_verbose_quiet 'Securing connection to database'
+ declare 'desc=log verbose formatter (with quiet option)'
+ [[ -z '' ]]
+ echo '       Securing connection to database'
       Securing connection to database
+ service_stop test-db-3
+ declare 'desc=stop a running service'
+ declare SERVICE=test-db-3
+ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-3
++ get_service_name test-db-3
++ declare 'desc=retrieve a docker service label'
++ declare SERVICE=test-db-3
++ echo dokku.postgres.test-db-3
+ local SERVICE_NAME=dokku.postgres.test-db-3
++ docker ps -aq --no-trunc --filter 'name=^/dokku.postgres.test-db-3$' --format '{{ .ID }}'
+ local ID=78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac
+ [[ -z 78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac ]]
+ [[ -n 78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac ]]
+ dokku_log_info2_quiet 'Stopping container'
+ declare 'desc=log info2 formatter (with quiet option)'
+ [[ -z '' ]]
+ echo '=====> Stopping container'
+ docker stop dokku.postgres.test-db-3
+ service_port_pause test-db-3
+ declare 'desc=pause service exposure'
+ declare SERVICE=test-db-3 LOG_FAIL=
+ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-3
++ get_service_name test-db-3
++ declare 'desc=retrieve a docker service label'
++ declare SERVICE=test-db-3
++ echo dokku.postgres.test-db-3
+ local EXPOSED_NAME=dokku.postgres.test-db-3.ambassador
+ local PORT_FILE=/var/lib/dokku/services/postgres/test-db-3/PORT
+ [[ '' == \t\r\u\e ]]
+ [[ ! -f /var/lib/dokku/services/postgres/test-db-3/PORT ]]
+ return 0
+ dokku_log_verbose_quiet 'Container stopped'
+ declare 'desc=log verbose formatter (with quiet option)'
+ [[ -z '' ]]
+ echo '       Container stopped'
+ docker run --rm -i -v /var/lib/dokku/services/postgres/test-db-3/data:/var/lib/postgresql/data postgres:13.4 bash -s
+++ dirname /var/lib/dokku/plugins/enabled/postgres/functions
++ cd /var/lib/dokku/plugins/enabled/postgres
++ pwd
++ docker ps -aq --no-trunc --filter status=exited --filter 'name=^/dokku.postgres.test-db-3$' --format '{{ .ID }}'
+ PREVIOUS_ID=78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac
+ docker start 78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac
+ service_port_unpause test-db-3
+ declare 'desc=start service exposure'
+ declare SERVICE=test-db-3 LOG_FAIL=
+ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-3
++ get_service_name test-db-3
++ declare 'desc=retrieve a docker service label'
++ declare SERVICE=test-db-3
++ echo dokku.postgres.test-db-3
+ local SERVICE_NAME=dokku.postgres.test-db-3
+ local EXPOSED_NAME=dokku.postgres.test-db-3.ambassador
+ local PORT_FILE=/var/lib/dokku/services/postgres/test-db-3/PORT
+ PORTS=()
+ local PORTS
+ PORTS=(${PORTS[@]:-$(get_random_ports ${#PLUGIN_DATASTORE_PORTS[@]})})
++ get_random_ports 1
++ declare 'desc=retrieve N random ports'
++ declare iterations=1
++ (( i = 0 ))
++ (( i < iterations ))
++ local port=22776
++ local quit=0
++ '[' 0 -ne 1 ']'
++ netstat -an
++ grep 22776
++ '[' 1 -gt 0 ']'
++ quit=1
++ '[' 1 -ne 1 ']'
++ echo 22776
++ (( i++ ))
++ (( i < iterations ))
++ cat /var/lib/dokku/services/postgres/test-db-3/ID
+ local ID=78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac
+ [[ 1 != \1 ]]
+ [[ '' == \t\r\u\e ]]
+ [[ ! -f /var/lib/dokku/services/postgres/test-db-3/PORT ]]
+ return 0
+ dokku_log_info2 'Postgres container created: test-db-3'
+ declare 'desc=log info2 formatter'
+ echo '=====> Postgres container created: test-db-3'
=====> Postgres container created: test-db-3
+ service_info test-db-3
+ declare 'desc=retrieve information about a given service'
+ declare SERVICE=test-db-3 INFO_FLAG=
+ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-3
++ service_url test-db-3
++ local SERVICE=test-db-3
+++ service_dns_hostname test-db-3
+++ declare 'desc=retrieve the alias of a service'
+++ declare SERVICE=test-db-3
++++ get_service_name test-db-3
++++ declare 'desc=retrieve a docker service label'
++++ declare SERVICE=test-db-3
++++ echo dokku.postgres.test-db-3
+++ local SERVICE_NAME=dokku.postgres.test-db-3
+++ echo dokku.postgres.test-db-3
+++ tr ._ -
++ local SERVICE_DNS_HOSTNAME=dokku-postgres-test-db-3
+++ get_database_name test-db-3
+++ declare 'desc=retrieve a sanitized database name'
+++ declare SERVICE=test-db-3
+++ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-3
+++ [[ ! -f /var/lib/dokku/services/postgres/test-db-3/DATABASE_NAME ]]
+++ cat /var/lib/dokku/services/postgres/test-db-3/DATABASE_NAME
++ local DATABASE_NAME=test_db_3
+++ service_password test-db-3
+++ declare 'desc=fetch the password for a service'
+++ declare SERVICE=test-db-3
+++ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-3
+++ local PASSWORD_FILE=/var/lib/dokku/services/postgres/test-db-3/PASSWORD
+++ [[ -f /var/lib/dokku/services/postgres/test-db-3/PASSWORD ]]
+++ cat /var/lib/dokku/services/postgres/test-db-3/PASSWORD
++ local PASSWORD=f3933f5bed23df5baa270f62a6d8bfc6
++ echo postgres://postgres:f3933f5bed23df5baa270f62a6d8bfc6@dokku-postgres-test-db-3:5432/test_db_3
+ local SERVICE_URL=postgres://postgres:f3933f5bed23df5baa270f62a6d8bfc6@dokku-postgres-test-db-3:5432/test_db_3
+ local PORT_FILE=/var/lib/dokku/services/postgres/test-db-3/PORT
++ cat /var/lib/dokku/services/postgres/test-db-3/ID
+ local SERVICE_CONTAINER_ID=78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac
+ local flag key valid_flags
++ cat /var/lib/dokku/services/postgres/test-db-3/CONFIG_OPTIONS
++ service_exposed_ports test-db-3
++ declare 'desc=list exposed ports for a service'
++ declare SERVICE=test-db-3
++ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-3
++ local PORT_FILE=/var/lib/dokku/services/postgres/test-db-3/PORT
++ [[ ! -f /var/lib/dokku/services/postgres/test-db-3/PORT ]]
++ echo -
++ return 0
++ get_container_ip 78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac
++ declare 'desc=retrieve the ip address of a container'
++ declare CONTAINER_ID=78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac
++ docker inspect --format '{{ .NetworkSettings.IPAddress }}' 78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac
++ service_linked_apps test-db-3
++ declare 'desc=list all apps linked to a service for info output'
++ declare SERVICE=test-db-3
++ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-3
++ local LINKS_FILE=/var/lib/dokku/services/postgres/test-db-3/LINKS
++ touch /var/lib/dokku/services/postgres/test-db-3/LINKS
++ [[ -z '' ]]
++ echo -
++ return 0
++ service_status test-db-3
++ declare 'desc=display the status of a service'
++ declare SERVICE=test-db-3
++ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-3
+++ cat /var/lib/dokku/services/postgres/test-db-3/ID
++ local ID=78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac
++ local CONTAINER_STATUS
+++ docker inspect -f '{{.State.Status}}' 78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac
++ CONTAINER_STATUS=running
++ [[ -n running ]]
++ echo running
++ return 0
++ service_version test-db-3
++ declare 'desc=display the running version for an image'
++ declare SERVICE=test-db-3
+++ get_service_name test-db-3
+++ declare 'desc=retrieve a docker service label'
+++ declare SERVICE=test-db-3
+++ echo dokku.postgres.test-db-3
++ local SERVICE_NAME=dokku.postgres.test-db-3
++ docker inspect -f '{{.Config.Image}}' dokku.postgres.test-db-3
+ flag_map=('--config-dir: /var/lib/dokku/services/postgres/test-db-3/data' '--config-options: ' '--data-dir: /var/lib/dokku/services/postgres/test-db-3/data' '--dsn: postgres://postgres:f3933f5bed23df5baa270f62a6d8bfc6@dokku-postgres-test-db-3:5432/test_db_3' '--exposed-ports: -' '--id: 78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac' '--internal-ip: 172.17.0.9' '--links: -' '--service-root: /var/lib/dokku/services/postgres/test-db-3' '--status: running' '--version: postgres:13.4')
+ local flag_map
+ [[ -z '' ]]
+ dokku_log_info2 'test-db-3 postgres service information'
+ declare 'desc=log info2 formatter'
+ echo '=====> test-db-3 postgres service information'
=====> test-db-3 postgres service information
+ for flag in "${flag_map[@]}"
++ echo 'config-dir: /var/lib/dokku/services/postgres/test-db-3/data'
++ cut -f1 '-d '
++ tr - ' '
+ key='config dir:'
++ printf '%-20s %-25s' 'Config dir:' /var/lib/dokku/services/postgres/test-db-3/data
+ dokku_log_verbose 'Config dir:          /var/lib/dokku/services/postgres/test-db-3/data'
+ declare 'desc=log verbose formatter'
+ echo '       Config dir:          /var/lib/dokku/services/postgres/test-db-3/data'
       Config dir:          /var/lib/dokku/services/postgres/test-db-3/data
+ for flag in "${flag_map[@]}"
++ cut -f1 '-d '
++ echo 'config-options: '
++ tr - ' '
+ key='config options:'
++ printf '%-20s %-25s' 'Config options:' ''
+ dokku_log_verbose 'Config options:                               '
+ declare 'desc=log verbose formatter'
+ echo '       Config options:                               '
       Config options:
+ for flag in "${flag_map[@]}"
++ echo 'data-dir: /var/lib/dokku/services/postgres/test-db-3/data'
++ tr - ' '
++ cut -f1 '-d '
+ key='data dir:'
++ printf '%-20s %-25s' 'Data dir:' /var/lib/dokku/services/postgres/test-db-3/data
+ dokku_log_verbose 'Data dir:            /var/lib/dokku/services/postgres/test-db-3/data'
+ declare 'desc=log verbose formatter'
+ echo '       Data dir:            /var/lib/dokku/services/postgres/test-db-3/data'
       Data dir:            /var/lib/dokku/services/postgres/test-db-3/data
+ for flag in "${flag_map[@]}"
++ echo 'dsn: postgres://postgres:f3933f5bed23df5baa270f62a6d8bfc6@dokku-postgres-test-db-3:5432/test_db_3'
++ cut -f1 '-d '
++ tr - ' '
+ key=dsn:
++ printf '%-20s %-25s' Dsn: postgres://postgres:f3933f5bed23df5baa270f62a6d8bfc6@dokku-postgres-test-db-3:5432/test_db_3
+ dokku_log_verbose 'Dsn:                 postgres://postgres:f3933f5bed23df5baa270f62a6d8bfc6@dokku-postgres-test-db-3:5432/test_db_3'
+ declare 'desc=log verbose formatter'
+ echo '       Dsn:                 postgres://postgres:f3933f5bed23df5baa270f62a6d8bfc6@dokku-postgres-test-db-3:5432/test_db_3'
       Dsn:                 postgres://postgres:f3933f5bed23df5baa270f62a6d8bfc6@dokku-postgres-test-db-3:5432/test_db_3
+ for flag in "${flag_map[@]}"
++ echo 'exposed-ports: -'
++ cut -f1 '-d '
++ tr - ' '
+ key='exposed ports:'
++ printf '%-20s %-25s' 'Exposed ports:' -
+ dokku_log_verbose 'Exposed ports:       -                        '
+ declare 'desc=log verbose formatter'
+ echo '       Exposed ports:       -                        '
       Exposed ports:       -
+ for flag in "${flag_map[@]}"
++ echo 'id: 78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac'
++ cut -f1 '-d '
++ tr - ' '
+ key=id:
++ printf '%-20s %-25s' Id: 78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac
+ dokku_log_verbose 'Id:                  78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac'
+ declare 'desc=log verbose formatter'
+ echo '       Id:                  78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac'
       Id:                  78c62ebeb53e8b042c3202c4ff83be643b685d030a2294df9dc73d0d376be1ac
+ for flag in "${flag_map[@]}"
++ echo 'internal-ip: 172.17.0.9'
++ cut -f1 '-d '
++ tr - ' '
+ key='internal ip:'
++ printf '%-20s %-25s' 'Internal ip:' 172.17.0.9
+ dokku_log_verbose 'Internal ip:         172.17.0.9               '
+ declare 'desc=log verbose formatter'
+ echo '       Internal ip:         172.17.0.9               '
       Internal ip:         172.17.0.9
+ for flag in "${flag_map[@]}"
++ echo 'links: -'
++ cut -f1 '-d '
++ tr - ' '
+ key=links:
++ printf '%-20s %-25s' Links: -
+ dokku_log_verbose 'Links:               -                        '
+ declare 'desc=log verbose formatter'
+ echo '       Links:               -                        '
       Links:               -
+ for flag in "${flag_map[@]}"
++ echo 'service-root: /var/lib/dokku/services/postgres/test-db-3'
++ cut -f1 '-d '
++ tr - ' '
+ key='service root:'
++ printf '%-20s %-25s' 'Service root:' /var/lib/dokku/services/postgres/test-db-3
+ dokku_log_verbose 'Service root:        /var/lib/dokku/services/postgres/test-db-3'
+ declare 'desc=log verbose formatter'
+ echo '       Service root:        /var/lib/dokku/services/postgres/test-db-3'
       Service root:        /var/lib/dokku/services/postgres/test-db-3
+ for flag in "${flag_map[@]}"
++ echo 'status: running'
++ cut -f1 '-d '
++ tr - ' '
+ key=status:
++ printf '%-20s %-25s' Status: running
+ dokku_log_verbose 'Status:              running                  '
+ declare 'desc=log verbose formatter'
+ echo '       Status:              running                  '
       Status:              running
+ for flag in "${flag_map[@]}"
++ echo 'version: postgres:13.4'
++ cut -f1 '-d '
++ tr - ' '
+ key=version:
++ printf '%-20s %-25s' Version: postgres:13.4
+ dokku_log_verbose 'Version:             postgres:13.4            '
+ declare 'desc=log verbose formatter'
+ echo '       Version:             postgres:13.4            '
       Version:             postgres:13.4
+ plugn trigger service-action post-create-complete test-db-3
+ implemented=1
+ [[ 1 -eq 0 ]]
+ [[ 1 -eq 0 ]]

docker logs dokku.postgres.test-db-3

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....2021-10-06 07:00:47.912 UTC [47] LOG:  starting PostgreSQL 13.4 (Debian 13.4-4.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2021-10-06 07:00:47.914 UTC [47] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-10-06 07:00:47.917 UTC [48] LOG:  database system was shut down at 2021-10-06 07:00:47 UTC
2021-10-06 07:00:47.921 UTC [47] LOG:  database system is ready to accept connections
 done
server started

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

2021-10-06 07:00:48.033 UTC [47] LOG:  received fast shutdown request
waiting for server to shut down....2021-10-06 07:00:48.034 UTC [47] LOG:  aborting any active transactions
2021-10-06 07:00:48.036 UTC [47] LOG:  background worker "logical replication launcher" (PID 54) exited with exit code 1
2021-10-06 07:00:48.037 UTC [49] LOG:  shutting down
2021-10-06 07:00:48.045 UTC [47] LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

2021-10-06 07:00:48.155 UTC [1] LOG:  starting PostgreSQL 13.4 (Debian 13.4-4.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2021-10-06 07:00:48.155 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-10-06 07:00:48.155 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2021-10-06 07:00:48.156 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-10-06 07:00:48.159 UTC [59] LOG:  database system was shut down at 2021-10-06 07:00:48 UTC
2021-10-06 07:00:48.162 UTC [1] LOG:  database system is ready to accept connections
2021-10-06 07:00:48.821 UTC [1] LOG:  received fast shutdown request
2021-10-06 07:00:48.822 UTC [1] LOG:  aborting any active transactions
2021-10-06 07:00:48.825 UTC [1] LOG:  background worker "logical replication launcher" (PID 65) exited with exit code 1
2021-10-06 07:00:48.825 UTC [60] LOG:  shutting down
2021-10-06 07:00:48.832 UTC [1] LOG:  database system is shut down

PostgreSQL Database directory appears to contain a database; Skipping initialization

2021-10-06 07:00:50.552 UTC [1] LOG:  starting PostgreSQL 13.4 (Debian 13.4-4.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2021-10-06 07:00:50.553 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-10-06 07:00:50.553 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2021-10-06 07:00:50.574 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-10-06 07:00:50.578 UTC [27] LOG:  database system was shut down at 2021-10-06 07:00:48 UTC
2021-10-06 07:00:50.582 UTC [1] LOG:  database system is ready to accept connections
josegonzalez commented 2 years ago

Okay I'm assuming this one created the database properly. Mind checking on that?

Also, if you can repeat the above (with a new name of course, or you can destroy that service and reuse the name) but this time include the --custom-env flag?

timaschew commented 2 years ago

Sorry, I was confused what you meant with if test-db-1 doesn't exist because the table doesn't exist but the service does ^^ and yes test-db-3 is ok, because I did not pass the --custom-env.

Okay now hopefully the final correct run:

dokku --trace postgres:create test-db-4 --custom-env "LC_ALL=C"

This command is not run as root, but with an user with sudo privs, but sudo was not prefixed for that command

+ export DOKKU_HOST_ROOT=/home/dokku
+ DOKKU_HOST_ROOT=/home/dokku
+ export DOKKU_DISTRO
++ . /etc/os-release
++ echo debian
+ DOKKU_DISTRO=debian
+ export DOCKER_BIN=docker
+ DOCKER_BIN=docker
+ export DOKKU_IMAGE=gliderlabs/herokuish:latest-20
+ DOKKU_IMAGE=gliderlabs/herokuish:latest-20
+ export DOKKU_CNB_BUILDER=heroku/buildpacks
+ DOKKU_CNB_BUILDER=heroku/buildpacks
+ export DOKKU_LIB_ROOT=/var/lib/dokku
+ DOKKU_LIB_ROOT=/var/lib/dokku
+ export PLUGIN_PATH=/var/lib/dokku/plugins
+ PLUGIN_PATH=/var/lib/dokku/plugins
+ export PLUGIN_AVAILABLE_PATH=/var/lib/dokku/plugins/available
+ PLUGIN_AVAILABLE_PATH=/var/lib/dokku/plugins/available
+ export PLUGIN_ENABLED_PATH=/var/lib/dokku/plugins/enabled
+ PLUGIN_ENABLED_PATH=/var/lib/dokku/plugins/enabled
+ export PLUGIN_CORE_PATH=/var/lib/dokku/core-plugins
+ PLUGIN_CORE_PATH=/var/lib/dokku/core-plugins
+ export PLUGIN_CORE_AVAILABLE_PATH=/var/lib/dokku/core-plugins/available
+ PLUGIN_CORE_AVAILABLE_PATH=/var/lib/dokku/core-plugins/available
+ export PLUGIN_CORE_ENABLED_PATH=/var/lib/dokku/core-plugins/enabled
+ PLUGIN_CORE_ENABLED_PATH=/var/lib/dokku/core-plugins/enabled
+ export DOKKU_SYSTEM_GROUP=dokku
+ DOKKU_SYSTEM_GROUP=dokku
+ export DOKKU_SYSTEM_USER=dokku
+ DOKKU_SYSTEM_USER=dokku
+ export DOKKU_API_VERSION=1
+ DOKKU_API_VERSION=1
+ export DOKKU_NOT_IMPLEMENTED_EXIT=10
+ DOKKU_NOT_IMPLEMENTED_EXIT=10
+ export DOKKU_VALID_EXIT=0
+ DOKKU_VALID_EXIT=0
+ export DOKKU_PID=2019789
+ DOKKU_PID=2019789
+ export DOKKU_LOGS_DIR=/var/log/dokku
+ DOKKU_LOGS_DIR=/var/log/dokku
+ export DOKKU_LOGS_HOST_DIR=/var/log/dokku
+ DOKKU_LOGS_HOST_DIR=/var/log/dokku
+ export DOKKU_EVENTS_LOGFILE=/var/log/dokku/events.log
+ DOKKU_EVENTS_LOGFILE=/var/log/dokku/events.log
+ export DOKKU_CONTAINER_LABEL=dokku
+ DOKKU_CONTAINER_LABEL=dokku
+ export 'DOKKU_GLOBAL_BUILD_ARGS=--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=dokku'
+ DOKKU_GLOBAL_BUILD_ARGS='--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=dokku'
+ export 'DOKKU_GLOBAL_RUN_ARGS=--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=dokku'
+ DOKKU_GLOBAL_RUN_ARGS='--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=dokku'
+ source /var/lib/dokku/core-plugins/available/common/functions
++ set -eo pipefail
++ [[ -n 1 ]]
++ set -x
+ parse_args postgres:create test-db-4 --custom-env LC_ALL=C
+ declare 'desc=top-level cli arg parser'
+ local next_index=1
+ local skip=false
+ args=('postgres:create' 'test-db-4' '--custom-env' 'LC_ALL=C')
+ local args
+ local flags
+ for arg in "$@"
+ [[ false == \t\r\u\e ]]
+ case "$arg" in
+ [[ false == \t\r\u\e ]]
+ [[ postgres:create == \-\-\a\p\p ]]
+ [[ postgres:create =~ ^--.* ]]
+ next_index=2
+ for arg in "$@"
+ [[ false == \t\r\u\e ]]
+ case "$arg" in
+ [[ false == \t\r\u\e ]]
+ [[ test-db-4 == \-\-\a\p\p ]]
+ [[ test-db-4 =~ ^--.* ]]
+ next_index=3
+ for arg in "$@"
+ [[ false == \t\r\u\e ]]
+ case "$arg" in
+ [[ false == \t\r\u\e ]]
+ [[ --custom-env == \-\-\a\p\p ]]
+ [[ --custom-env =~ ^--.* ]]
+ flags=' --custom-env'
+ next_index=4
+ for arg in "$@"
+ [[ false == \t\r\u\e ]]
+ case "$arg" in
+ [[ false == \t\r\u\e ]]
+ [[ LC_ALL=C == \-\-\a\p\p ]]
+ [[ LC_ALL=C =~ ^--.* ]]
+ next_index=5
+ [[ -z --trace --custom-env ]]
+ return 0
+ args=("$@")
+ skip_arg=false
+ [[ postgres:create =~ ^--.* ]]
+ has_tty
+ declare 'desc=return 0 if we have a tty'
+ [[ '' == \t\r\u\e ]]
++ LC_ALL=C
++ /usr/bin/tty
+ [[ /dev/pts/0 == \n\o\t\ \a\ \t\t\y ]]
+ return 0
++ id -un
+ [[ dokku != \d\o\k\k\u ]]
+ [[ postgres:create =~ ^plugin:.* ]]
+ [[ postgres:create == \s\s\h\-\k\e\y\s\:\a\d\d ]]
+ [[ postgres:create == \s\s\h\-\k\e\y\s\:\r\e\m\o\v\e ]]
+ [[ -n '' ]]
+ dokku_auth postgres:create test-db-4 --custom-env LC_ALL=C
+ declare 'desc=calls user-auth plugin trigger'
+ export SSH_USER=admin
+ SSH_USER=admin
+ export SSH_NAME=default
+ SSH_NAME=default
++ wc -l
++ find /var/lib/dokku/plugins/enabled/20_events/user-auth
+ local user_auth_count=1
+ [[ 1 == 0 ]]
+ [[ 1 == 1 ]]
+ [[ -f /var/lib/dokku/plugins/enabled/20_events/user-auth ]]
+ return 0
+ case "$1" in
+ execute_dokku_cmd postgres:create test-db-4 --custom-env LC_ALL=C
+ declare 'desc=executes dokku sub-commands'
+ local PLUGIN_NAME=postgres:create
+ local PLUGIN_CMD=postgres:create
+ local implemented=0
+ local script
+ argv=('postgres:create' 'test-db-4' '--custom-env' 'LC_ALL=C')
+ local argv
+ case "$PLUGIN_NAME" in
++ readlink -f /var/lib/dokku/plugins/enabled/postgres
+ [[ /var/lib/dokku/plugins/available/postgres == *core-plugins* ]]
+ [[ -x /var/lib/dokku/plugins/enabled/postgres:create/subcommands/default ]]
+ [[ -x /var/lib/dokku/plugins/enabled/postgres:create/subcommands/postgres:create ]]
+ [[ -x /var/lib/dokku/plugins/enabled/postgres/subcommands/create ]]
+ [[ -n create ]]
+ /var/lib/dokku/plugins/enabled/postgres/subcommands/create postgres:create test-db-4 --custom-env LC_ALL=C
+ source /var/lib/dokku/plugins/enabled/common/functions
++ set -eo pipefail
++ [[ -n 1 ]]
++ set -x
++++ dirname /var/lib/dokku/plugins/enabled/postgres/subcommands/create
+++ cd /var/lib/dokku/plugins/enabled/postgres/subcommands
+++ pwd
++ dirname /var/lib/dokku/plugins/enabled/postgres/subcommands
+ source /var/lib/dokku/plugins/enabled/postgres/functions
++++ dirname /var/lib/dokku/plugins/enabled/postgres/functions
+++ cd /var/lib/dokku/plugins/enabled/postgres
+++ pwd
++ source /var/lib/dokku/plugins/enabled/postgres/config
+++++ dirname /var/lib/dokku/plugins/enabled/postgres/config
++++ cd /var/lib/dokku/plugins/enabled/postgres
++++ pwd
+++ _DIR=/var/lib/dokku/plugins/enabled/postgres
+++ export POSTGRES_IMAGE=postgres
+++ POSTGRES_IMAGE=postgres
+++ export POSTGRES_IMAGE_VERSION=13.4
+++ POSTGRES_IMAGE_VERSION=13.4
+++ export POSTGRES_ROOT=/var/lib/dokku/services/postgres
+++ POSTGRES_ROOT=/var/lib/dokku/services/postgres
+++ export POSTGRES_HOST_ROOT=/var/lib/dokku/services/postgres
+++ POSTGRES_HOST_ROOT=/var/lib/dokku/services/postgres
+++ PLUGIN_UNIMPLEMENTED_SUBCOMMANDS=()
+++ export PLUGIN_UNIMPLEMENTED_SUBCOMMANDS
+++ export PLUGIN_COMMAND_PREFIX=postgres
+++ PLUGIN_COMMAND_PREFIX=postgres
+++ export PLUGIN_CONFIG_ROOT=/var/lib/dokku/config/postgres
+++ PLUGIN_CONFIG_ROOT=/var/lib/dokku/config/postgres
+++ export PLUGIN_DATA_ROOT=/var/lib/dokku/services/postgres
+++ PLUGIN_DATA_ROOT=/var/lib/dokku/services/postgres
+++ export PLUGIN_DATA_HOST_ROOT=/var/lib/dokku/services/postgres
+++ PLUGIN_DATA_HOST_ROOT=/var/lib/dokku/services/postgres
+++ PLUGIN_DATASTORE_PORTS=('5432')
+++ export PLUGIN_DATASTORE_PORTS
+++ export PLUGIN_DATASTORE_WAIT_PORT=5432
+++ PLUGIN_DATASTORE_WAIT_PORT=5432
+++ export PLUGIN_DEFAULT_ALIAS=DATABASE
+++ PLUGIN_DEFAULT_ALIAS=DATABASE
+++ export PLUGIN_DISABLE_PULL=
+++ PLUGIN_DISABLE_PULL=
+++ export PLUGIN_DISABLE_PULL_VARIABLE=POSTGRES_DISABLE_PULL
+++ PLUGIN_DISABLE_PULL_VARIABLE=POSTGRES_DISABLE_PULL
+++ export PLUGIN_ALT_ALIAS=DOKKU_POSTGRES
+++ PLUGIN_ALT_ALIAS=DOKKU_POSTGRES
+++ export PLUGIN_IMAGE=postgres
+++ PLUGIN_IMAGE=postgres
+++ export PLUGIN_IMAGE_VERSION=13.4
+++ PLUGIN_IMAGE_VERSION=13.4
+++ export PLUGIN_SCHEME=postgres
+++ PLUGIN_SCHEME=postgres
+++ export PLUGIN_SERVICE=Postgres
+++ PLUGIN_SERVICE=Postgres
+++ export PLUGIN_VARIABLE=POSTGRES
+++ PLUGIN_VARIABLE=POSTGRES
+++ export PLUGIN_BASE_PATH=/var/lib/dokku/plugins
+++ PLUGIN_BASE_PATH=/var/lib/dokku/plugins
+++ export PLUGIN_CONFIG_SUFFIX=data
+++ PLUGIN_CONFIG_SUFFIX=data
+++ [[ -n 1 ]]
+++ export PLUGIN_BASE_PATH=/var/lib/dokku/plugins/enabled
+++ PLUGIN_BASE_PATH=/var/lib/dokku/plugins/enabled
+++ export PLUGIN_BUSYBOX_IMAGE=busybox:1.31.1-uclibc
+++ PLUGIN_BUSYBOX_IMAGE=busybox:1.31.1-uclibc
+++ export PLUGIN_AMBASSADOR_IMAGE=dokku/ambassador:0.3.3
+++ PLUGIN_AMBASSADOR_IMAGE=dokku/ambassador:0.3.3
+++ export PLUGIN_S3BACKUP_IMAGE=dokku/s3backup:0.10.3
+++ PLUGIN_S3BACKUP_IMAGE=dokku/s3backup:0.10.3
+++ export PLUGIN_WAIT_IMAGE=dokku/wait:0.4.3
+++ PLUGIN_WAIT_IMAGE=dokku/wait:0.4.3
+++ export POSTGRES_CONFIG_OPTIONS=
+++ POSTGRES_CONFIG_OPTIONS=
++ set -eo pipefail
++ [[ -n 1 ]]
++ set -x
++++ dirname /var/lib/dokku/plugins/enabled/postgres/functions
+++ cd /var/lib/dokku/plugins/enabled/postgres
+++ pwd
++ source /var/lib/dokku/plugins/enabled/postgres/common-functions
+++++ dirname /var/lib/dokku/plugins/enabled/postgres/common-functions
++++ cd /var/lib/dokku/plugins/enabled/postgres
++++ pwd
+++ source /var/lib/dokku/plugins/enabled/postgres/config
++++++ dirname /var/lib/dokku/plugins/enabled/postgres/config
+++++ cd /var/lib/dokku/plugins/enabled/postgres
+++++ pwd
++++ _DIR=/var/lib/dokku/plugins/enabled/postgres
++++ export POSTGRES_IMAGE=postgres
++++ POSTGRES_IMAGE=postgres
++++ export POSTGRES_IMAGE_VERSION=13.4
++++ POSTGRES_IMAGE_VERSION=13.4
++++ export POSTGRES_ROOT=/var/lib/dokku/services/postgres
++++ POSTGRES_ROOT=/var/lib/dokku/services/postgres
++++ export POSTGRES_HOST_ROOT=/var/lib/dokku/services/postgres
++++ POSTGRES_HOST_ROOT=/var/lib/dokku/services/postgres
++++ PLUGIN_UNIMPLEMENTED_SUBCOMMANDS=()
++++ export PLUGIN_UNIMPLEMENTED_SUBCOMMANDS
++++ export PLUGIN_COMMAND_PREFIX=postgres
++++ PLUGIN_COMMAND_PREFIX=postgres
++++ export PLUGIN_CONFIG_ROOT=/var/lib/dokku/config/postgres
++++ PLUGIN_CONFIG_ROOT=/var/lib/dokku/config/postgres
++++ export PLUGIN_DATA_ROOT=/var/lib/dokku/services/postgres
++++ PLUGIN_DATA_ROOT=/var/lib/dokku/services/postgres
++++ export PLUGIN_DATA_HOST_ROOT=/var/lib/dokku/services/postgres
++++ PLUGIN_DATA_HOST_ROOT=/var/lib/dokku/services/postgres
++++ PLUGIN_DATASTORE_PORTS=('5432')
++++ export PLUGIN_DATASTORE_PORTS
++++ export PLUGIN_DATASTORE_WAIT_PORT=5432
++++ PLUGIN_DATASTORE_WAIT_PORT=5432
++++ export PLUGIN_DEFAULT_ALIAS=DATABASE
++++ PLUGIN_DEFAULT_ALIAS=DATABASE
++++ export PLUGIN_DISABLE_PULL=
++++ PLUGIN_DISABLE_PULL=
++++ export PLUGIN_DISABLE_PULL_VARIABLE=POSTGRES_DISABLE_PULL
++++ PLUGIN_DISABLE_PULL_VARIABLE=POSTGRES_DISABLE_PULL
++++ export PLUGIN_ALT_ALIAS=DOKKU_POSTGRES
++++ PLUGIN_ALT_ALIAS=DOKKU_POSTGRES
++++ export PLUGIN_IMAGE=postgres
++++ PLUGIN_IMAGE=postgres
++++ export PLUGIN_IMAGE_VERSION=13.4
++++ PLUGIN_IMAGE_VERSION=13.4
++++ export PLUGIN_SCHEME=postgres
++++ PLUGIN_SCHEME=postgres
++++ export PLUGIN_SERVICE=Postgres
++++ PLUGIN_SERVICE=Postgres
++++ export PLUGIN_VARIABLE=POSTGRES
++++ PLUGIN_VARIABLE=POSTGRES
++++ export PLUGIN_BASE_PATH=/var/lib/dokku/plugins
++++ PLUGIN_BASE_PATH=/var/lib/dokku/plugins
++++ export PLUGIN_CONFIG_SUFFIX=data
++++ PLUGIN_CONFIG_SUFFIX=data
++++ [[ -n 1 ]]
++++ export PLUGIN_BASE_PATH=/var/lib/dokku/plugins/enabled
++++ PLUGIN_BASE_PATH=/var/lib/dokku/plugins/enabled
++++ export PLUGIN_BUSYBOX_IMAGE=busybox:1.31.1-uclibc
++++ PLUGIN_BUSYBOX_IMAGE=busybox:1.31.1-uclibc
++++ export PLUGIN_AMBASSADOR_IMAGE=dokku/ambassador:0.3.3
++++ PLUGIN_AMBASSADOR_IMAGE=dokku/ambassador:0.3.3
++++ export PLUGIN_S3BACKUP_IMAGE=dokku/s3backup:0.10.3
++++ PLUGIN_S3BACKUP_IMAGE=dokku/s3backup:0.10.3
++++ export PLUGIN_WAIT_IMAGE=dokku/wait:0.4.3
++++ PLUGIN_WAIT_IMAGE=dokku/wait:0.4.3
++++ export POSTGRES_CONFIG_OPTIONS=
++++ POSTGRES_CONFIG_OPTIONS=
+++ set -eo pipefail
+++ [[ -n 1 ]]
+++ set -x
+++ source /var/lib/dokku/plugins/available/config/functions
++++ set -eo pipefail
++++ [[ -n 1 ]]
++++ set -x
++++ source /var/lib/dokku/core-plugins/available/common/functions
+++++ set -eo pipefail
+++++ [[ -n 1 ]]
+++++ set -x
++ source /var/lib/dokku/plugins/enabled/common/functions
+++ set -eo pipefail
+++ [[ -n 1 ]]
+++ set -x
++ source /var/lib/dokku/plugins/available/config/functions
+++ set -eo pipefail
+++ [[ -n 1 ]]
+++ set -x
+++ source /var/lib/dokku/core-plugins/available/common/functions
++++ set -eo pipefail
++++ [[ -n 1 ]]
++++ set -x
++ [[ -f /var/lib/dokku/plugins/available/docker-options/functions ]]
++ source /var/lib/dokku/plugins/available/docker-options/functions
+++ set -eo pipefail
+++ [[ -n 1 ]]
+++ set -x
+++ source /var/lib/dokku/core-plugins/available/common/functions
++++ set -eo pipefail
++++ [[ -n 1 ]]
++++ set -x
+++ AVAILABLE_PHASES=(build deploy run)
+ service-create-cmd postgres:create test-db-4 --custom-env LC_ALL=C
+ declare 'desc=create a Postgres service'
+ argv=('postgres:create' 'test-db-4' '--custom-env' 'LC_ALL=C')
+ local cmd=postgres:create argv
+ [[ postgres:create == \p\o\s\t\g\r\e\s\:\c\r\e\a\t\e ]]
+ shift 1
+ CREATE_FLAGS_LIST=('--custom-env' 'LC_ALL=C')
+ declare SERVICE=test-db-4 CREATE_FLAGS_LIST
+ service_create test-db-4 --custom-env LC_ALL=C
+ local SERVICE=test-db-4
+ is_valid_service_name test-db-4
+ declare 'desc=validate a service name'
+ declare SERVICE=test-db-4
+ [[ -z test-db-4 ]]
+ [[ test-db-4 =~ ^[A-Za-z0-9_-]+$ ]]
+ return 0
+ [[ -z test-db-4 ]]
+ [[ ! -d /var/lib/dokku/services/postgres/test-db-4 ]]
+ SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-4
+ LINKS_FILE=/var/lib/dokku/services/postgres/test-db-4/LINKS
+ service_parse_args --custom-env LC_ALL=C
+ declare 'desc=cli arg parser'
+ local next_index=1
+ local skip=false
+ args=('--custom-env' 'LC_ALL=C')
+ local args
+ for arg in "$@"
+ shift
+ case "$arg" in
+ set -- LC_ALL=C -C
+ for arg in "$@"
+ shift
+ case "$arg" in
+ set -- -C LC_ALL=C
+ OPTIND=1
+ getopts a:c:C:d:i:I:m:p:q:R:r:s:u: opt
+ case "$opt" in
+ export SERVICE_CUSTOM_ENV=LC_ALL=C
+ SERVICE_CUSTOM_ENV=LC_ALL=C
+ getopts a:c:C:d:i:I:m:p:q:R:r:s:u: opt
+ shift 2
+ service_image_exists test-db-4
+ declare 'desc=check if the current image exists'
+ declare SERVICE=test-db-4
+ local plugin_image=postgres
+ local plugin_image_version=13.4
+ [[ -f /var/lib/dokku/services/postgres/test-db-4/IMAGE ]]
+ [[ -f /var/lib/dokku/services/postgres/test-db-4/IMAGE_VERSION ]]
+ local IMAGE=postgres:13.4
++ docker images -q postgres:13.4
+ [[ cd4b5373985e == '' ]]
+ return 0
+ plugn trigger service-action pre-create test-db-4
+ mkdir -p /var/lib/dokku/services/postgres/test-db-4
+ mkdir -p /var/lib/dokku/services/postgres/test-db-4/data
+ touch /var/lib/dokku/services/postgres/test-db-4/LINKS
++ openssl rand -hex 16
+ PASSWORD=7eed152250fc0cc49d6e129510964cfd
+ [[ -n '' ]]
+ echo 7eed152250fc0cc49d6e129510964cfd
+ chmod 640 /var/lib/dokku/services/postgres/test-db-4/PASSWORD
+ service_commit_config test-db-4
+ declare SERVICE=test-db-4
+ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-4
+ local CONFIG_VARIABLE=POSTGRES_CONFIG_OPTIONS
+ local ENV_VARIABLE=POSTGRES_CUSTOM_ENV
+ custom_env=
+ [[ -n LC_ALL=C ]]
+ custom_env=LC_ALL=C
+ [[ -n LC_ALL=C ]]
+ echo LC_ALL=C
+ tr ';' '\n'
+ config_options=
+ [[ -n '' ]]
+ [[ -n '' ]]
+ echo ''
+ [[ -n '' ]]
+ [[ -n '' ]]
+ [[ -n postgres ]]
+ echo postgres
+ [[ -n 13.4 ]]
+ echo 13.4
+ write_database_name test-db-4
+ declare 'desc=write a sanitized database name'
+ declare SERVICE=test-db-4
+ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-4
+ echo test-db-4
+ tr .- _
+ plugn trigger service-action post-create test-db-4
+ service_create_container test-db-4
+ local SERVICE=test-db-4
+ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-4
+ local SERVICE_HOST_ROOT=/var/lib/dokku/services/postgres/test-db-4
++ get_service_name test-db-4
++ declare 'desc=retrieve a docker service label'
++ declare SERVICE=test-db-4
++ echo dokku.postgres.test-db-4
+ local SERVICE_NAME=dokku.postgres.test-db-4
++ service_password test-db-4
++ declare 'desc=fetch the password for a service'
++ declare SERVICE=test-db-4
++ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-4
++ local PASSWORD_FILE=/var/lib/dokku/services/postgres/test-db-4/PASSWORD
++ [[ -f /var/lib/dokku/services/postgres/test-db-4/PASSWORD ]]
++ cat /var/lib/dokku/services/postgres/test-db-4/PASSWORD
+ local PASSWORD=7eed152250fc0cc49d6e129510964cfd
++ get_database_name test-db-4
++ declare 'desc=retrieve a sanitized database name'
++ declare SERVICE=test-db-4
++ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-4
++ [[ ! -f /var/lib/dokku/services/postgres/test-db-4/DATABASE_NAME ]]
++ cat /var/lib/dokku/services/postgres/test-db-4/DATABASE_NAME
+ local DATABASE_NAME=test_db_4
+ local PREVIOUS_ID
+ [[ -f /var/lib/dokku/services/postgres/test-db-4/CONFIG_OPTIONS ]]
++ cat /var/lib/dokku/services/postgres/test-db-4/CONFIG_OPTIONS
+ export CONFIG_OPTIONS=
+ CONFIG_OPTIONS=
+ [[ -f /var/lib/dokku/services/postgres/test-db-4/SERVICE_MEMORY ]]
+ [[ -n '' ]]
+ [[ -f /var/lib/dokku/services/postgres/test-db-4/SHM_SIZE ]]
+ [[ -n '' ]]
+ [[ -f /var/lib/dokku/services/postgres/test-db-4/IMAGE ]]
++ cat /var/lib/dokku/services/postgres/test-db-4/IMAGE
+ PLUGIN_IMAGE=postgres
+ [[ -f /var/lib/dokku/services/postgres/test-db-4/IMAGE_VERSION ]]
++ cat /var/lib/dokku/services/postgres/test-db-4/IMAGE_VERSION
+ PLUGIN_IMAGE_VERSION=13.4
++ docker run --name dokku.postgres.test-db-4 -v /var/lib/dokku/services/postgres/test-db-4/data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=7eed152250fc0cc49d6e129510964cfd --env-file=/var/lib/dokku/services/postgres/test-db-4/ENV -d --restart always --label dokku=service --label dokku.service=postgres postgres:13.4
+ ID=0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338
+ echo 0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338
+ dokku_log_verbose_quiet 'Waiting for container to be ready'
+ declare 'desc=log verbose formatter (with quiet option)'
+ [[ -z '' ]]
+ echo '       Waiting for container to be ready'
       Waiting for container to be ready
+ docker run --rm --link dokku.postgres.test-db-4:postgres dokku/wait:0.4.3 -p 5432
+ dokku_log_verbose_quiet 'Creating container database'
+ declare 'desc=log verbose formatter (with quiet option)'
+ [[ -z '' ]]
+ echo '       Creating container database'
       Creating container database
+ docker exec dokku.postgres.test-db-4 su - postgres -c 'createdb -E utf8 test_db_4'
+ dokku_log_verbose_quiet 'Already exists'
+ declare 'desc=log verbose formatter (with quiet option)'
+ [[ -z '' ]]
+ echo '       Already exists'
       Already exists
+ dokku_log_verbose_quiet 'Securing connection to database'
+ declare 'desc=log verbose formatter (with quiet option)'
+ [[ -z '' ]]
+ echo '       Securing connection to database'
       Securing connection to database
+ service_stop test-db-4
+ declare 'desc=stop a running service'
+ declare SERVICE=test-db-4
+ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-4
++ get_service_name test-db-4
++ declare 'desc=retrieve a docker service label'
++ declare SERVICE=test-db-4
++ echo dokku.postgres.test-db-4
+ local SERVICE_NAME=dokku.postgres.test-db-4
++ docker ps -aq --no-trunc --filter 'name=^/dokku.postgres.test-db-4$' --format '{{ .ID }}'
+ local ID=0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338
+ [[ -z 0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338 ]]
+ [[ -n 0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338 ]]
+ dokku_log_info2_quiet 'Stopping container'
+ declare 'desc=log info2 formatter (with quiet option)'
+ [[ -z '' ]]
+ echo '=====> Stopping container'
+ docker stop dokku.postgres.test-db-4
+ service_port_pause test-db-4
+ declare 'desc=pause service exposure'
+ declare SERVICE=test-db-4 LOG_FAIL=
+ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-4
++ get_service_name test-db-4
++ declare 'desc=retrieve a docker service label'
++ declare SERVICE=test-db-4
++ echo dokku.postgres.test-db-4
+ local EXPOSED_NAME=dokku.postgres.test-db-4.ambassador
+ local PORT_FILE=/var/lib/dokku/services/postgres/test-db-4/PORT
+ [[ '' == \t\r\u\e ]]
+ [[ ! -f /var/lib/dokku/services/postgres/test-db-4/PORT ]]
+ return 0
+ dokku_log_verbose_quiet 'Container stopped'
+ declare 'desc=log verbose formatter (with quiet option)'
+ [[ -z '' ]]
+ echo '       Container stopped'
+ docker run --rm -i -v /var/lib/dokku/services/postgres/test-db-4/data:/var/lib/postgresql/data postgres:13.4 bash -s
+++ dirname /var/lib/dokku/plugins/enabled/postgres/functions
++ cd /var/lib/dokku/plugins/enabled/postgres
++ pwd
++ docker ps -aq --no-trunc --filter status=exited --filter 'name=^/dokku.postgres.test-db-4$' --format '{{ .ID }}'
+ PREVIOUS_ID=0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338
+ docker start 0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338
+ service_port_unpause test-db-4
+ declare 'desc=start service exposure'
+ declare SERVICE=test-db-4 LOG_FAIL=
+ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-4
++ get_service_name test-db-4
++ declare 'desc=retrieve a docker service label'
++ declare SERVICE=test-db-4
++ echo dokku.postgres.test-db-4
+ local SERVICE_NAME=dokku.postgres.test-db-4
+ local EXPOSED_NAME=dokku.postgres.test-db-4.ambassador
+ local PORT_FILE=/var/lib/dokku/services/postgres/test-db-4/PORT
+ PORTS=()
+ local PORTS
+ PORTS=(${PORTS[@]:-$(get_random_ports ${#PLUGIN_DATASTORE_PORTS[@]})})
++ get_random_ports 1
++ declare 'desc=retrieve N random ports'
++ declare iterations=1
++ (( i = 0 ))
++ (( i < iterations ))
++ local port=19711
++ local quit=0
++ '[' 0 -ne 1 ']'
++ grep 19711
++ netstat -an
++ '[' 1 -gt 0 ']'
++ quit=1
++ '[' 1 -ne 1 ']'
++ echo 19711
++ (( i++ ))
++ (( i < iterations ))
++ cat /var/lib/dokku/services/postgres/test-db-4/ID
+ local ID=0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338
+ [[ 1 != \1 ]]
+ [[ '' == \t\r\u\e ]]
+ [[ ! -f /var/lib/dokku/services/postgres/test-db-4/PORT ]]
+ return 0
+ dokku_log_info2 'Postgres container created: test-db-4'
+ declare 'desc=log info2 formatter'
+ echo '=====> Postgres container created: test-db-4'
=====> Postgres container created: test-db-4
+ service_info test-db-4
+ declare 'desc=retrieve information about a given service'
+ declare SERVICE=test-db-4 INFO_FLAG=
+ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-4
++ service_url test-db-4
++ local SERVICE=test-db-4
+++ service_dns_hostname test-db-4
+++ declare 'desc=retrieve the alias of a service'
+++ declare SERVICE=test-db-4
++++ get_service_name test-db-4
++++ declare 'desc=retrieve a docker service label'
++++ declare SERVICE=test-db-4
++++ echo dokku.postgres.test-db-4
+++ local SERVICE_NAME=dokku.postgres.test-db-4
+++ echo dokku.postgres.test-db-4
+++ tr ._ -
++ local SERVICE_DNS_HOSTNAME=dokku-postgres-test-db-4
+++ get_database_name test-db-4
+++ declare 'desc=retrieve a sanitized database name'
+++ declare SERVICE=test-db-4
+++ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-4
+++ [[ ! -f /var/lib/dokku/services/postgres/test-db-4/DATABASE_NAME ]]
+++ cat /var/lib/dokku/services/postgres/test-db-4/DATABASE_NAME
++ local DATABASE_NAME=test_db_4
+++ service_password test-db-4
+++ declare 'desc=fetch the password for a service'
+++ declare SERVICE=test-db-4
+++ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-4
+++ local PASSWORD_FILE=/var/lib/dokku/services/postgres/test-db-4/PASSWORD
+++ [[ -f /var/lib/dokku/services/postgres/test-db-4/PASSWORD ]]
+++ cat /var/lib/dokku/services/postgres/test-db-4/PASSWORD
++ local PASSWORD=7eed152250fc0cc49d6e129510964cfd
++ echo postgres://postgres:7eed152250fc0cc49d6e129510964cfd@dokku-postgres-test-db-4:5432/test_db_4
+ local SERVICE_URL=postgres://postgres:7eed152250fc0cc49d6e129510964cfd@dokku-postgres-test-db-4:5432/test_db_4
+ local PORT_FILE=/var/lib/dokku/services/postgres/test-db-4/PORT
++ cat /var/lib/dokku/services/postgres/test-db-4/ID
+ local SERVICE_CONTAINER_ID=0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338
+ local flag key valid_flags
++ cat /var/lib/dokku/services/postgres/test-db-4/CONFIG_OPTIONS
++ service_exposed_ports test-db-4
++ declare 'desc=list exposed ports for a service'
++ declare SERVICE=test-db-4
++ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-4
++ local PORT_FILE=/var/lib/dokku/services/postgres/test-db-4/PORT
++ [[ ! -f /var/lib/dokku/services/postgres/test-db-4/PORT ]]
++ echo -
++ return 0
++ get_container_ip 0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338
++ declare 'desc=retrieve the ip address of a container'
++ declare CONTAINER_ID=0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338
++ docker inspect --format '{{ .NetworkSettings.IPAddress }}' 0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338
++ service_linked_apps test-db-4
++ declare 'desc=list all apps linked to a service for info output'
++ declare SERVICE=test-db-4
++ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-4
++ local LINKS_FILE=/var/lib/dokku/services/postgres/test-db-4/LINKS
++ touch /var/lib/dokku/services/postgres/test-db-4/LINKS
++ [[ -z '' ]]
++ echo -
++ return 0
++ service_status test-db-4
++ declare 'desc=display the status of a service'
++ declare SERVICE=test-db-4
++ local SERVICE_ROOT=/var/lib/dokku/services/postgres/test-db-4
+++ cat /var/lib/dokku/services/postgres/test-db-4/ID
++ local ID=0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338
++ local CONTAINER_STATUS
+++ docker inspect -f '{{.State.Status}}' 0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338
++ CONTAINER_STATUS=running
++ [[ -n running ]]
++ echo running
++ return 0
++ service_version test-db-4
++ declare 'desc=display the running version for an image'
++ declare SERVICE=test-db-4
+++ get_service_name test-db-4
+++ declare 'desc=retrieve a docker service label'
+++ declare SERVICE=test-db-4
+++ echo dokku.postgres.test-db-4
++ local SERVICE_NAME=dokku.postgres.test-db-4
++ docker inspect -f '{{.Config.Image}}' dokku.postgres.test-db-4
+ flag_map=('--config-dir: /var/lib/dokku/services/postgres/test-db-4/data' '--config-options: ' '--data-dir: /var/lib/dokku/services/postgres/test-db-4/data' '--dsn: postgres://postgres:7eed152250fc0cc49d6e129510964cfd@dokku-postgres-test-db-4:5432/test_db_4' '--exposed-ports: -' '--id: 0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338' '--internal-ip: 172.17.0.10' '--links: -' '--service-root: /var/lib/dokku/services/postgres/test-db-4' '--status: running' '--version: postgres:13.4')
+ local flag_map
+ [[ -z '' ]]
+ dokku_log_info2 'test-db-4 postgres service information'
+ declare 'desc=log info2 formatter'
+ echo '=====> test-db-4 postgres service information'
=====> test-db-4 postgres service information
+ for flag in "${flag_map[@]}"
++ echo 'config-dir: /var/lib/dokku/services/postgres/test-db-4/data'
++ cut -f1 '-d '
++ tr - ' '
+ key='config dir:'
++ printf '%-20s %-25s' 'Config dir:' /var/lib/dokku/services/postgres/test-db-4/data
+ dokku_log_verbose 'Config dir:          /var/lib/dokku/services/postgres/test-db-4/data'
+ declare 'desc=log verbose formatter'
+ echo '       Config dir:          /var/lib/dokku/services/postgres/test-db-4/data'
       Config dir:          /var/lib/dokku/services/postgres/test-db-4/data
+ for flag in "${flag_map[@]}"
++ echo 'config-options: '
++ cut -f1 '-d '
++ tr - ' '
+ key='config options:'
++ printf '%-20s %-25s' 'Config options:' ''
+ dokku_log_verbose 'Config options:                               '
+ declare 'desc=log verbose formatter'
+ echo '       Config options:                               '
       Config options:
+ for flag in "${flag_map[@]}"
++ echo 'data-dir: /var/lib/dokku/services/postgres/test-db-4/data'
++ cut -f1 '-d '
++ tr - ' '
+ key='data dir:'
++ printf '%-20s %-25s' 'Data dir:' /var/lib/dokku/services/postgres/test-db-4/data
+ dokku_log_verbose 'Data dir:            /var/lib/dokku/services/postgres/test-db-4/data'
+ declare 'desc=log verbose formatter'
+ echo '       Data dir:            /var/lib/dokku/services/postgres/test-db-4/data'
       Data dir:            /var/lib/dokku/services/postgres/test-db-4/data
+ for flag in "${flag_map[@]}"
++ echo 'dsn: postgres://postgres:7eed152250fc0cc49d6e129510964cfd@dokku-postgres-test-db-4:5432/test_db_4'
++ cut -f1 '-d '
++ tr - ' '
+ key=dsn:
++ printf '%-20s %-25s' Dsn: postgres://postgres:7eed152250fc0cc49d6e129510964cfd@dokku-postgres-test-db-4:5432/test_db_4
+ dokku_log_verbose 'Dsn:                 postgres://postgres:7eed152250fc0cc49d6e129510964cfd@dokku-postgres-test-db-4:5432/test_db_4'
+ declare 'desc=log verbose formatter'
+ echo '       Dsn:                 postgres://postgres:7eed152250fc0cc49d6e129510964cfd@dokku-postgres-test-db-4:5432/test_db_4'
       Dsn:                 postgres://postgres:7eed152250fc0cc49d6e129510964cfd@dokku-postgres-test-db-4:5432/test_db_4
+ for flag in "${flag_map[@]}"
++ echo 'exposed-ports: -'
++ cut -f1 '-d '
++ tr - ' '
+ key='exposed ports:'
++ printf '%-20s %-25s' 'Exposed ports:' -
+ dokku_log_verbose 'Exposed ports:       -                        '
+ declare 'desc=log verbose formatter'
+ echo '       Exposed ports:       -                        '
       Exposed ports:       -
+ for flag in "${flag_map[@]}"
++ echo 'id: 0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338'
++ cut -f1 '-d '
++ tr - ' '
+ key=id:
++ printf '%-20s %-25s' Id: 0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338
+ dokku_log_verbose 'Id:                  0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338'
+ declare 'desc=log verbose formatter'
+ echo '       Id:                  0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338'
       Id:                  0f31d5d3e896bc81b514779d5714757a3128f45dcd67d02fd9084e539d64f338
+ for flag in "${flag_map[@]}"
++ echo 'internal-ip: 172.17.0.10'
++ tr - ' '
++ cut -f1 '-d '
+ key='internal ip:'
++ printf '%-20s %-25s' 'Internal ip:' 172.17.0.10
+ dokku_log_verbose 'Internal ip:         172.17.0.10              '
+ declare 'desc=log verbose formatter'
+ echo '       Internal ip:         172.17.0.10              '
       Internal ip:         172.17.0.10
+ for flag in "${flag_map[@]}"
++ echo 'links: -'
++ cut -f1 '-d '
++ tr - ' '
+ key=links:
++ printf '%-20s %-25s' Links: -
+ dokku_log_verbose 'Links:               -                        '
+ declare 'desc=log verbose formatter'
+ echo '       Links:               -                        '
       Links:               -
+ for flag in "${flag_map[@]}"
++ echo 'service-root: /var/lib/dokku/services/postgres/test-db-4'
++ cut -f1 '-d '
++ tr - ' '
+ key='service root:'
++ printf '%-20s %-25s' 'Service root:' /var/lib/dokku/services/postgres/test-db-4
+ dokku_log_verbose 'Service root:        /var/lib/dokku/services/postgres/test-db-4'
+ declare 'desc=log verbose formatter'
+ echo '       Service root:        /var/lib/dokku/services/postgres/test-db-4'
       Service root:        /var/lib/dokku/services/postgres/test-db-4
+ for flag in "${flag_map[@]}"
++ echo 'status: running'
++ tr - ' '
++ cut -f1 '-d '
+ key=status:
++ printf '%-20s %-25s' Status: running
+ dokku_log_verbose 'Status:              running                  '
+ declare 'desc=log verbose formatter'
+ echo '       Status:              running                  '
       Status:              running
+ for flag in "${flag_map[@]}"
++ echo 'version: postgres:13.4'
++ tr - ' '
++ cut -f1 '-d '
+ key=version:
++ printf '%-20s %-25s' Version: postgres:13.4
+ dokku_log_verbose 'Version:             postgres:13.4            '
+ declare 'desc=log verbose formatter'
+ echo '       Version:             postgres:13.4            '
       Version:             postgres:13.4
+ plugn trigger service-action post-create-complete test-db-4
+ implemented=1
+ [[ 1 -eq 0 ]]
+ [[ 1 -eq 0 ]]

docker logs dokku.postgres.test-db-4

This command is run as root because I get otherwise this error

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/dokku.postgres.test-db-4/json": dial unix /var/run/docker.sock: connect: permission denied
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 "C".
The default database encoding has accordingly been set to "SQL_ASCII".
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
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.
syncing data to disk ... ok

Success. You can now start the database server using:

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

waiting for server to start....2021-10-06 07:08:13.437 UTC [48] LOG:  starting PostgreSQL 13.4 (Debian 13.4-4.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2021-10-06 07:08:13.438 UTC [48] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-10-06 07:08:13.441 UTC [49] LOG:  database system was shut down at 2021-10-06 07:08:13 UTC
2021-10-06 07:08:13.445 UTC [48] LOG:  database system is ready to accept connections
 done
server started

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

waiting for server to shut down...2021-10-06 07:08:13.559 UTC [48] LOG:  received fast shutdown request
.2021-10-06 07:08:13.560 UTC [48] LOG:  aborting any active transactions
2021-10-06 07:08:13.562 UTC [48] LOG:  background worker "logical replication launcher" (PID 55) exited with exit code 1
2021-10-06 07:08:13.563 UTC [50] LOG:  shutting down
2021-10-06 07:08:13.570 UTC [48] LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

2021-10-06 07:08:13.675 UTC [1] LOG:  starting PostgreSQL 13.4 (Debian 13.4-4.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2021-10-06 07:08:13.676 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-10-06 07:08:13.676 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2021-10-06 07:08:13.677 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-10-06 07:08:13.680 UTC [60] LOG:  database system was shut down at 2021-10-06 07:08:13 UTC
2021-10-06 07:08:13.684 UTC [1] LOG:  database system is ready to accept connections
2021-10-06 07:08:14.173 UTC [77] ERROR:  new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
2021-10-06 07:08:14.173 UTC [77] HINT:  Use the same encoding as in the template database, or use template0 as template.
2021-10-06 07:08:14.173 UTC [77] STATEMENT:  CREATE DATABASE test_db_4 ENCODING 'utf8';
2021-10-06 07:08:14.240 UTC [1] LOG:  received fast shutdown request
2021-10-06 07:08:14.241 UTC [1] LOG:  aborting any active transactions
2021-10-06 07:08:14.242 UTC [1] LOG:  background worker "logical replication launcher" (PID 66) exited with exit code 1
2021-10-06 07:08:14.245 UTC [61] LOG:  shutting down
2021-10-06 07:08:14.251 UTC [1] LOG:  database system is shut down

PostgreSQL Database directory appears to contain a database; Skipping initialization

2021-10-06 07:08:15.390 UTC [1] LOG:  starting PostgreSQL 13.4 (Debian 13.4-4.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2021-10-06 07:08:15.390 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-10-06 07:08:15.390 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2021-10-06 07:08:15.391 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-10-06 07:08:15.394 UTC [27] LOG:  database system was shut down at 2021-10-06 07:08:14 UTC
2021-10-06 07:08:15.398 UTC [1] LOG:  database system is ready to accept connections
josegonzalez commented 2 years ago

I would expect the database created to be test_db_4 in this last case (since database names are underscored versions of the service name, as that makes a lot of tooling happier for whatever reason).

I see the following output:

2021-10-06 07:08:14.173 UTC [77] ERROR:  new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
2021-10-06 07:08:14.173 UTC [77] HINT:  Use the same encoding as in the template database, or use template0 as template.
2021-10-06 07:08:14.173 UTC [77] STATEMENT:  CREATE DATABASE test_db_4 ENCODING 'utf8';

Did the test_db_4 database get created?

josegonzalez commented 2 years ago

I wonder if this is failing due to the LC_ALL=C encoding you are setting...

timaschew commented 2 years ago

It's not related to underscores in the name, it's related to LC_ALL=C. I've tried to set another value:--custom-env "LC_ALL=en_US.UTF-8" and in that case everything is fine! But --custom-env "LC_ALL=POSIX" also doesn't work (container is created, and only 3 default databases)

//edit: I found out that C has the same effect as POSIX and it means no locale, so it's the most generic setting.


And there is also a difference between an invalid Locale, like --custom-env "LC_ALL=de_DE.UTF-8" in that case I even can't enter the container. In the logs I find this:

initdb: error: invalid locale settings; check LANG and LC_* environment variables
bash: warning: setlocale: LC_ALL: cannot change locale (de_DE.UTF-8)
bash: warning: setlocale: LC_ALL: cannot change locale (de_DE.UTF-8)
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

initdb: error: invalid locale settings; check LANG and LC_* environment variables
josegonzalez commented 2 years ago

What happens if you try to start the database manually with the upstream image?

Here is the command that gets run:

docker run --name dokku.postgres.test-db-3 -v /var/lib/dokku/services/postgres/test-db-3/data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=f3933f5bed23df5baa270f62a6d8bfc6 --env-file=/var/lib/dokku/services/postgres/test-db-3/ENV -d --restart always --label dokku=service --label dokku.service=postgres postgres:13.4

You could change the --env-file there to be --env LC_ALL=C, change the volume paths as appropriate, and change anything else naming wise for the test (the command was fetched from your trace output).

timaschew commented 2 years ago

I did now carefully ready the logs, this line is important (to me):

The default database encoding has accordingly been set to "SQL_ASCII".

That is actually not what I wanted. I found out that I need to set --custom-env "LC_ALL=C.UTF-8", then everything works.

@josegonzalez thanks for your help!

timaschew commented 2 years ago

The context is: I want to deploy matrix (synapse backend) via dokku. Here are some instructions: https://matrix-org.github.io/synapse/latest/postgres.html

su - postgres
# Or, if your system uses sudo to get administrative rights
sudo -u postgres bash
# this will prompt for a password for the new user
createuser --pwprompt synapse_user
createdb --encoding=UTF8 --locale=C --template=template0 --owner=synapse_user synapse

Note that the PostgreSQL database must have the correct encoding set (as shown above), otherwise it will not be able to store UTF8 strings.


There is a strict check in codebase that ctype and collation must be C. It means C.UTF-8 is not allowed, which is wrong in my opinion.

The problem now is that:

So either I need somehow to explicitly set the encoding to UTF-8 but I didn't found an environment variable for it.

I wonder how it's possible that the encoding is set to SQL_ASCII, because of this line: https://github.com/dokku/dokku-postgres/blob/f1d60d6f4b3b9232745a37ca2e9a5e0f4fe60706/functions#L97

The encoding is hardcoded!

To me this is the problem. Alternatively it would be nice to pass the arguments for createdb (locale, encoding, etc.) dynamically.