PostgreSQL運維命令整理

# 控制檯命令

su - postgres

psql

\q 退出控制檯

\password 設置密碼

\h 查看SQL命令的解釋,比如\h select。

\? 查看psql命令列表。

\l 列出所有數據庫。

\c [database_name]:連接其他數據庫。

\d 列出當前數據庫的所有表格。

\d [table_name]:列出某一張表格的結構。

\du 列出所有用戶。

\e 打開文本編輯器。

\conninfo 列出當前數據庫和連接的信息。


# 登陸數據庫

psql -U postgres -d dbname -h 127.0.0.1 -p 5432

-U 指定用戶

-d 指定數據庫

-h 指定服務器

-p 指定端口


example:

psql -U postgres -d freeswitch -h 127.0.0.1 -p 5432


# 數據庫備份

pg_dump dbname > outfile

-U 指定用戶

-h 指定服務器

-p 指定端口


example:

pg_dump -U postgres -h 127.0.0.1 -p 5432 freeswitch > outfile


# 查詢數據庫位置

select oid,datname from pg_database;

------------------------

  oid  |  datname

-------+------------

     1 | template1

 12865 | template0

 12870 | postgres

 16384 | freeswitch

(4 行記錄)

--------------------


#確認存儲位置

ls /var/lib/pgsql/9.2/data/base/16384/

參閱文檔

====================

http://www.ruanyifeng.com/blog/2013/12/getting_started_with_postgresql.html


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