Ported step2.tmpl to support PostgreSQL