How to get all create for index and Constraints in PostgreSQL using just SQL I want a sql to get a list of CREATE of all Index and Constraints in a table 'tablename' just using SQL.
To show all the indexes of a table, use pg_indexes  PostgreSQL List Indexes

SELECT
    indexname,
    indexdef
FROM
    pg_indexes
WHERE
    tablename = 'table_name'; 


Replace &lt;table name&gt; with the name of your table.

Constraints can be retrieved via pg_catalog.pg_constraint. pg_constraint

SELECT con.*
       FROM pg_catalog.pg_constraint con
            INNER JOIN pg_catalog.pg_class rel
                       ON rel.oid = con.conrelid
            INNER JOIN pg_catalog.pg_namespace nsp
                       ON nsp.oid = connamespace
       WHERE nsp.nspname = '&lt;schema name&gt;'
             AND rel.relname = '&lt;table name&gt;';


Replace &lt;schema name&gt; with the name of your schema and &lt;table name&gt; with the name of your table.