接觸PostgreSQL也有好長時間了,知識不總結梳理,彷佛總不是本身的,繼續努力吧少年!以此記錄個人軟件工藝之路!
SHOW search_path;
run,如:php
search_path ---------------- "$user",public (1 row)
其中$user,表示一個和當前用戶同名的模式,若是這樣的模式不存在,則該模式會被忽略。html
select CURRENT_USER; -- or -- select * from pg_user where usename = CURRENT_USER;
\du
run,如:sql
List of roles Role name | Attributes | Member of -----------+------------------------------------------------+----------- geodb | Superuser, Create DB, Replication | {} postgres | Superuser, Create role, Create DB, Replication | {} xiwang | Superuser, Create DB, Replication | {}
\l
列出服務器上全部數據庫的名字和它們的全部者以及字符集編碼。在命令名稱後面加一個 "+" 還能夠看到對數據庫的描述。如:數據庫
List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- blogdb | xiwang | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =CTc/xiwang + | | | | | xiwang=CTc/xiwang 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
\d
如:服務器
List of relations Schema | Name | Type | Owner --------+-----------------+----------+-------- xiwang | articles | table | xiwang xiwang | articles_id_seq | sequence | xiwang xiwang | comments | table | xiwang xiwang | messages_id_seq | sequence | xiwang xiwang | users | table | xiwang xiwang | users_id_seq | sequence | xiwang
\d tablename
查看更多信息:app
\d+ tablename
SELECT EXISTS ( SELECT 1 FROM information_schema.tables WHERE table_schema = 'schema_name' AND table_name = 'table_name' );
\dt [pattern]
列出全部數據類型或只顯示那些匹配 pattern的。這條命令的 \dT+ 形式顯示更多信息
如:post
\dt xiwang.*
能夠查看名爲xiwang的模式下全部的數據類型。學習
\s [ filename ]
將命令行歷史打印出或是存放到 filename。 若是省略 filename, 歷史將輸出到標準輸出。這個選項只有在 psql 配置成使用 GNU Readline 庫後才生效。編碼
更多更詳細的資料,更查看手冊文檔。命令行