teslamate-org / teslamate

A self-hosted data logger for your Tesla 🚘
https://docs.teslamate.org
MIT License
5.76k stars 719 forks source link

teslamate container keeps on restarting / database connection fails #2918

Closed tsandner closed 8 months ago

tsandner commented 1 year ago

Is there an existing issue for this?

What happened?

I'm new to teslamate and installed a new Ubuntu 22.04.1 LTS and deployed teslamate. I could loginto the teslamate web ui and provide access key and refresh token and I could log into grafana, but grafana showed "query data issues" and I thougt it might be the issue with a space before the database passowrd like described here: https://github.com/adriankumpf/teslamate/discussions/2773

I've decided to perform a fresh deployment and killed all containers and did a docker system prune --all and did a fresh deployment via docker-compose up -d after adjusting the docker-compose.yml.

However for some reason the teslamate container keeps restarting and it looks liek there is some issue with the db conneciton but I really don't know where this is coming from since I pruned all containers before.

Expected Behavior

No response

Steps To Reproduce

No response

Relevant log output

docker@docker:~$ docker ps
CONTAINER ID   IMAGE                        COMMAND                  CREATED          STATUS                          PORTS                                       NAMES
831b6e369637   postgres:14                  "docker-entrypoint.s…"   10 minutes ago   Up 10 minutes                   5432/tcp                                    docker_database_1
8c5463375fe7   teslamate/grafana:latest     "/run.sh"                10 minutes ago   Up 10 minutes                   0.0.0.0:3000->3000/tcp, :::3000->3000/tcp   docker_grafana_1
3eb379705d40   teslamate/teslamate:latest   "tini -- /bin/sh /en…"   10 minutes ago   Restarting (1) 24 seconds ago                                               docker_teslamate_1
1c7d4cd279b3   eclipse-mosquitto:2          "/docker-entrypoint.…"   10 minutes ago   Up 10 minutes                   1883/tcp                                    docker_mosquitto_1

docker@docker:~$ docker logs --tail 50 --follow 3eb379705d40

    (ecto_sql 3.8.3) lib/ecto/adapters/sql.ex:932: Ecto.Adapters.SQL.raise_sql_call_error/1
    (elixir 1.13.4) lib/enum.ex:1593: Enum."-map/2-lists^map/1-0-"/2
    (ecto_sql 3.8.3) lib/ecto/adapters/sql.ex:1024: Ecto.Adapters.SQL.execute_ddl/4
    (ecto_sql 3.8.3) lib/ecto/migrator.ex:696: Ecto.Migrator.verbose_schema_migration/3
    (ecto_sql 3.8.3) lib/ecto/migrator.ex:510: Ecto.Migrator.lock_for_migrations/4
    (ecto_sql 3.8.3) lib/ecto/migrator.ex:422: Ecto.Migrator.run/4
    (ecto_sql 3.8.3) lib/ecto/migrator.ex:146: Ecto.Migrator.with_repo/3
    (teslamate 1.27.1) lib/teslamate/release.ex:9: anonymous fn/2 in TeslaMate.Release.migrate/0
