PostgreSQL trivia

, Andreas Katzian

Sometimes it is necessary to use the psql command line tool to quickly explore odds in database. Often you also need to use some commands to view structure of your database or tables. In PostgreSQL (and also in other database systems) you can do that by querying system tables like pg_tables, pg_class, pg_attribute and so on.

Following you’ll find some quick commands for doing that a little bit easier.

Command Description
d This command is in general the shortcut for “describe”. In other database systems the “desc” keyword is used instead.
dt Displays all your user defined tables.
dT Displays all your user defined data types.
df Displays all your user defined functions.
di Displays all your user defined indexes.
dv Displays all your user defined views.
dn Displays all namespaces.
du Displays all users.
l Displays all databases.
d [tablename] Describes the table [tablename] with all fields and indexes.

Also most of this commands can be used in combination with a search pattern. So dt proj_* will list all tables with the prefix proj_ respectively.

Andreas Katzian
process

comments powered by Disqus

 

Recent Posts

 

Kinect on MacOS X with Homebrew

How to get libfreenect running with homebrew on MacOS X 10.8

Updating sitemap file on Heroku

Updating the sitemap.xml on Heroku for your rails application by using the sitemap_generator gem and AWS S3/CloudFront.

Various ActiveResource Tips

Enabling Logging, Set different model name, Set HTTP headers, Set xml/json format

Show NSWindow below your NSStatusItem

Show your own window below your status bar application.