简体   繁体   中英

postgresql psql command \d does not list indexes

I created a table in PGSQL (version 13) using the following command:

db1=# create table temp2(
foo int PRIMARY KEY,
bar varchar(20) UNIQUE NOT NULL
);
CREATE TABLE

The \d or d+ command does not list the associated indexes for the table (contrary to what I gathered from reading various sites.)

db1=# \d temp2
 foo    | integer               |           | not null |
 bar    | character varying(20) |           | not null |

db1=# \d+ temp2
 foo    | integer               |           | not null |         | plain    |              |
 bar    | character varying(20) |           | not null |         | extended |              |

Is there a way I get list indexes associated with a table?

Thank you, Ahmed.

You have tuples_only set to on .

 create table temp2(
foo int PRIMARY KEY,
bar varchar(20) UNIQUE NOT NULL
);

test(5432)=# \d temp2
                      Table "public.temp2"
 Column |         Type          | Collation | Nullable | Default 
--------+-----------------------+-----------+----------+---------
 foo    | integer               |           | not null | 
 bar    | character varying(20) |           | not null | 
Indexes:
    "temp2_pkey" PRIMARY KEY, btree (foo)
    "temp2_bar_key" UNIQUE CONSTRAINT, btree (bar)

test(5432)=# \pset tuples_only on


test(5432)=# \d temp2
 foo    | integer               |           | not null | 
 bar    | character varying(20) |           | not null | 

test(5432)=# \pset tuples_only off
test(5432)=# \d temp2
                      Table "public.temp2"
 Column |         Type          | Collation | Nullable | Default 
--------+-----------------------+-----------+----------+---------
 foo    | integer               |           | not null | 
 bar    | character varying(20) |           | not null | 
Indexes:
    "temp2_pkey" PRIMARY KEY, btree (foo)
    "temp2_bar_key" UNIQUE CONSTRAINT, btree (bar)

Verify by doing:

\pset
border                   1
columns                  0
csv_fieldsep             ','
expanded                 off
fieldsep                 '|'
fieldsep_zero            off
footer                   on
format                   aligned
linestyle                ascii
null                     'NULL'
numericlocale            off
pager                    1
pager_min_lines          0
recordsep                '\n'
recordsep_zero           off
tableattr                
title                    
tuples_only              on
unicode_border_linestyle single
unicode_column_linestyle single
unicode_header_linestyle single


You need \di to get the index information. Check the manual :

the letters E, i, m, s, t, and v stand for foreign table, index, materialized view, sequence, table, and view, respectively.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM