Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres issue starting up / vid "has already been taken" #90

Closed
netkruzer opened this issue Aug 13, 2019 · 6 comments
Closed

Postgres issue starting up / vid "has already been taken" #90

netkruzer opened this issue Aug 13, 2019 · 6 comments

Comments

@netkruzer
Copy link

I had teslamate working on my Ubuntu computer, but it's having issues now.

teslamate_1 | 13:41:10.682 [info] Already up
teslamate_1 | 13:41:16.681 [info] Running TeslaMateWeb.Endpoint with cowboy 2.6.3 at :::4000 (http)
teslamate_1 | 13:41:16.681 [info] Access TeslaMateWeb.Endpoint at http://192.168.10.51
teslamate_1 | 13:41:16.760 [info] Found car 'Kevin Model 3'
teslamate_1 | 13:41:16.773 [info] Application teslamate exited: TeslaMate.Application.start(:normal, []) returned an error: shutdown: failed to start child: TeslaMate.Vehicles
teslamate_1 | ** (EXIT) an exception was raised:
teslamate_1 | ** (MatchError) no match of right hand side value: {:error, #Ecto.Changeset<action: :insert, changes: %{efficiency: 0.153, eid: 36230209430047724, model: "M3", vid: 1749778265}, errors: [vid: {"has already been taken", [constraint: :unique, constraint_name: "cars_vid_index"]}], data: #TeslaMate.Log.Car<>, valid?: false>}
teslamate_1 | (teslamate) lib/teslamate/vehicles.ex:70: TeslaMate.Vehicles.create_new!/1
teslamate_1 | (teslamate) lib/teslamate/vehicles.ex:25: anonymous fn/2 in TeslaMate.Vehicles.init/1
teslamate_1 | (elixir) lib/enum.ex:1336: Enum."-map/2-lists^map/1-0-"/2
teslamate_1 | (teslamate) lib/teslamate/vehicles.ex:25: TeslaMate.Vehicles.init/1
teslamate_1 | (stdlib) supervisor.erl:295: :supervisor.init/1
teslamate_1 | (stdlib) gen_server.erl:374: :gen_server.init_it/2
teslamate_1 | (stdlib) gen_server.erl:342: :gen_server.init_it/6
teslamate_1 | (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
teslamate_1 | {"Kernel pid terminated",application_controller,"{application_start_failure,teslamate,{{shutdown,{failed_to_start_child,'Elixir.TeslaMate.Vehicles',{{badmatch,{error,#{'struct' => 'Elixir.Ecto.Changeset',action => insert,changes => #{efficiency => 0.153,eid => 36230209430047724,model => <<"M3">>,vid => 1749778265},constraints => [#{constraint => <<"cars_vid_index">>,error_message => <<"has already been taken">>,error_type => unique,field => vid,match => exact,type => unique},#{constraint => <<"cars_eid_index">>,error_message => <<"has already been taken">>,error_type => unique,field => eid,match => exact,type => unique}],data => #{'meta' => #{'struct' => 'Elixir.Ecto.Schema.Metadata',context => nil,prefix => nil,schema => 'Elixir.TeslaMate.Log.Car',source => <<"cars">>,state => built},'struct' => 'Elixir.TeslaMate.Log.Car',charging_processes => #{'cardinality' => many,'field' => charging_processes,'owner' => 'Elixir.TeslaMate.Log.Car','struct' => 'Elixir.Ecto.Association.NotLoaded'},drives => #{'cardinality' => many,'field' => drives,'owner' => 'Elixir.TeslaMate.Log.Car','struct' => 'Elixir.Ecto.Association.NotLoaded'},efficiency => nil,eid => 36230209430047724,id => nil,inserted_at => nil,model => nil,positions => #{'cardinality' => many,'field' => positions,'owner' => 'Elixir.TeslaMate.Log.Car','struct' => 'Elixir.Ecto.Association.NotLoaded'},updated_at => nil,vid => 1749778265},empty_values => [<<>>],errors => [{vid,{<<"has already been taken">>,[{constraint,unique},{constraint_name,<<"cars_vid_index">>}]}}],filters => #{},params => #{<<"efficiency">> => 0.153,<<"eid">> => 36230209430047724,<<"model">> => <<"M3">>,<<"vid">> => 1749778265},prepare => [],repo => 'Elixir.TeslaMate.Repo',repo_opts => [],required => [eid,vid,model,efficiency],types => #{charging_processes => {assoc,#{'struct' => 'Elixir.Ecto.Association.Has',cardinality => many,defaults => [],field => charging_processes,on_cast => nil,on_delete => nothing,on_replace => raise,owner => 'Elixir.TeslaMate.Log.Car',owner_key => id,queryable => 'Elixir.TeslaMate.Log.ChargingProcess',related => 'Elixir.TeslaMate.Log.ChargingProcess',related_key => car_id,relationship => child,unique => true,where => []}},drives => {assoc,#{'struct' => 'Elixir.Ecto.Association.Has',cardinality => many,defaults => [],field => drives,on_cast => nil,on_delete => nothing,on_replace => raise,owner => 'Elixir.TeslaMate.Log.Car',owner_key => id,queryable => 'Elixir.TeslaMate.Log.Drive',related => 'Elixir.TeslaMate.Log.Drive',related_key => car_id,relationship => child,unique => true,where => []}},efficiency => float,eid => integer,id => id,inserted_at => naive_datetime,model => string,positions => {assoc,#{'struct' => 'Elixir.Ecto.Association.Has',cardinality => many,defaults => [],field => positions,on_cast => nil,on_delete => nothing,on_replace => raise,owner => 'Elixir.TeslaMate.Log.Car',owner_key => id,queryable => 'Elixir.TeslaMate.Log.Position',related => 'Elixir.TeslaMate.Log.Position',related_key => car_id,relationship => child,unique => true,where => []}},updated_at => naive_datetime,vid => integer},'valid?' => false,validations => []}}},[{'Elixir.TeslaMate.Vehicles','create_new!',1,[{file,"lib/teslamate/vehicles.ex"},{line,70}]},{'Elixir.TeslaMate.Vehicles','-init/1-fun-0-',2,[{file,"lib/teslamate/vehicles.ex"},{line,25}]},{'Elixir.Enum','-map/2-lists^map/1-0-',2,[{file,"lib/enum.ex"},{line,1336}]},{'Elixir.TeslaMate.Vehicles',init,1,[{file,"lib/teslamate/vehicles.ex"},{line,25}]},{supervisor,init,1,[{file,"supervisor.erl"},{line,295}]},{gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}}},{'Elixir.TeslaMate.Application',start,[normal,[]]}}}"}
teslamate_1 | Kernel pid terminated (application_controller) ({application_start_failure,teslamate,{{shutdown,{failed_to_start_child,'Elixir.TeslaMate.Vehicles',{{badmatch,{error,#{'struct' => 'Elixir.Ecto.Chan
teslamate_1 |
teslamate_1 | Crash dump is being written to: erl_crash.dump...done
db_1 | 2019-08-13 20:41:20.582 UTC [685] LOG: incomplete startup packet
teslamate_1 | 13:41:22.813 [info] Already up

I tried connecting to the docker-compose psql and looking at the database directly, but it seemed to be fine:

sudo docker-compose run --rm db psql -h db -U teslamate

teslamate=# SELECT * from cars;
id | eid | vid | model | efficiency | inserted_at | updated_at
----+-------------------+------------+-------+------------+---------------------+---------------------
1 | 19822922099185452 | 1749778265 | M3 | 0.153 | 2019-07-31 17:46:32 | 2019-07-31 17:46:32
(1 row)

teslamate=# \dt
List of relations
Schema | Name | Type | Owner
--------+--------------------+-------+-----------
public | addresses | table | teslamate
public | cars | table | teslamate
public | charges | table | teslamate
public | charging_processes | table | teslamate
public | drives | table | teslamate
public | geofences | table | teslamate
public | positions | table | teslamate
public | schema_migrations | table | teslamate
public | settings | table | teslamate
public | states | table | teslamate
public | tokens | table | teslamate
public | updates | table | teslamate
(12 rows)

I'm not sure how to get this fixed without wiping my entire docker install. Help?

@adriankumpf
Copy link
Collaborator

adriankumpf commented Aug 13, 2019

Someone else reported the same issue today. The underlying problem is actually a quirk on Tesla's end.

They recently changed the IDs (!!!) of some cars. See timdorr/tesla-api#139

Unfortunately you have to fix it manually by updating the entry in the database table "cars". Change the eid of entry that has the vid 1749778265 to "36230209430047724" (I got those values from the log output you posted).

Edit: This is how it should be

eid: 36230209430047724
vid: 1749778265

@netkruzer
Copy link
Author

Well that's annoying of Tesla to do that.

kevin@NUC-TV:~/teslamate$ sudo docker-compose run --rm db psql -h db -U teslamate
[sudo] password for kevin:
Password for user teslamate:
psql (11.5 (Debian 11.5-1.pgdg90+1))
Type "help" for help.

teslamate=# SELECT * from cars;
id | eid | vid | model | efficiency | inserted_at | updated_at
----+-------------------+------------+-------+------------+---------------------+---------------------
1 | 19822922099185452 | 1749778265 | M3 | 0.153 | 2019-07-31 17:46:32 | 2019-07-31 17:46:32
(1 row)

teslamate=# UPDATE cars set vid=36230209430047724 ;
UPDATE 1
teslamate=#

That fixed that issue... now it's saying this:

teslamate_1 | Server: 192.168.10.51:4000 (http)
teslamate_1 | Request: GET /
teslamate_1 | ** (exit) exited in: :gen_statem.call(:"1", :summary, :infinity)
teslamate_1 | ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started

This happens whenever I attempt to view the page at port:4000. Ideas?

@adriankumpf
Copy link
Collaborator

You might have changed the wrong id :)

This is how it should be:

eid: 36230209430047724
vid: 1749778265

@netkruzer
Copy link
Author

netkruzer commented Aug 13, 2019

Yup, I did that wrong, had to delete the new car.

teslamate=# DELETE FROM cars where eid=36230209430047724;
DELETE 1
teslamate=# SELECT * from cars;
id | eid | vid | model | efficiency | inserted_at | updated_at
----+-------------------+-------------------+-------+------------+---------------------+---------------------
1 | 19822922099185452 | 36230209430047724 | M3 | 0.153 | 2019-07-31 17:46:32 | 2019-07-31 17:46:32
(1 row)

teslamate=# update cars set eid=36230209430047724 ;
UPDATE 1
teslamate=# update cars set vid=1749778265 ;
UPDATE 1
teslamate=# SELECT * from cars;
id | eid | vid | model | efficiency | inserted_at | updated_at
----+-------------------+------------+-------+------------+---------------------+---------------------
1 | 36230209430047724 | 1749778265 | M3 | 0.153 | 2019-07-31 17:46:32 | 2019-07-31 17:46:32
(1 row)

Thanks for your quick help. It's working again!

@adriankumpf
Copy link
Collaborator

adriankumpf commented Aug 13, 2019

Thanks for your quick help. It's working again!

Awesome!

There may be others affected by this problem as well. I'll pin this issue 👍

@adriankumpf adriankumpf pinned this issue Aug 13, 2019
@netkruzer
Copy link
Author

netkruzer commented Aug 13, 2019

FYI, the user needs to run the docker-compose in one ssh window and let it continue to error itself out, while you connect to that docker install with the command to command line Postgres in another SSH window:

sudo docker-compose run --rm db psql -h db -U teslamate

I didn't know much about how Docker worked until today. Even less about Postgres. Took me forever to figure out how to connect to a Postgres database inside of a Docker container.

@adriankumpf adriankumpf changed the title Postgres issue starting up Postgres issue starting up / vid "has already been taken" Aug 13, 2019
@adriankumpf adriankumpf unpinned this issue Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants