OpenNetAdmin

Track. Automate. Configure.

Home About Features Community Develop
Download this project as a tar.gz file

stale device records?

yshollander

10-05-2011 13:27:18

Hi,

I'm trying to clean up an unused entry in the locations table (id = 5). The UI shows no hosts at that location. However, ONA still complains that there are still entries in the devices table with location_id = 5.

There are no corresponding hosts table records for those devices.

SELECT * FROM devices d, hosts h where d.id = h.device_id and d.location_id = 5

returns no records.

Is it safe to manually remove the records from the devices table so that I can delete the location record as desired?

Thanks

Isaac

Matt

11-05-2011 15:09:47

Try doing the following query:

select * from devices where location_id = 5 (though its pretty much what you already did)

In looking at my dev code it looks ok and I'm unable to recreate an issue of being able to delete this data. It simply says look for this location id in any of the rows of the devices table. It is possible that the device table has records in it that dont match up to any hosts and are orphaned. If this is the case, yes, it is safe to delete those device records. You can further check to see before deleting that there are no host records that use that device id

select * from hosts where device_id = ??

I think your query is trying to join together this information.. but if the record does not exist, then it would not show up... I suggest separating the query out like my examples to see if you can find the data that might be orphaned.

Ultimately yes, delete the devices, then you can delete the location. OR you could even update the location_id and set it to 0 or some other value for any that are currently 5

update devices set location_id = 0 where location_id = 5