Fix postgresql locale and encoding.

Sorry for the double pull request. The previous merge didn't set up database encoding properly. This one should hit all the cases, and all tests pass.