some tweaks to make postgres work.  no mysql regression tested