Lamer Moments: Listing databases in PostgreSQL

Wed 14 December 2005

Filed under Howto

Tags Lamer Moments PostgreSQL

In MySQL you can use 'show databases' along with many other convenient 'show' commands. PostgreSQL is a different beast entirely. using real databases can be challenging if you grew up on MySQL.


Connect to the database with psql:


psql -U postgres template1
opsdb ~ # psql -U postgres template1
Welcome to psql 8.0.3, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

template1=# select datname from pg_database;
   datname
--------------
 template1
 template0
 mydb
 typo
(4 rows)

template1=# quit


Update: [2005-12-16]

After MANY people have pointed out that "dude" \L works in the Interactive Interface. I would like to tell you: This is useless when you are actually using PostgreSQL from within programs / scripts.


Comments


Up To Something © Joshua M Schmidlkofer Powered by Pelican and Twitter Bootstrap. Icons by Font Awesome and Font Awesome More