3

I installed an application that uses a postgreSQL server but I don't know the name of the database and the tables it uses. Is there any command in order to see the name of the database and the tables of this application?

3 Answers 3

4

If you are able to view the database using the psql terminal command:

> psql -h hostname -U username dbname

...then, in the psql shell, \d ("describe") will show you a list of all the relations in the database. You can use \d on specific relations as well, e.g.

db_name=# \d table_name
        Table "public.table_name"
    Column     | Type    | Modifiers
---------------+---------+-----------
id             | integer | not null
... etc ...
Sign up to request clarification or add additional context in comments.

2 Comments

what could I do in case I dont have the "db_name" and the "table_name" ?
Read A.H.'s answer - \l lists databases. \d lists tables.
1

Using the psql on Linux you can use the \l command to list databases, \c dbname to connect to that db and the \d command to list tables in the db.

Comments

1

Short answer: connect to the default database with psql, and list all databases with '\l' Then, connect to you database of interest, and list tables with '\dt'

Slightly larger answer: A Postgresql server installation usually has a "data directory" (can have more than one, if there are two server instances running, but that's quite unusual), which defines what postgresl calls "a cluster". Inside it, you can have several databases ; you usually have at least the defaults 'template0' and 'template1', plus your own database(s).

1 Comment

Great thats exactly what I was looking for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.