PostgreSQL基礎知識

1. PostgreSQL日常命令

# 常用SQL
查看當前用戶: SELECT current_user;
查看所有用戶: SELECT * FROM pg_user;
查看所有數據庫: SELECT * FROM pg_database;
修改庫的所有者: ALTER DATABASE mydb OWNER TO newowner;
修改表的所有者: ALTER TABLE tablename OWNER TO newowner;
如何連接到PostgreSQL數據庫: psql -U <username> -d <database name> -h <host> -p <port>

# 常用命令
\c mydatabase myuser        以myuser用戶連接到mydatabase
\l[+]   [PATTERN]           list databases
\dt[S+] [PATTERN]           list tables
\d[S+]  NAME                describe table, view, sequence, or index
\dp     [PATTERN]           list table, view, and sequence access privileges
\df[anptw][S+] [FUNCPTRN [TYPEPTRN ...]]            list [only agg/normal/procedure/trigger/window] functions
\x [on|off|auto]            toggle expanded output (currently off)
\password [USERNAME]        securely change the password for a user

# 基礎知識
PostgreSQL的系統庫: postgres, template0和template1

2. PostgreSQL環境搭建

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章