一般的なコマンドセット1つのpostgresql

免責事項:この記事はブロガーオリジナル記事です、続くBY-SAのCC 4.0を著作権契約、複製、元のソースのリンクと、この文を添付してください。
このリンク: https://blog.csdn.net/quhaizhou3/article/details/102764883

記事のディレクトリ

  1、データベースをチェック

  図2は、テーブルを表示します

  3、インデックスを参照してください

  ワイルドカードと4、ファジークエリ

  5、SQLの実行時間を表示します

  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)

方法2、PGのデータベースをログインした後、データベースをチェック

   

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

デフォルトでは、データベース作成db_quhaizhouあるpostgresのデータを、という名前になります。


2つのテンプレートデータベースがありtemplate1ではtemplate1のは、データベースの構築では、ユーザーは、デフォルトのtemplate1データベースはテンプレートからクローン化されたとき、コンテンツtemplate1データベースをカスタマイズすることが通常可能である
ように、その後に作成いくつかのテーブルや関数を追加するためでtemplate0としてデータベースはまた、テーブルや機能を持っていますtemplate1をの内容を継承します。そして、template1ではでは、データベースを作成するときに、最も単純化されたテンプレートライブラリの一つである
あなたが明示的にデータベースからの継承を指定した場合、最も単純化されたデータベースの1を作成します。

  図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

 

おすすめ

転載: blog.csdn.net/quhaizhou3/article/details/102764883