Question: how to create database if not exists in postgresql?
Answer: PostgreSQL does not support IF NOT EXISTS for CREATE DATABASE statement. It is supported only in CREATE SCHEMA . Moreover CREATE DATABASE cannot be issued in transaction therefore it cannot be in DO block with exception catching.