LibrePhotos / librephotos-docker

You can find here the Dockerfiles for the automated build process of LibrePhotos.
MIT License
157 stars 101 forks source link

FATAL: database "docker" does not exist #59

Closed bleomycin closed 2 years ago

bleomycin commented 2 years ago

With the latest unmodified docker-compose.yml and librephotos.env files, on debian 11 with docker version 20.10.17, build 100c701. Following the instructions here exactly: https://docs.librephotos.com/1/standard_install/ yields the following endlessly repeating database error from the db container: FATAL: database "docker" does not exist

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....2022-07-07 21:50:07.918 UTC [49] LOG:  starting PostgreSQL 13.7 (Debian 13.7-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-07-07 21:50:07.918 UTC [49] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-07-07 21:50:07.919 UTC [50] LOG:  database system was shut down at 2022-07-07 21:50:07 UTC
2022-07-07 21:50:07.923 UTC [49] LOG:  database system is ready to accept connections
 done
server started
CREATE DATABASE

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

2022-07-07 21:50:08.155 UTC [49] LOG:  received fast shutdown request
waiting for server to shut down....2022-07-07 21:50:08.155 UTC [49] LOG:  aborting any active transactions
2022-07-07 21:50:08.158 UTC [49] LOG:  background worker "logical replication launcher" (PID 56) exited with exit code 1
2022-07-07 21:50:08.158 UTC [51] LOG:  shutting down
2022-07-07 21:50:08.166 UTC [49] LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

2022-07-07 21:50:08.285 UTC [1] LOG:  starting PostgreSQL 13.7 (Debian 13.7-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-07-07 21:50:08.285 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2022-07-07 21:50:08.285 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2022-07-07 21:50:08.285 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-07-07 21:50:08.288 UTC [63] LOG:  database system was shut down at 2022-07-07 21:50:08 UTC
2022-07-07 21:50:08.294 UTC [1] LOG:  database system is ready to accept connections
2022-07-07 21:50:12.299 UTC [77] FATAL:  database "docker" does not exist
2022-07-07 21:50:16.000 UTC [78] ERROR:  relation "constance_config" does not exist at character 91
2022-07-07 21:50:16.000 UTC [78] STATEMENT:  SELECT "constance_config"."id", "constance_config"."key", "constance_config"."value" FROM "constance_config" WHERE "constance_config"."key" IN ('ALLOW_REGISTRATION', 'ALLOW_UPLOAD', 'SKIP_PATTERNS', 'HEAVYWEIGHT_PROCESS', 'MAP_API_KEY', 'IMAGE_DIRS')
2022-07-07 21:50:16.001 UTC [78] ERROR:  relation "constance_config" does not exist at character 91
2022-07-07 21:50:16.001 UTC [78] STATEMENT:  SELECT "constance_config"."id", "constance_config"."key", "constance_config"."value" FROM "constance_config" WHERE "constance_config"."key" = 'ALLOW_UPLOAD' LIMIT 21
2022-07-07 21:50:16.002 UTC [78] ERROR:  relation "constance_config" does not exist at character 91
2022-07-07 21:50:16.002 UTC [78] STATEMENT:  SELECT "constance_config"."id", "constance_config"."key", "constance_config"."value" FROM "constance_config" WHERE "constance_config"."key" = 'ALLOW_UPLOAD' LIMIT 21
2022-07-07 21:50:17.391 UTC [86] FATAL:  database "docker" does not exist
2022-07-07 21:50:18.793 UTC [87] ERROR:  relation "constance_config" does not exist at character 91
2022-07-07 21:50:18.793 UTC [87] STATEMENT:  SELECT "constance_config"."id", "constance_config"."key", "constance_config"."value" FROM "constance_config" WHERE "constance_config"."key" = 'ALLOW_UPLOAD' LIMIT 21
2022-07-07 21:50:18.793 UTC [87] ERROR:  relation "constance_config" does not exist at character 91
2022-07-07 21:50:18.793 UTC [87] STATEMENT:  SELECT "constance_config"."id", "constance_config"."key", "constance_config"."value" FROM "constance_config" WHERE "constance_config"."key" = 'ALLOW_UPLOAD' LIMIT 21
2022-07-07 21:50:22.481 UTC [95] FATAL:  database "docker" does not exist
2022-07-07 21:50:27.581 UTC [104] FATAL:  database "docker" does not exist
2022-07-07 21:50:32.774 UTC [118] FATAL:  database "docker" does not exist
2022-07-07 21:50:37.881 UTC [126] FATAL:  database "docker" does not exist
2022-07-07 21:50:43.014 UTC [134] FATAL:  database "docker" does not exist
2022-07-07 21:50:48.141 UTC [142] FATAL:  database "docker" does not exist
2022-07-07 21:50:53.317 UTC [150] FATAL:  database "docker" does not exist
2022-07-07 21:50:58.482 UTC [161] FATAL:  database "docker" does not exist
2022-07-07 21:51:03.656 UTC [175] FATAL:  database "docker" does not exist
2022-07-07 21:51:08.787 UTC [194] FATAL:  database "docker" does not exist
2022-07-07 21:51:13.923 UTC [204] FATAL:  database "docker" does not exist
2022-07-07 21:51:19.132 UTC [215] FATAL:  database "docker" does not exist
2022-07-07 21:51:24.344 UTC [226] FATAL:  database "docker" does not exist
2022-07-07 21:51:29.417 UTC [238] FATAL:  database "docker" does not exist
2022-07-07 21:51:34.559 UTC [249] FATAL:  database "docker" does not exist
quartztester commented 2 years ago

I am able to reproduce this error. Most likely caused after my commit from #56. However, this error does not seeming appear to be interfering with account creation or general application experience.

Any ideas on why database "docker" is being referenced?

derneuere commented 2 years ago

The name of the db is written down in librephotos.env. This file should be renamed to .env

The name docker is usually the dbUser name. This error happens every five seconds, so my guess would be, that the error is somewhere here: https://github.com/LibrePhotos/librephotos-docker/blob/09dbe057444481dc1aca004073bbafda90f3a71e/docker-compose.yml#L38

quartztester commented 2 years ago

I've been trying to implement different ways for the wait function to not be recalled upon successful initialization of the database. So far I have had no luck. I do not know why the pg_isready is not able to connect to the database with the correct username. It seems as though it can't find the DB within the container. Even when 2022-07-07 21:50:08.294 UTC [1] LOG: database system is ready to accept connections

This is with 'librephotos.env' being changed to '.env'.

Again to note in my previous comment, this error does not seem to impact functionality nor usage. The pg_isready command is not ending after the database is setup. The 'test:' is somehow working as intended to delay the backend startup.

The question is: why is the test not ending?

bleomycin commented 2 years ago

I'm sorry I can't be more helpful other than to add that while I'm unsure if it is related I did notice that performance seemed extremely slow when scanning new photos to the database of this fresh installation. By extremely slow I mean only processing a few photos a minute on an AMD ryzen 5600g processor with 64GB ram on all ssd storage.

quartztester commented 2 years ago

"Docker go up, Docker go down"

I do not have enough knowledge of docker containers to be able to properly diagnose this issue fully. It does seem like a .sh script will need to be implemented in some way as shown in the proof-of-concept #41.

If anyone could show me channels to learn about "setting up a wrapper script" I would appreciate it. I tried a crude setup for wait-for-it but was not able to figure out how to path to ./wait-for-it.sh or where the code would go within the existing repo.

Using: https://docs.docker.com/compose/startup-order/ Such that: command: ["./wait-for-it.sh", "db:5432", "--", "python", "app.py"] would check for a databse. Or as in the second example: command: ["./wait-for-postgres.sh", "db", "python", "app.py"] would do the same with a shorter script file.

(I am assuming in each, python & app.py is not needed in this case)

Other:

https://stackoverflow.com/questions/15301826/psql-fatal-role-postgres-does-not-exist https://github.com/docker-library/postgres/issues/146 https://gist.github.com/roylee0704/b5c8090e6cbfe1a9ae6c63062623a7cd#file-dockergrep-sh https://github.com/docker-library/postgres/issues/880 https://github.com/docker/compose/issues/8154 https://stackoverflow.com/questions/55762806/in-this-simple-docker-wrapper-script-example-how-may-one-correctly-pass-a-curre

quartztester commented 2 years ago

I did notice that performance seemed extremely slow when scanning new photos to the database of this fresh installation.

@bleomycin Could you at all copy the backend and db docker logs here to see if it's related?

quartztester commented 2 years ago

After looking into it for another day, nada. Here are somethings I was looking into.

https://www.howtogeek.com/devops/how-and-why-to-add-health-checks-to-your-docker-containers/ https://stackoverflow.com/questions/16931244/checking-if-output-of-a-command-contains-a-certain-string-in-a-shell-script https://stackoverflow.com/questions/34724980/finding-a-string-in-docker-logs-of-container

https://stackoverflow.com/questions/31887258/get-docker-container-names https://frightanic.com/computers/docker-default-container-names/ https://stackoverflow.com/questions/31887258/get-docker-container-names https://docker-docs.uclv.cu/engine/reference/commandline/exec/

(Extremely messy code)
#! /bin/sh

#test code 1
if docker exec -it db pg_isready -U docker | grep -q '/var/run/postgresql:5432 - accepting connections'; 
then
    echo "0"
else
    echo "1"
fi

#test code 2
set -e

host="$1"
shift

until psql -h "$dbHost" -U "$dbUser" -c '\q'; do
    >&2 echo "Postgres is unavailable - sleeping"
    sleep 1
done
>&2 echo "Postgres is up - executing command"
exec "$@"
derneuere commented 2 years ago

I played around with it too. GitHub Copilot suggested a valid alternative that works :D Would be great if you could confirm, if it works on your system too.

quartztester commented 2 years ago

(edit:) @derneuere I see the commit, testing out now.

quartztester commented 2 years ago

Error is gone! Thank you!

As for performance in response to @bleomycin: 100 photos scanned within 3 minutes. Default config, gtx 1080ti sc2, R7 2700X, 32gb ram, regular ssd. For some odd reason my "things" album doesn't seem to be showing thumbnails even though I can still search for the terms. However, if I change to a different directory with only 2 photos instead of 100 they do appear.

100 photos scan: image image

2 photos scan: image