久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

PostgreSQL常用命令有哪些

141次閱讀
沒有評論

共計 2702 個字符,預計需要花費 7 分鐘才能閱讀完成。

這篇文章主要介紹 PostgreSQL 常用命令有哪些,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

查看版本信息

mydb=# SELECT version();
 version 
-------------------------------------------------------------------------------------------------------
 PostgreSQL 9.3.6 on i686-pc-linux-gnu, compiled by gcc (GCC) 4.4.6 20110731 (Red Hat 4.4.6-3), 32-bit
(1 row)

創建數據庫

mydb=# CREATE DATABASE test;
CREATE DATABASE

顯示所有數據庫

mydb-# \l
 List of databases
 Name | Owner | Encoding | Collate | Ctype | Access privileges 
-----------+---------+----------+-------------+-------------+---------------------
 mydb | postgre | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 postgres | postgre | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 template0 | postgre | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgre +
 | | | | | postgre=CTc/postgre
 template1 | postgre | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgre +
 | | | | | postgre=CTc/postgre
 test | postgre | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | 
(5 rows)

切換當前數據庫

mydb-# \c test
Password for user postgre: 
You are now connected to database  test  as user  postgre .

刪除數據庫

#  不能刪除當前連接的數據庫
test=# DROP DATABASE test; 
ERROR: cannot drop the currently open database
test=# DROP DATABASE mydb;
DROP DATABASE

列舉當前數據庫表

test=# create table t as select * from pg_tablespace;
SELECT 2
test=# \dt
 List of relations
 Schema | Name | Type | Owner 
--------+------+-------+---------
 public | t | table | postgre
(1 row)

查看表結構

test=# \d t
 Table  public.t 
 Column | Type | Modifiers 
------------+-----------+-----------
 spcname | name | 
 spcowner | oid | 
 spcacl | aclitem[] | 
 spcoptions | text[] |

重命名表

test=# alter table t rename to t_t;
ALTER TABLE
test=# \dt
 List of relations
 Schema | Name | Type | Owner 
--------+------+-------+---------
 public | t_t | table | postgre
(1 row)

查看表索引

#  創建索引
test=# create index idx_name on t (spcname);
CREATE INDEX
#  顯示索引
test=# \di ;
 List of relations
 Schema | Name | Type | Owner | Table 
--------+----------+-------+---------+-------
 public | idx_name | index | postgre | t
 public | idx_t | index | postgre | t_t
(2 rows)

刪除表

test=# drop table t_t;
DROP TABLE

創建用戶

test=# CREATE USER svoid;
CREATE ROLE
#  創建 sovid  指定密碼
test=# CREATE USER svoid WITH PASSWORD  123qwe 
CREATE ROLE

查看系統用戶信息

test=# SELECT usename FROM pg_user;
 usename 
---------
 postgre
 svoid
(2 rows)
test=# \du;
 List of roles
 Role name | Attributes | Member of 
-----------+------------------------------------------------+-----------
 postgre | Superuser, Create role, Create DB, Replication | {}
 svoid | | {}

刪除用戶

test=# DROP USER svoid;
DROP ROLE

查看 schema

test=# \dn;
 List of schemas
 Name | Owner 
--------+---------
 public | postgre
(1 row)

創建 schema

test=# CREATE SCHEMA myschema;
CREATE SCHEMA

刪除 schema

test=# DROP SCHEMA myschema;
DROP SCHEMA

以上是“PostgreSQL 常用命令有哪些”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注丸趣 TV 行業資訊頻道!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-27發表,共計2702字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 湛江市| 麻城市| 定襄县| 朝阳县| 广昌县| 章丘市| 黑龙江省| 东兰县| 鄂州市| 青川县| 黑龙江省| 郸城县| 靖江市| 西城区| 宿松县| 本溪市| 五常市| 南涧| 苍南县| 中西区| 汉沽区| 赣榆县| 苍南县| 萨嘎县| 林州市| 贵定县| 拜城县| 金沙县| 平湖市| 普兰县| 玉山县| 璧山县| 塘沽区| 双鸭山市| 光山县| 扎鲁特旗| 黑山县| 夏津县| 磴口县| 新晃| 信阳市|