9:59 AMBrowse 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:
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 :-)
|Total comments: 0|