Postgres (SQL) - list databases using the psql command
by
Jeremy Canfield |
Updated: June 05 2023
| Postgres (SQL) articles
The psql --list command can be used to add a new column to a table.
If using the default posgres user account, I typically go with the following command.
sudo -u postgres psql --list
If you have created a user account, the -u or --username option and --password flag can be used.
psql --username johndoe --password --list
Better yet, you can setup passwordless authentication using the hidden .pgpass file and then connect without the --password flag.
psql --username johndoe --dbname mydb --list
Or, the --command option can be used.
psql --username johndoe --dbname mydb --command "\list"
Something like this should be returned.
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
db001 | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
db002 | john.doe | UTF8 | en_US.utf8 | en_US.utf8 |
Did you find this article helpful?
If so, consider buying me a coffee over at