2022-09-27 20:20:03.877 [error] Postgrex.Protocol (#PID<0.166.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "teslamate"
2022-09-27 20:20:03.877 [error] Postgrex.Protocol (#PID<0.165.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "teslamate"
2022-09-27 20:20:05.483 [error] Postgrex.Protocol (#PID<0.166.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "teslamate"
2022-09-27 20:20:06.053 [error] Postgrex.Protocol (#PID<0.165.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "teslamate"
2022-09-27 20:20:06.830 [error] Could not create schema migrations table. This error usually happens due to the following:

  * The database does not exist
  * The "schema_migrations" table, which Ecto uses for managing
    migrations, was defined by another library
  * There is a deadlock while migrating (such as using concurrent
    indexes with a migration_lock)

To fix the first issue, run "mix ecto.create".

To address the second, you can run "mix ecto.drop" followed by
"mix ecto.create". Alternatively you may configure Ecto to use
another table and/or repository for managing migrations:

    config :teslamate, TeslaMate.Repo,
      migration_source: "some_other_table_for_schema_migrations",
      migration_repo: AnotherRepoForSchemaMigrations

The full error report is shown below.

** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2972ms. This means requests are coming in and your connection pool cannot serve them fast enough. You can address this by:

  1. Ensuring your database is available and that you can connect to it
  2. Tracking down slow queries and making sure they are running fast enough
  3. Increasing the pool_size (although this increases resource consumption)
  4. Allowing requests to wait longer by increasing :queue_target and :queue_interval

See DBConnection.start_link/2 for more information

    (ecto_sql 3.8.3) lib/ecto/adapters/sql.ex:932: Ecto.Adapters.SQL.raise_sql_call_error/1
    (elixir 1.13.4) lib/enum.ex:1593: Enum."-map/2-lists^map/1-0-"/2
    (ecto_sql 3.8.3) lib/ecto/adapters/sql.ex:1024: Ecto.Adapters.SQL.execute_ddl/4
    (ecto_sql 3.8.3) lib/ecto/migrator.ex:696: Ecto.Migrator.verbose_schema_migration/3
    (ecto_sql 3.8.3) lib/ecto/migrator.ex:510: Ecto.Migrator.lock_for_migrations/4
    (ecto_sql 3.8.3) lib/ecto/migrator.ex:422: Ecto.Migrator.run/4
    (ecto_sql 3.8.3) lib/ecto/migrator.ex:146: Ecto.Migrator.with_repo/3
    (teslamate 1.27.1) lib/teslamate/release.ex:9: anonymous fn/2 in TeslaMate.Release.migrate/0

Attaching to docker_teslamate_1
teslamate_1  | 2022-09-27 20:18:33.634 [error] Postgrex.Protocol (#PID<0.166.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "teslamate"
teslamate_1  | 2022-09-27 20:18:33.634 [error] Postgrex.Protocol (#PID<0.165.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "teslamate"
teslamate_1  | 2022-09-27 20:18:35.598 [error] Postgrex.Protocol (#PID<0.166.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "teslamate"
teslamate_1  | 2022-09-27 20:18:36.595 [error] Could not create schema migrations table. This error usually happens due to the following:
teslamate_1  |
teslamate_1  |   * The database does not exist
teslamate_1  |   * The "schema_migrations" table, which Ecto uses for managing
teslamate_1  |     migrations, was defined by another library
teslamate_1  |   * There is a deadlock while migrating (such as using concurrent
teslamate_1  |     indexes with a migration_lock)
teslamate_1  |
teslamate_1  | To fix the first issue, run "mix ecto.create".
teslamate_1  |
teslamate_1  | To address the second, you can run "mix ecto.drop" followed by
teslamate_1  | "mix ecto.create". Alternatively you may configure Ecto to use
teslamate_1  | another table and/or repository for managing migrations:
teslamate_1  |
teslamate_1  |     config :teslamate, TeslaMate.Repo,
teslamate_1  |       migration_source: "some_other_table_for_schema_migrations",
teslamate_1  |       migration_repo: AnotherRepoForSchemaMigrations
teslamate_1  |
teslamate_1  | The full error report is shown below.
teslamate_1  |
teslamate_1  | ** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2966ms. This means requests are coming in and your connection pool cannot serve them fast enough. You can address this by:
teslamate_1  |
teslamate_1  |   1. Ensuring your database is available and that you can connect to it
teslamate_1  |   2. Tracking down slow queries and making sure they are running fast enough
teslamate_1  |   3. Increasing the pool_size (although this increases resource consumption)
teslamate_1  |   4. Allowing requests to wait longer by increasing :queue_target and :queue_interval
teslamate_1  |
teslamate_1  | See DBConnection.start_link/2 for more information
teslamate_1  |
teslamate_1  |     (ecto_sql 3.8.3) lib/ecto/adapters/sql.ex:932: Ecto.Adapters.SQL.raise_sql_call_error/1
teslamate_1  |     (elixir 1.13.4) lib/enum.ex:1593: Enum."-map/2-lists^map/1-0-"/2
teslamate_1  |     (ecto_sql 3.8.3) lib/ecto/adapters/sql.ex:1024: Ecto.Adapters.SQL.execute_ddl/4
teslamate_1  |     (ecto_sql 3.8.3) lib/ecto/migrator.ex:696: Ecto.Migrator.verbose_schema_migration/3
teslamate_1  |     (ecto_sql 3.8.3) lib/ecto/migrator.ex:510: Ecto.Migrator.lock_for_migrations/4
teslamate_1  |     (ecto_sql 3.8.3) lib/ecto/migrator.ex:422: Ecto.Migrator.run/4
teslamate_1  |     (ecto_sql 3.8.3) lib/ecto/migrator.ex:146: Ecto.Migrator.with_repo/3
teslamate_1  |     (teslamate 1.27.1) lib/teslamate/release.ex:9: anonymous fn/2 in TeslaMate.Release.migrate/0
teslamate_1  | 2022-09-27 20:18:38.216 [error] Postgrex.Protocol (#PID<0.166.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "teslamate"
teslamate_1  | 2022-09-27 20:18:38.216 [error] Postgrex.Protocol (#PID<0.165.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "teslamate"
teslamate_1  | 2022-09-27 20:18:39.641 [error] Postgrex.Protocol (#PID<0.165.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "teslamate"
teslamate_1  | 2022-09-27 20:18:39.651 [error] Postgrex.Protocol (#PID<0.166.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "teslamate"
teslamate_1  | 2022-09-27 20:18:41.178 [error] Could not create schema migrations table. This error usually happens due to the following:
teslamate_1  |
teslamate_1  |   * The database does not exist
teslamate_1  |   * The "schema_migrations" table, which Ecto uses for managing
teslamate_1  |     migrations, was defined by another library
teslamate_1  |   * There is a deadlock while migrating (such as using concurrent
teslamate_1  |     indexes with a migration_lock)
teslamate_1  |
teslamate_1  | To fix the first issue, run "mix ecto.create".
teslamate_1  |
teslamate_1  | To address the second, you can run "mix ecto.drop" followed by
teslamate_1  | "mix ecto.create". Alternatively you may configure Ecto to use
teslamate_1  | another table and/or repository for managing migrations:
teslamate_1  |
teslamate_1  |     config :teslamate, TeslaMate.Repo,
teslamate_1  |       migration_source: "some_other_table_for_schema_migrations",
teslamate_1  |       migration_repo: AnotherRepoForSchemaMigrations
teslamate_1  |TeslaMate.Release.migrate/0

Screenshots

No response

Additional data

No response

Type of installation

Docker

Version

1.27.1 (?)

pihomeserver commented 1 year ago

Try to connect to the container and run the suggested commands or crash the container and the related volumes and start again

wzc89757 commented 1 year ago

你好,我有同样的问题。有人知道如何解决吗?

同样的问题 解决不了

nasula commented 1 year ago

Seems like it's maybe an authentication problem, which I can't figure out. Looking at teslamate logs gives exactly the same, but looking at the db container: 2022-11-27 18:03:03.883 UTC [1] LOG: database system is ready to accept connections 2022-11-27 18:03:05.503 UTC [35] FATAL: password authentication failed for user "teslamate" 2022-11-27 18:03:05.503 UTC [35] DETAIL: Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"

jtuckr commented 1 year ago

Had the same issue, and for me it was resolved by doing docker system prune --all and also docker volume prune --force. If you look in the database log, there was a line that essentially said "already found a 'teslamate' database in this volume, so i'm going to use that" which in my case meant the previous password I tried to configure (and failed because YAML sucks and I have a hard time remembering when to use quotes for strings) for the teslamate database user was still configured, thus it getting the authentication failed message. Hope that resolves this error for others!

radhoo2k10 commented 1 year ago

I had the same problem. Used a long and complicated password with alot of special letters in them. The teslamate was restarting constantly. Tried the prune commands that @jtuckr posted with no luck. Same problem. Installed portainer https://pimylifeup.com/raspberry-pi-portainer/ and deleted every instance of the teslamate I could find. Under containers I stopped and deleted teslamate. Under volume I did the same. As well under Images. Then I tried the docker-compose up -d with shorter and less complicated passwords and everything works.

can't connect port 4000 teslamate

teslamate restarting

ouzc12358 commented 11 months ago

Just don't understand why it happened , when I tried to deploy it in my NAS just never worked , but everything is going well on my vps, and the errors is exactly same as it up there!

Testmate container just keep restarting ,

The resource is totally ok there , only 20% usage of CPU and similar in RAM

And i also delete every container of Teslamate related , reinstall for hundreds times, nothing changed

Any one have any clue for the issue????

sparvata commented 11 months ago

try the following command (enter Ctrl+C to exit following the logs) and check if there any errors docker-compose logs -f

ouzc12358 commented 11 months ago

try the following command (enter Ctrl+C to exit following the logs) and check if there any errors

docker-compose logs -f

tesla-teslamate-1 | The full error report is shown below. tesla-teslamate-1 | tesla-teslamate-1 | ** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2965ms. This means requests are coming in and your connection pool cannot serve them fast enough. You can address this by: tesla-teslamate-1 | tesla-teslamate-1 | 1. Ensuring your database is available and that you can connect to it tesla-teslamate-1 | 2. Tracking down slow queries and making sure they are running fast enough tesla-teslamate-1 | 3. Increasing the pool_size (although this increases resource consumption) tesla-teslamate-1 | 4. Allowing requests to wait longer by increasing :queue_target and :queue_interval tesla-teslamate-1 | tesla-teslamate-1 | See DBConnection.start_link/2 for more information tesla-teslamate-1 | tesla-teslamate-1 | (ecto_sql 3.10.1) lib/ecto/adapters/sql.ex:913: Ecto.Adapters.SQL.raise_sql_call_error/1 tesla-teslamate-1 | (elixir 1.15.0-rc.1) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2 tesla-teslamate-1 | (ecto_sql 3.10.1) lib/ecto/adapters/sql.ex:1005: Ecto.Adapters.SQL.execute_ddl/4 tesla-teslamate-1 | (ecto_sql 3.10.1) lib/ecto/migrator.ex:738: Ecto.Migrator.verbose_schema_migration/3 tesla-teslamate-1 | (ecto_sql 3.10.1) lib/ecto/migrator.ex:552: Ecto.Migrator.lock_for_migrations/4 tesla-teslamate-1 | (ecto_sql 3.10.1) lib/ecto/migrator.ex:428: Ecto.Migrator.run/4 tesla-teslamate-1 | (ecto_sql 3.10.1) lib/ecto/migrator.ex:170: Ecto.Migrator.with_repo/3 tesla-teslamate-1 | nofile:1: (file) tesla-database-1 | 2023-09-28 04:02:57.132 UTC [3046] FATAL: password authentication failed for user "teslamate" tesla-database-1 | 2023-09-28 04:02:57.132 UTC [3046] DETAIL: Connection matched pg_hba.conf line 100: "host all all all scram-sha-256" tesla-database-1 | 2023-09-28 04:02:57.133 UTC [3045] FATAL: password authentication failed for user "teslamate" tesla-database-1 | 2023-09-28 04:02:57.133 UTC [3045] DETAIL: Connection matched pg_hba.conf line 100: "host all all all scram-sha-256" tesla-database-1 | 2023-09-28 04:02:58.390 UTC [3047] FATAL: password authentication failed for user "teslamate" tesla-database-1 | 2023-09-28 04:02:58.390 UTC [3047] DETAIL: Connection matched pg_hba.conf line 100: "host all all all scram-sha-256" tesla-teslamate-1 exited with code 1

ouzc12358 commented 11 months ago

And I actually use same yaml file as my VPS setting,

pihomeserver commented 11 months ago

Message in log is not correct ? It says at the beginning that DB connection fails. So the container stops except if in the config you say that it should always restart and then your enter in a no end loop of restart

ouzc12358 commented 11 months ago

Just don't understand why it happened , when I tried to deploy it in my NAS just never worked , but everything is going well on my vps, and the errors is exactly same as it up there!

Testmate container just keep restarting ,

The resource is totally ok there , only 20% usage of CPU and similar in RAM

And i also delete every container of Teslamate related , reinstall for hundreds times, nothing changed

Any one have any clue for the issue????

Problem solved for me , the Grafana port , the default 5432 port is already used by other process, you need to change to a new one for grafana in your docker-compose.yml file ,once done , run the docker-compose up -d then all works

github-actions[bot] commented 9 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

dengke80622 commented 4 months ago

Had the same issue, and for me it was resolved by doing docker system prune --all and also docker volume prune --force. If you look in the database log, there was a line that essentially said "already found a 'teslamate' database in this volume, so i'm going to use that" which in my case meant the previous password I tried to configure (and failed because YAML sucks and I have a hard time remembering when to use quotes for strings) for the teslamate database user was still configured, thus it getting the authentication failed message. Hope that resolves this error for others!

Thanks, clean up resolves the auth issue