Created 12-05-2017 03:12 PM
I am trying to remove old worker from the DB ( from ambari-server machine ) as the following
* reference - https://community.hortonworks.com/questions/52910/how-can-i-remove-registered-host-but-do-not-added....
psql -U ambari ambari Password for user ambari:
ambari-> select host_id from hosts where host_name='worker05.sys59.com'; host_id --------- 255 (1 row)
so I delete the host:
ambari=> Delete from hoststate where host_id=255 ambari-> Delete from hosts where host_id=255
ambari=> select host_id from hosts where host_name='worker05.sys59.com'; host_id --------- 255 (1 row)
this worker still exists in DB , ( host_id=255 ) , even I restart the ambari-server !!
why?
and how to total remove this worker include all worker properties from postgreSQL ?
Created 12-05-2017 08:21 PM
You can try the following approach to completely remove the unwanted host from your ambari Database.
0. Stop ambari-server.
# ambari-server stop
1. Please take a fresh ambari DB dump for safety and backup.
2. Now run the following SQL queries inside your ambari DB to delete the unwanted host. Please replace the "unwanted1.host.com" with your unwanted hostname and similarly the "351" with the "host_id" that you want to remove from your Database.
delete from execution_command where task_id in (select task_id from host_role_command where host_id in (351)); delete from host_version where host_id in (351); delete from host_role_command where host_id in (351); delete from serviceconfighosts where host_id in (351); delete from hoststate where host_id in (351); delete from kerberos_principal_host WHERE host_id='unwanted1.host.com'; ----> For kerberized Env delete from hosts where host_name in ('unwanted1.host.com'); delete from alert_current where history_id in ( select alert_id from alert_history where host_name in ('unwanted1.host.com'));
3. Now restart ambari-server.
# ambari-server start
.
Created 12-05-2017 05:04 PM
I strongly suggest not to delete/edit entries directly in database. However if you still want to do it at your own risk
delete from host_role_command where host_id=351; Delete from hosts where host_id=351;
Created 12-05-2017 06:13 PM
You have to delete all the rows which have FK constraint in different tables. Then you will be able to delete the host entry
Created 12-05-2017 06:24 PM
I'm sorry. I do not have a setup where I can try this currently. But you can see the error message and delete the rows of a table on which it complains the FK constraint
for ex: ERROR: update or delete on table "host_role_command" violates foreign key constraint "fk_execution_command_task_id" on table "execution_command" DETAIL: Key (task_id)=(5156) is still referenced from table "execution_command".
For this error you can run
delete from execution_command where task_id=5156;
Created 12-05-2017 05:07 PM
we still get the same errors about
ambari=> delete from host_role_command where host_id=351; ERROR: update or delete on table "host_role_command" violates foreign key constraint "fk_execution_command_task_id" on table "execution_command" DETAIL: Key (task_id)=(5156) is still referenced from table "execution_command". ambari=> Delete from hosts where host_id=351; ERROR: update or delete on table "hosts" violates foreign key constraint "fk_host_role_command_host_id" on table "host_role_command" DETAIL: Key (host_id)=(351) is still referenced from table "host_role_command".
Created 12-05-2017 06:18 PM
can you share with me please how to rows which have FK constraint in different tables
Created 12-05-2017 08:21 PM
You can try the following approach to completely remove the unwanted host from your ambari Database.
0. Stop ambari-server.
# ambari-server stop
1. Please take a fresh ambari DB dump for safety and backup.
2. Now run the following SQL queries inside your ambari DB to delete the unwanted host. Please replace the "unwanted1.host.com" with your unwanted hostname and similarly the "351" with the "host_id" that you want to remove from your Database.
delete from execution_command where task_id in (select task_id from host_role_command where host_id in (351)); delete from host_version where host_id in (351); delete from host_role_command where host_id in (351); delete from serviceconfighosts where host_id in (351); delete from hoststate where host_id in (351); delete from kerberos_principal_host WHERE host_id='unwanted1.host.com'; ----> For kerberized Env delete from hosts where host_name in ('unwanted1.host.com'); delete from alert_current where history_id in ( select alert_id from alert_history where host_name in ('unwanted1.host.com'));
3. Now restart ambari-server.
# ambari-server start
.