Welcome, Guest! Registration


Thursday, 2019-02-21
Main » 2016 » February » 27 » Browse postgresql database from command line (psql)
9:59 AM
Browse postgresql database from command line (psql)

psql is handy command line tool for full control of the postgresql database. Here is quick cheat-sheet on how to navigate through a database structure, how to view databases and tables. Imagine you have to get a list tables for a certain database.

Before you dive into the dark world of psql navigation, you've got to know that when browsing postgresql database expect certain hierarchy of its objects. The grand path is:

  • database cluster
    • database
      • schema
        • tables and all other tasty stuff

Here is how you browse postgresql with psql command line tool.

Once you get into postgres database cluster with psql:

Get the list of databases available with \l.

To switch to a database do \c your_database. In terms of postgresql that is "connect to a database". You can also shortcut to the database by calling psql -d your_database or just psql your_database.

Before you get to the list of tables you better off to get schema names (tables are members of schemas in postgresql), execute \dn.

Now, finally you should be able to get the list of tables using something like this: \dt your_schema. (note the trailing dot).

That is it. Quick and easy :-)

Views: 475 | Added by: ep | Tags: postgresql | Rating: 0.0/0
Total comments: 0
Only registered users can add comments.
[ Registration | Login ]