Is there any better way to list all the databases in Postgres except database named postgres?
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 &lt;&gt; 'postgres';