3.1.1不帶參數的創建用戶; xiaop@localhost~$ createuser testuser Shall the new user be allowed to create databases? (y/n) n --------是否可以創建數據庫:否 Shall the new user be allowed to create more new users? (y/n) n ---------是否可以創建新用戶:否 CREATE USER 注:不帶參數創建用戶時,Postgres會詢問此用戶的權限,上面的例子創建了一個普通用戶;
3.1.2 為指定的主機和端口上創建用戶 ; xiaop@localhost~$ createuser -h 172.28.18.51 -p 5000 -D -A -e testuser CREATE USER joe NOCREATEDB NOCREATEUSER; CREATE USER 注:這個命令為主機172.28.18.51的5000端口創建用戶testuser, 此用戶不可以創建數據庫和其他用戶。
3.1.3創建超級用戶; xiaop@localhost~$ createuser -P -d -a -e testuser Enter password for new user: testuser Enter it again: testuser CREATE USER joe PASSWORD 'testuser' CREATEDB CREATEUSER; CREATE USER 注:這個命令在本地創建一個超級用戶(-a),可以創建數據庫(-d), 同時要求設置密碼。
3.2.1 刪除本地的Postgres用戶; xiaop@localhost~$ dropuser testuser DROP USER
3.2.2 刪除遠程Postgres服務器上的用戶; xiaop@localhost~$ dropuser -p 5000 -h 172.28.18.51 -i -e testuser User "testuser" and any owned databases will be permanently deleted. Are you sure? (y/n) y DROP USER "testuser" DROP USER 注:此命令刪除主機172.28.18.51(-h)的5000端口(-p)的用戶testuser,并且需要確認(-i);
5.1 激活數據庫 您需要啟動psql,試驗剛才的例子。您可以用下面的命令為 mydb 數據庫激活它: xiaop@localhost~$ psql mydb 如果您省略了數據庫名字,那么它缺省就是您的用戶賬號名字。 Welcome to psql 8.2.4, the PostgreSQL interactive terminal. Type: /copyright for distribution terms /h for help with SQL commands /? for help with psql commands /g or terminate with semicolon to execute query /q to quit mydb=# 注:最后一行 mydb=#,這個提示符意味著您是數據庫超級用戶。