Bootstrap FreeKB - Postgres (SQL) - list databases using the psql command
Postgres (SQL) - list databases using the psql command

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter d57aa4 in the box below so that we can be sure you are a human.