Jamf Pro – Database maintenance

The JSS keeps every recon for every computer. It only needs the last one. In large estates this can be GB’s of data and can slowdown or stop upgrades.

Heres how to clean the tables

[cc]###########
# flush reports, keep newest reports for each computer only
# count before
select count(*) from reports;
#make a new table with all the same columns
create table reports_new like reports;
#copy only the newest location_history for each computer
insert into reports_new select * from reports where report_id in (SELECT MAX(report_id) FROM reports GROUP BY computer_id);
#table switcheroo
rename table reports TO reports_old, reports_new TO reports;
# count after
select count(*) from reports;

#if all looks good
drop table reports_old;

###########
# flush applications, keep only newest report_id found in flushed reports
# count before
select count(*) from applications;
#make a new table with all the same columns
create table applications_new like applications;
#make new table from the remaining newest report_id
insert into applications_new select * from applications where report_id in (select report_id from reports);
#table switcheroo
rename table applications TO applications_old, applications_new TO applications;
#count after
select count(*) from applications;

#if all looks good
drop table applications_old;[/cc]

Clear Pending and Failed Commands

View and clear pending commands:

Before clearing or viewing, select the database:

[cc]use jamfsoftware;[/cc]

To view Pending:

[cc]select count(*) from mobile_device_management_commands where apns_result_status !=’Acknowledged’;[/cc]

To clear Pending codes:

[cc]delete from mobile_device_management_commands where apns_result_status !=’Acknowledged’;[/cc]

View and clear failed commands:

To view Failed commands:

[cc]select count(*) from mobile_device_management_commands where apns_result_status !=’Error’;[/cc]

To clear Failed codes:

[cc]delete from mobile_device_management_commands where apns_result_status !=’Error’;[/cc]