SELECT datname FROM pg_database WHERE datistemplate = false AND datallowconn = true And datname NOT IN ('postgres')

Using the code above, I get all the databases except postgres as shown in the image below: All databases in Postgres

Is there any better/cleaner/nicer way than my code above to get the same result?

1 Answer 1


There is no real improvement possible, but I think the following is more readable:

SELECT datname
FROM pg_database
WHERE NOT datistemplate
  AND datallowconn
  AND datname <> 'postgres';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.