Why does selecting all tables from postgres gives different results based on syntax used

Viewed 162

If I log into postgres and switch to the postgres database, when I check for tables with this command I get nothing back:

postgres=# \c postgres
You are now connected to database "postgres" as user "postgres".
postgres=# \dt+
Did not find any relations.

However if I do a select on the DB tables I do see that the tables are there:

postgres=# SELECT *
postgres-# FROM pg_catalog.pg_tables
postgres-# WHERE schemaname != 'pg_catalog' AND
postgres-#     schemaname != 'information_schema';
 schemaname |   tablename    | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity
------------+----------------+------------+------------+------------+----------+-------------+-------------
 pgagent    | pga_jobclass   | postgres   |            | t          | f        | t           | f
 pgagent    | pga_job        | postgres   |            | t          | f        | t           | f
 pgagent    | pga_jobagent   | postgres   |            | t          | f        | t           | f
 pgagent    | pga_jobstep    | postgres   |            | t          | f        | t           | f
 pgagent    | pga_schedule   | postgres   |            | t          | f        | t           | f
 pgagent    | pga_exception  | postgres   |            | t          | f        | t           | f
 pgagent    | pga_joblog     | postgres   |            | t          | f        | t           | f
 pgagent    | pga_jobsteplog | postgres   |            | t          | f        | t           | f
(8 rows)

Why do I get nothing when I use \dt+ but I can see the tables using a select statement?

2 Answers

I think that this will help LINK

\d [NAME] describe table, index, sequence, or view
\d{t|i|s|v|S} [PATTERN] ("+" detail) list tables/indexes/sequences/views/system tables
\da [PATTERN] list aggregate functions
\db [PATTERN] list tablespaces (add "+" for more detail)

use \dt+ *

the * to match all as the command needs a pattern

The reason is that the pgagent schema is not on your search_path. \dt will only show those tables that you can access without schema qualification.

Related