Best method to clean up database table orphaned data in Drupal 7? Currently my files and images table has over 100k entries, but I know for a fact that alot of them are orphaned and the files do not exist anymore. What is a best method to cross-reference this data to see if the file exist so i can delete them?
This is a script I use on my own Drupal sites, you can see if it works for yours, it deletes files and records in the file_managed table that have no references in the Drupal file_usage table, or things that are no longer being used by the Drupal installation.

$result = db_query('SELECT fm.fid, fm.uri FROM {file_managed} fm LEFT JOIN {file_usage} fu ON fm.fid = fu.fid WHERE fu.fid IS NULL ORDER BY fm.fid');
$num_files_deleted = 0;
$num_records_deleted = 0;
$time_before_start = time();

foreach ($result as $record) {
    $file = file_load($record -&gt; fid);

    if ($file != FALSE) {
        if (file_delete($file)) {
            print(drupal_realpath($record -&gt; uri) . " has been successfully deleted.\n");
            $num_files_deleted++;
        }
    }

    db_delete('file_managed') -&gt; condition('fid', $record -&gt; fid) -&gt; execute();
    $num_records_deleted++;
}

$time_after_finish = time();
$total_time = ($time_after_finish - $time_before_start);
$total_time_h = $total_time / 3600 % 24;
$total_time_m = $total_time / 60 % 60;
$total_time_s = $total_time % 60;

if ($num_records_deleted || $num_files_deleted &gt;= 1) {
    print("\n\n");
    print($num_files_deleted . " files purged and " . $num_records_deleted . " in " . $total_time_h . ":" . $total_time_m . ":" . $total_time_s . ".\n");
}
else {
    print("Nothing to purge.\n");
}


You can try running that on a dev to see if that's also something you would want.