一、创建账号
$ psql -U postgres
psql (9.4.4)
Type "help" for help.
postgres=# \! uuidgen
c1b9ef9e-f09e-4f26-9f34-c048aad3a9b2
postgres=# create role user1 with login password 'c1b9ef9e-f09e-4f26-9f34-c048aad3a9b2';
CREATE ROLE
postgres=# \c rdht01
You are now connected to database "rdht01" as user "postgres".
rdht01=# grant select,update,delete,insert on all tables in schema public to user1;
GRANT
rdht01=# alter default privileges in schema public grant select,update,delete,insert on tables to user1;
ALTER DEFAULT PRIVILEGES
rdht01=# alter default privileges in schema public grant usage on sequences to user1;
ALTER DEFAULT PRIVILEGES
二、删除账号
postgres=# drop owned by user1;
DROP OWNED
postgres=# drop role user1 ;
DROP ROLE
伞
验证
dcs=# \q
[postgres@zhaopin-210-11 tingting.zhang]$ psql -U web_ihr_admin_user -d rdcs -W -h 172.30.230.10
could not change directory to "/home/tingting.zhang": Permission denied
Password for user web_ihr_admin_user:
psql (9.4.5)
Type "help" for help.
rdcs=> \dt
List of relations
Schema | Name | Type | Owner
--------+--------------------+-------+----------
public | cs_x_rd | table | postgres
public | csgroup | table | postgres
public | cslist | table | postgres
public | jobpublishmodule | table | postgres
public | jobpublishschedule | table | postgres
public | operationlog | table | postgres
public | org_x_city | table | postgres
public | organ | table | postgres
public | staff | table | postgres
(9 rows)
rdcs=> select * from staff limit 1;
staffid | passportuserid | companyid | orgid | orghostid | staffname | email | telephone | mobile | fax | jobposition | status | cr
eatedate | modifieddate | lastlogindate | email2 | createuserid | modifiedusertid | ctimestamp | accountnumber | staffcode | sourcet
ype | sourceid | passportuserhostid | sourcecompanytype | sourcecompanyid | firstrechargedate
---------+----------------+-----------+-------+-----------+-----------+-------+-----------+--------+-----+-------------+--------+---
---------+--------------+---------------+--------+--------------+-----------------+------------+---------------+-----------+--------
----+----------+--------------------+-------------------+-----------------+-------------------
(0 rows)
$ psql -U postgres
psql (9.4.4)
Type "help" for help.
postgres=# \! uuidgen
c1b9ef9e-f09e-4f26-9f34-c048aad3a9b2
postgres=# create role user1 with login password 'c1b9ef9e-f09e-4f26-9f34-c048aad3a9b2';
CREATE ROLE
postgres=# \c rdht01
You are now connected to database "rdht01" as user "postgres".
rdht01=# grant select,update,delete,insert on all tables in schema public to user1;
GRANT
rdht01=# alter default privileges in schema public grant select,update,delete,insert on tables to user1;
ALTER DEFAULT PRIVILEGES
rdht01=# alter default privileges in schema public grant usage on sequences to user1;
ALTER DEFAULT PRIVILEGES
二、删除账号
postgres=# drop owned by user1;
DROP OWNED
postgres=# drop role user1 ;
DROP ROLE
伞
验证
dcs=# \q
[postgres@zhaopin-210-11 tingting.zhang]$ psql -U web_ihr_admin_user -d rdcs -W -h 172.30.230.10
could not change directory to "/home/tingting.zhang": Permission denied
Password for user web_ihr_admin_user:
psql (9.4.5)
Type "help" for help.
rdcs=> \dt
List of relations
Schema | Name | Type | Owner
--------+--------------------+-------+----------
public | cs_x_rd | table | postgres
public | csgroup | table | postgres
public | cslist | table | postgres
public | jobpublishmodule | table | postgres
public | jobpublishschedule | table | postgres
public | operationlog | table | postgres
public | org_x_city | table | postgres
public | organ | table | postgres
public | staff | table | postgres
(9 rows)
rdcs=> select * from staff limit 1;
staffid | passportuserid | companyid | orgid | orghostid | staffname | email | telephone | mobile | fax | jobposition | status | cr
eatedate | modifieddate | lastlogindate | email2 | createuserid | modifiedusertid | ctimestamp | accountnumber | staffcode | sourcet
ype | sourceid | passportuserhostid | sourcecompanytype | sourcecompanyid | firstrechargedate
---------+----------------+-----------+-------+-----------+-----------+-------+-----------+--------+-----+-------------+--------+---
---------+--------------+---------------+--------+--------------+-----------------+------------+---------------+-----------+--------
----+----------+--------------------+-------------------+-----------------+-------------------
(0 rows)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29898569/viewspace-1833801/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29898569/viewspace-1833801/