Search code examples
postgresqldockerthingsboard

ThingsBoard Docker container deploy resulting in `PSQLException`


I want to deploy ThingsBoard as a Docker container. I use this image and I try to overwrite some environment variables to get connection with an external Postgres database.

I simply have a Postgres running on localhost:5432 with (empty) database thingsboard, I create the Docker volumes mytb-data and mytb-logs and I launch:

docker run -it -p 9090:9090 -p 1883:1883 -p 5683:5683/udp -v mytb-data:/data -v mytb-logs:/var/log/thingsboard -e SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/thingsboard -e SPRING_DATASOURCE_USERNAME=postgres -e SPRING_DATASOURCE_PASSWORD=<MY_PASSWORD_HERE> --name mytb --restart=always thingsboard/tb-postgres

The container starts, but the logs report the following error:

2020-11-03 07:55:40,480 [main] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ERROR: relation "admin_settings" does not exist
  Position: 152
... [OMITTED]
Caused by: org.postgresql.util.PSQLException: ERROR: relation "admin_settings" does not exist
  Position: 152
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2455)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2155)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:288)
        at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:430)
        at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:356)
        at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:168)
        at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:116)
        at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
        at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:57)
        ... 166 common frames omitted
pg_ctl: could not send stop signal (PID: 9): No such process

Any idea why this happens?


Solution

  • The environment variables shall be delimited with quotes '[...]' in Docker launch command.

    This is not necessary in Docker Compose.

    For Docker, launch

    docker run -it -p 9090:9090 -p 1883:1883 -p 5683:5683/udp --name thingsboard --restart always -e SPRING_DATASOURCE_URL='<URL>' -e SPRING_DATASOURCE_USERNAME='<USERNAME>' -e SPRING_DATASOURCE_PASSWORD='<PASSWORD>' thingsboard/tb-postgres
    
    

    Moreover, I was able to solve the issue using the following configuration (Docker Compose, similar for Docker):

    thingsboard:
    container_name: thingsboard
    image: thingsboard/tb-postgres
    restart: always
    environment:
        - SPRING_DATASOURCE_URL=jdbc:postgresql://<HOSTNAME>:<PORT>/thingsboard
        - SPRING_DATASOURCE_USERNAME=<USERNAME>
        - SPRING_DATASOURCE_PASSWORD=<PASSWORD>
    ports:
        - '9090:9090'
        - '1883:1883'
        - '5683:5683/udp'