This script fixes the most common issues with inconsistent storeconfigs database (including duplicate resources record, duplicate param_values records, dangling records...).
Usage:
stop all puppetmasters
backup your database!
% cat ext/dbfix.sql | mysql puppet
relaunch all puppetmasters