Today I Learned

hashrocket A Hashrocket project

List Postgres Databases

Today I learned how to list postgres databases from the command line. I use createdb and dropdb all the time to create and drop databases respectively, but alas listdb is not a valid command.

Instead, you can list the databases with psql -l.

$ psql -l
             Name             |  Owner   | Encoding |   Collate   |    Ctype    | ICU Locale | Locale Provider |   Access privileges
-----------------------------+----------+----------+-------------+-------------+------------+-----------------+-----------------------
 postgres                    | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | en-US      | icu             |
 template0                   | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | en-US      | icu             | =c/postgres          +
                             |          |          |             |             |            |                 | postgres=CTc/postgres
 template1                   | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | en-US      | icu             | =c/postgres          +
                             |          |          |             |             |            |                 | postgres=CTc/postgres
...

Docs

See More #sql TILs
Looking for help? Hashrocket developers believe that data quality is as important as code quality. We enjoy all the challenges of relational databases, from finding the fastest index, to structuring data to fit the needs of an application. We're eager to share our experiences; check out PG Casts, our series of free PostgreSQL screencasts.