'ERROR: relation "entity_alarm" does not exist"

i'm running TB v3.3.4.1P on Ubuntu. i have an analytics aggregate stream node, it should be counting produced units per hour. whenever i try to edit it i receive the error below "could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet"

in the Things Board log file i get the below error whenever i try to add or delete any device. "2022-04-13 21:24:45,297 [http-nio-0.0.0.0-8080-exec-3] WARN o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 42P01 2022-04-13 21:24:45,298 [http-nio-0.0.0.0-8080-exec-3] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ERROR: relation "entity_alarm" does not exist"

Postgres Log File " postgres@thingsboard ERROR: relation "entity_alarm" does not exist at character 306 2022-04-15 13:29:09.746 UTC [2114] postgres@thingsboard STATEMENT: select entityalar0_.alarm_id as alarm_id1_17_, entityalar0_.entity_id as entity_i2_17_, entityalar0_.alarm_type as alarm_ty3_17_, entityalar0_.created_time as created_4_17_, entityalar0_.customer_id as customer5_17_, entityalar0_.entity_type as entity_t6_17_, entityalar0_.tenant_id as tenant_i7_17_ from entity_alarm entityalar0_ where entityalar0_.entity_id=$1 "

knowing that an entity alarm was never created. Appreciate your kind support.



Solution 1:[1]

I suppose it's because of a failed upgrade or at least some warning during the upgrade. Have you installed that version or has it been updated from an older one?

Executing this piece of the schema.sql creates the table and it should solve the problem.

CREATE TABLE IF NOT EXISTS entity_alarm (
    tenant_id uuid NOT NULL,
    entity_type varchar(32),
    entity_id uuid NOT NULL,
    created_time bigint NOT NULL,
    alarm_type varchar(255) NOT NULL,
    customer_id uuid,
    alarm_id uuid,
    CONSTRAINT entity_alarm_pkey PRIMARY KEY (entity_id, alarm_id),
    CONSTRAINT fk_entity_alarm_id FOREIGN KEY (alarm_id) REFERENCES alarm(id) ON DELETE CASCADE
);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 karel