To list all the tables in database in PostgreSQL

  • psql terminal

\dt  command will show all the tables in current database

-------- CONNECT TO POSTGRES DATABASE --------------

postgres=# \c postgres
You are now connected to database "postgres" as user "postgres".
postgres=# \dt
List of relations
Schema | Name | Type | Owner
--------+---------+-------+----------
public | mentor | table | postgres
public | student | table | postgres
(2 rows)
  • Query to check tables in current database

we have to give schema name (by default public schema used)

postgres=# select * from pg_tables where schemaname = 'public' ;
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity
------------+-----------+------------+------------+------------+----------+-------------+-------------
public | student | postgres | | t | f | f | f
public | mentor | postgres | | t | f | f | f
(2 rows)