標籤:postgresql
Ubuntu下postgres的一些操作總結
1. 基本操作命令
createdb dbname:建立資料庫
dropdb dbname: 刪除資料庫
createuser [--superuser] username:建立使用者
dropuserusername: 刪除使用者
\du:列出當前所有的使用者資訊
\l: 列出當前所有的資料庫資訊
\q: 退出
\password username:修改指定的user的密碼
\dn:查看shema
\i:命令從指定的檔案中讀取命令
2. 使用shell命令列方式添加使用者和建立資料庫
PostgreSQL提供了命令列程式createuser和createdb,可以使用shell命令列方式添加使用者和建立資料庫。以建立使用者dbuser和資料庫exampledb為例。
-
首先,建立資料庫使用者dbuser,並指定其為超級使用者
sudo -u postgres createuser --superuser dbuser
-
然後,登入資料庫控制台,設定dbuser使用者的密碼,完成後退出控制台。
sudo -u postgres psql
\password dbuser
\q
-
接著,在shell命令列下,建立資料庫exampledb,並指定所有者為dbuser。
sudo -u postgres createdb -O dbuser exampledbshell命令列登入資料庫
-
同樣以上述例子中的使用者和資料庫為例,使用新使用者的名義登入資料庫
psql -U dbuser -d exampledb -h 127.0.0.1 -p 5432
上面命令的參數含義如下:-U指定使用者,-d指定資料庫,-h指定伺服器,-p指定連接埠。輸入上面命令以後,系統會提示輸入dbuser使用者的密碼。輸入正確,就可以登入控制台。
3.Ubuntu下postgresql的服務開啟關閉方式使用如下命令:
4. 串連資料庫時出現一些認證情況的解決辦法:
local all all trust # replace ident or peer with trust |
local all all md5 # replace peer with md5 |
完成上面的修改後請重新載入postgresql:
/etc/init.d/postgresql reload
本文出自 “斜視天花板” 部落格,請務必保留此出處http://lemidi.blog.51cto.com/8601832/1535349