Listar las tablas de schemas en postgres

Categorías:

Para listar tablas en postgres de hace uso del comando dt, veamos como.

 

postgres=# \dt
            List of relations
 Schema |     Name     | Type  |  Owner   
--------+--------------+-------+----------
 public | departments  | table | postgres
 public | dept_emp     | table | postgres
 public | dept_manager | table | postgres
 public | employees    | table | postgres
 public | mes          | table | postgres
 public | salaries     | table | postgres
 public | titles       | table | postgres
(7 rows)

postgres=#

Si queremos tener un mayor detalle agregamos el caracter + a la sentencia.

postgres=# \dt+
                          List of relations
 Schema |     Name     | Type  |  Owner   |    Size    | Description 
--------+--------------+-------+----------+------------+-------------
 public | departments  | table | postgres | 8192 bytes | 
 public | dept_emp     | table | postgres | 17 MB      | 
 public | dept_manager | table | postgres | 8192 bytes | 
 public | employees    | table | postgres | 18 MB      | 
 public | mes          | table | postgres | 16 kB      | 
 public | salaries     | table | postgres | 120 MB     | 
 public | titles       | table | postgres | 24 MB      | 
(7 rows)

postgres=#

Pero, si lo que queremos es ver todas las tablas de un esquema en particular, anteponemos el nombre del esquema y un punto seguido de asterisco.  En el siguiente ejemplo estoy en una base de datos llamada vicidial

vicidial=# \dt vicidial.*
                 List of relations
  Schema  |        Name         | Type  |  Owner   
----------+---------------------+-------+----------
 vicidial | call_log            | table | postgres
 vicidial | vicidial_agent_log  | table | postgres
 vicidial | vicidial_closer_log | table | postgres
 vicidial | vicidial_list       | table | postgres
 vicidial | vicidial_lists      | table | postgres
 vicidial | vicidial_log        | table | postgres
(6 rows)

vicidial=#

Para ver las tablas de todos los esquemas, usamos la siguiente sentencia sql.

vicidial=# \dt *.*
                        List of relations
       Schema       |          Name           | Type  |  Owner   
--------------------+-------------------------+-------+----------
 information_schema | sql_features            | table | postgres
 information_schema | sql_implementation_info | table | postgres
 information_schema | sql_parts               | table | postgres
 information_schema | sql_sizing              | table | postgres
 pg_catalog         | pg_aggregate            | table | postgres
 pg_catalog         | pg_am                   | table | postgres
 pg_catalog         | pg_amop                 | table | postgres
 pg_catalog         | pg_amproc               | table | postgres
 pg_catalog         | pg_attrdef              | table | postgres
 pg_catalog         | pg_attribute            | table | postgres
 pg_catalog         | pg_auth_members         | table | postgres
 pg_catalog         | pg_authid               | table | postgres
 pg_catalog         | pg_cast                 | table | postgres
 pg_catalog         | pg_class                | table | postgres
 pg_catalog         | pg_collation            | table | postgres
 pg_catalog         | pg_constraint           | table | postgres
 pg_catalog         | pg_conversion           | table | postgres
 pg_catalog         | pg_database             | table | postgres
 pg_catalog         | pg_db_role_setting      | table | postgres
 pg_catalog         | pg_default_acl          | table | postgres
 pg_catalog         | pg_depend               | table | postgres
 pg_catalog         | pg_description          | table | postgres
 pg_catalog         | pg_enum                 | table | postgres
 pg_catalog         | pg_event_trigger        | table | postgres
 pg_catalog         | pg_extension            | table | postgres
 pg_catalog         | pg_foreign_data_wrapper | table | postgres
 pg_catalog         | pg_foreign_server       | table | postgres
 pg_catalog         | pg_foreign_table        | table | postgres
 pg_catalog         | pg_index                | table | postgres
 pg_catalog         | pg_inherits             | table | postgres
 pg_catalog         | pg_init_privs           | table | postgres
 pg_catalog         | pg_language             | table | postgres
 pg_catalog         | pg_largeobject          | table | postgres
 pg_catalog         | pg_largeobject_metadata | table | postgres
 pg_catalog         | pg_namespace            | table | postgres
 pg_catalog         | pg_opclass              | table | postgres
 pg_catalog         | pg_operator             | table | postgres
 pg_catalog         | pg_opfamily             | table | postgres
 pg_catalog         | pg_partitioned_table    | table | postgres
 pg_catalog         | pg_policy               | table | postgres
 pg_catalog         | pg_proc                 | table | postgres
 pg_catalog         | pg_publication          | table | postgres
 pg_catalog         | pg_publication_rel      | table | postgres
 pg_catalog         | pg_range                | table | postgres
 pg_catalog         | pg_replication_origin   | table | postgres
 pg_catalog         | pg_rewrite              | table | postgres
 pg_catalog         | pg_seclabel             | table | postgres
 pg_catalog         | pg_sequence             | table | postgres
 pg_catalog         | pg_shdepend             | table | postgres
 pg_catalog         | pg_shdescription        | table | postgres
 pg_catalog         | pg_shseclabel           | table | postgres
 pg_catalog         | pg_statistic            | table | postgres
 pg_catalog         | pg_statistic_ext        | table | postgres
 pg_catalog         | pg_statistic_ext_data   | table | postgres
 pg_catalog         | pg_subscription         | table | postgres
 pg_catalog         | pg_subscription_rel     | table | postgres
 pg_catalog         | pg_tablespace           | table | postgres
 pg_catalog         | pg_transform            | table | postgres
 pg_catalog         | pg_trigger              | table | postgres
 pg_catalog         | pg_ts_config            | table | postgres
 pg_catalog         | pg_ts_config_map        | table | postgres
 pg_catalog         | pg_ts_dict              | table | postgres
 pg_catalog         | pg_ts_parser            | table | postgres
 pg_catalog         | pg_ts_template          | table | postgres
 pg_catalog         | pg_type                 | table | postgres
 pg_catalog         | pg_user_mapping         | table | postgres
 vicidial           | call_log                | table | postgres
 vicidial           | vicidial_agent_log      | table | postgres
 vicidial           | vicidial_closer_log     | table | postgres
 vicidial           | vicidial_list           | table | postgres
 vicidial           | vicidial_lists          | table | postgres
 vicidial           | vicidial_log            | table | postgres
(72 rows)

vicidial=#

Y listo el pollo.