文章目录
1、查看数据库
2、查看表
3、查看索引
1、查看数据库
方法一、在操作系统上执行命令
$psql -l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
--------------+-----------+----------+-------------+-------------+-------------------------
db_quhaizhou | quhaizhou | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/quhaizhou +
| | | | | quhaizhou=CTc/quhaizhou
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
$ psql
postgres=# \c db_quhaizhou
You are Now connected to database "db_quhaizhou" as user "postgres".
db_quhaizhou=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
--------------+-----------+----------+-------------+-------------+-------------------------
db_quhaizhou | quhaizhou | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/quhaizhou +
| | | | | quhaizhou=CTc/quhaizhou
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
默认会有一个叫postgres数据,其中db_quhaizhou是创建的数据库
还有两个模板数据库 template0和 template1.当用户在建数据库时,默认是从模板数据库 template1克隆出来的,所以通常可以定制 template1数据库中的内容,
如往 template0中添加一些表和函数,后续创建的数据库就会继承 template1中的内容,也会拥有这些表和函数。而 template0是一个最简化的模板库,创建数据库时,
如果明确指定从此数据库中继承,将创建出一个最简化的数据库。
2、查看表
db_quhaizhou-# \d student
包括表结构字段信息及索引信息
3、查看索引
db_quhaizhou=#\d student_pkey
4、用通配符模糊查询
用通配符查看所有和student有关的表和索引
db_quhaizhou-# \d student*
Table "public.student"
Column | Type | Collation | Nullable | Default
--------+---------------+-----------+----------+---------
id | integer | | not null |
name | character(32) | | |
number | character(5) | | |
Indexes:
"student_pkey" PRIMARY KEY, btree (id)
Index "public.student_pkey"
Column | Type | DeFinition
--------+---------+------------
id | integer | id
primary key, btree, for table "public.student"
5、显示sql执行时间
db_quhaizhou-# \timing on
Timing is on.
db_quhaizhou=# select * from student;
id | name | number
----+------------------------------------+--------
1 | 张三 | 1023
(1 row)
Time: 0.610 ms
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。