Common Command Set 1 postgresql

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/quhaizhou3/article/details/102764883

Article Directory

  1, check the database

  2, view the table

  3, see the index

  4, fuzzy queries with a wildcard

  5, show sql execution time

  1, check the database

       A method, execute commands on the operating system

 

$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)

Method two, after logging pg database, check the database

   

$ 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)

The default will be named postgres data, which is a database created db_quhaizhou


There are two template database template0 and template1 . When the user in the construction of the database, the default database template1 is cloned from a template, it is usually possible to customize the content template1 database,
such as template0 to add some tables and functions subsequently created database will inherit the contents of template1 you will also have tables and functions. And template0 is one of the most simplified template library, when you create a database,
if you explicitly specify inheritance from the database, will create one of the most simplified database.

  2, view the table

 

db_quhaizhou-# \d student

包括表结构字段信息及索引信息

  3, see the index

 

db_quhaizhou=#\d student_pkey

 4, fuzzy queries with a wildcard

    

用通配符查看所有和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, show sql execution time

db_quhaizhou-# \timing on 
Timing is on.


db_quhaizhou=# select * from student;
 id |                name                | number 
----+------------------------------------+--------
  1 | 张三                               | 1023 
(1 row)

Time: 0.610 ms

 

Guess you like

Origin blog.csdn.net/quhaizhou3/article/details/102764883