boschkundendienst / guacamole-docker-compose

Guacamole with docker-compose using PostgreSQL, nginx with SSL (self-signed)
GNU General Public License v3.0
991 stars 411 forks source link

ERROR: relation "guacamole_user" does not exist at character 505 #1

Closed Starli0n closed 4 years ago

Starli0n commented 6 years ago

Hi,

The project does not work out of the box anymore

I did not use the nginx part and commented it

After a docker-compose up -d, I have the following error while trying to connect to the url:

http://ip-server:8080/guacamole

$ docker logs postgres_guacamole_compose -f
2018-11-13 14:51:13.309 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2018-11-13 14:51:13.309 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2018-11-13 14:51:13.387 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2018-11-13 14:51:13.418 UTC [20] LOG:  database system was shut down at 2018-11-13 14:50:37 UTC
2018-11-13 14:51:13.562 UTC [1] LOG:  database system is ready to accept connections
2018-11-13 14:52:34.566 UTC [29] ERROR:  relation "guacamole_user" does not exist at character 505
2018-11-13 14:52:34.566 UTC [29] STATEMENT:  SELECT
                    guacamole_user.user_id,
                    guacamole_user.username,
                    password_hash,
                    password_salt,
                    password_date,
                    disabled,
                    expired,
                    access_window_start,
                    access_window_end,
                    valid_from,
                    valid_until,
                    timezone,
                    full_name,
                    email_address,
                    organization,
                    organizational_role,
                    MAX(start_date) AS last_active
                FROM guacamole_user
                LEFT JOIN guacamole_user_history ON guacamole_user_history.user_id = guacamole_user.user_id
                WHERE
                    guacamole_user.username = $1
                GROUP BY guacamole_user.user_id

Nevertheless, I have the correct Apache Tomcat home page at the address:

http://ip-server:8080

Could you please advice on the subject ?

Thank you in advance

boschkundendienst commented 6 years ago

Hi,

could you try to specify the Postgres Image like this to force using of 9.6.9?

...
  # postgres
  postgres:
    container_name: postgres_guacamole_compose
    environment:
      PGDATA: /var/lib/postgresql/data/guacamole
      POSTGRES_DB: guacamole_db
      POSTGRES_PASSWORD: ChooseYourOwnPasswordHere1234
      POSTGRES_USER: guacamole_user
    image: postgres:9.6.9
    networks:
      guacnetwork_compose:
    restart: always
    volumes:
    - ./init:/docker-entrypoint-initdb.d:ro
    - ./data:/var/lib/postgresql/data:rw
...

So effectively change image: postgres to image: postgres:9.6.9 and retry?

Also be aware, that if the containers are rebuilt with updated images it might be necessary to update the SQL Schema as described here (adopt to your installation):

Regards

Peter

Starli0n commented 6 years ago

Hi,

I retried with the specific version of postgres 9.6.9 but it changed nothing as I still have the same error.

I made a reset before, deleted all the files that were generated.

I am not sure what to do with the link you provided with, knowing that I am starting from scratch.

In the same way, what are the tags I should use for the two other images ?

Starli0n commented 6 years ago

I made another test by skipping the generation of the initdb.sql and I also have the same error.

So it seems that the postgres image does not take into account the script at the first run.

I do not know what to do to initiate the database with the script.

Starli0n commented 6 years ago

Actually, it was a permission issue and so /docker-entrypoint-initdb.d was skipped in the first place

I had a umask initially set to 077 and I set it to 0022 like the one defined inside the postgres image

This solved my issue

umask 0022

So the init folder and initdb.sql were set with the right permissions before starting the container

I tested with the last tags:

Thank you so much for your help

Xachman commented 4 years ago

Im getting this too while following the instructions

Xachman commented 4 years ago

umask for me is 0022

Xachman commented 4 years ago
postgres_guacamole_compose | PostgreSQL Database directory appears to contain a database; Skipping initialization

this seems to be the related error in the logs

Xachman commented 4 years ago

changing to postgress:9.6.9

and running ./reset.sh then ./prepare.sh has fixed the issue. I also set 777 permissions on the init folder.

This seems to still be an issue and some solution should be applied to the repo.

boschkundendienst commented 4 years ago

