2

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.
    – kqw
    Aug 8 '14 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 '14 at 15:45
  • <1k vs >15k views - by now this question has vastly surpassed the other question in popularity.
    – kqw
    Jan 28 '18 at 10:20
5

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.