Make cdr_pgsql gracefully handle restarts (bug #3628)