Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres - list databases from Mac terminal

Tags:

postgresql

I'm experienced with MySQL, but I've just started to work with Postgres - from the terminal on my Mac, how can I see the list of existing Postgres databases using the psql command?

I checked the documentation and I've seen this issue brought up here - https://dba.stackexchange.com/questions/1285/how-do-i-list-all-databases-and-tables-using-psql, where the accepted solution is to simply type psql \l, and that makes sense to me... however, when I try this, I get the error

psql: FATAL: database "l" does not exist

but I am logged in to Postgres - if I type psql DATABASE_NAME, no problem, I get into the database... this was an issue for me recently because I couldn't remember the name of the database that I wanted to work on. I went into another table (the name of which I did remember), then used the \l command to see my databases and connected to the DB I needed, but I'd much rather just be able to see a list without having to first connect to a database. How can I do that?

like image 777
skwidbreth Avatar asked May 22 '16 17:05

skwidbreth


1 Answers

Thanks to @Michał Sznurawa for pointing me in the right direction - from the Mac terminal, using psql -l, rather than psql \l does the trick.

like image 149
skwidbreth Avatar answered Nov 20 '22 08:11

skwidbreth