postgresql structure refactoring