The prepare.sh script does not create a database, it just creates a "database setup script" using the commands from /opt/guacamole/bin/initdb.sh.

/opt/guacamole/bin/initdb.sh is shipped with guacamole and prepare.sh just calls it.

The result is ./init/initdb.sql

The official documentation for the postgresql docker image explains how to initialize a database when postgres ist started by placing initialization scripts in /docker-entrypoint-initdb.d.

The prepare.sh script uses an official script from guacamole (/opt/guacamole/bin/initdb.sh) to create initdb.sql. initdb.sql is then located in ./init/initdb.sql.

In docker-compose.yml, the folder ./init is mounted read-only into the postgres container as /docker-entrypoint-initdb.d.

When postgres starts, it recognizes the initalization scripts and creates the database in /var/lib/postgresql/data inside the container (./data outside of the container)

As also stated in the official documentation for the postgresql docker image:

Quote: scripts in /docker-entrypoint-initdb.d are only run if you start the container with a data directory that is empty; any pre-existing database will be left untouched on container startup

So I assume somehow you tried setting up guacamole using my scripts, a database has been created in ./data and that causes the error and of course using reset.sh will remove the database and things will work.

I hope I could clarify things and my assumptions were correct.

So this then is not a problem with this repo but with your local setup.

If you still have this problem (on a brand new system with a working docker environment, where the scripts never ran before), feel free to contact me again.

tablatronix commented 2 years ago

So whats this then when running prepare ?

ifelse: fatal: unable to exec /opt/guacamole/bin/initdb.sh: No such file or directory

boschkundendienst commented 2 years ago

Hi,

this error has nothing to do with the previous bug here. Please open a separate one if needed.

The error you get is from

docker run --rm guacamole/guacamole /opt/guacamole/bin/initdb.sh --postgres > ./init/initdb.sql

where docker pulls the guacamole image and starts a container to init the database. I would assume something is wrong with running a container or downloading images from the internet.

tablatronix commented 2 years ago

The end error is similar in logs, role guacamole does not exist.. I will investigate more, I think the image I was using was wrong, i had trouble finding a guac client for armv8, not an all in one image.

connwork commented 1 year ago

I'm dealing with this same issue.

I deleted all docker containers, completely cleared out the persistent volumes, and am getting this on reinstall.

I'm not sure how deleting all persistent data, dockers, everything, can still lead to some leftover database issue that prevents seamless reinstall.

Is it possibly related to this line in the postgres docker? /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*

starnutoditopo commented 1 year ago

If it can help, I just deleted the data and init directories, so that PostgreSql could recreate its files, then restarted the whole environment with docker compose ... up

boschkundendienst commented 1 year ago

I'm dealing with this same issue.

I deleted all docker containers, completely cleared out the persistent volumes, and am getting this on reinstall.

I'm not sure how deleting all persistent data, dockers, everything, can still lead to some leftover database issue that prevents seamless reinstall.

Is it possibly related to this line in the postgres docker? /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*

That's absolutely right. The database handling is as follows (from my understanding of the guacamole containers and postgres containers):

Guacamole needs a database that has a specific scheme. That's why they created the initdb.sh file which is included in the guacamole container. My prepare.sh script executes this initdb.sh file to create initdb.sql as a result.

The posgres container looks for an initdb.sql file in /docker-entrypoint-initdb.d/ folder. If it finds one, it executes it at startup (if no databse is present). With this mechanism the postgres database is ready for Guacamole. When the database has been created, postgres no longer executes the initdb.sql at startup, since a database is already present. So if you "initialized" the database once restarting Guacamole with docker-compose would not delete/overwrite/re-initialize the database. That's absolutely perfect since you don't want to overwrite an existing database that might already have connections and users configured. Even re-running prepare.sh would not harm the database since even the initdb.sql file is recreated postgres will not initialize the database again since it is already present.

If you want to start from scratch (lose everything) and you used the original version of my project you only have to

But be careful! reset.sh will completely remove the folder ./init (that holds the initdb.sql) and also the folders ./data/, ./record/ and ./nginx/ssl so the entire database, existing recordings and the SSL certificates will be deleted.

To start again after running reset.sh you have to re-run prepare.sh. After that when starting up with docker-compose up -d you would have a fresh installation of Guacamole.