postgresql: update template files and use jinja2 logic