Optimizing database utilization and costs