4

This question deals with getting a list. So I get this:

$ psql --list
                                    List of databases
      Name      |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
----------------+----------+----------+-------------+-------------+-----------------------
 testdb1        | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 odoo           | openerp  | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 odoo-demo      | openerp  | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 odoo8          | openerp  | UTF8     | en_US.UTF-8 | en_US.UTF-8 |

I could use psql --list|grep UTF8|awk '{ print $1 }' to get a list of just the databases. Can psql also give me a clean useful list directly?

3
  • The answer is the same, the question title is quite different though. I wouldn't have looked there if I had seen that title.
    – the
    Aug 8, 2014 at 12:46
  • Agreed, I've changed the title for something more descriptive. But anyway the -Atc switches should be mentioned in the answers of the much more popular question you linked. Aug 8, 2014 at 15:45
  • <1k vs >15k views - by now this question has vastly surpassed the other question in popularity.
    – the
    Jan 28, 2018 at 10:20

1 Answer 1

6

psql -q -A -t -c "SELECT datname FROM pg_database" does the trick.

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