创建用户及密码:
postgres=# create user test with password 'test';
CREATE ROLE
##删除用户:
drop user test;
DROP ROLE
\du 查看建立好的用户
##普通用户登陆不上,需要设置pg_hba.conf
postgres=# exit
-bash-4.2$ psql -U test
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: Peer authentication failed for user "test"
/var/lib/pgsql/14/data
修改: pg_hba.conf
local all all md5
##使用test用户,进入mydb创建的数据库:
-bash-4.2$ psql -U test -d mydb;
Password for user test:
psql (14.10)
Type "help" for help.
mydb=>
mydb=> create table xx(id int,name varchar(10));
CREATE TABLE
mydb=> show tables;
ERROR: unrecognized configuration parameter "tables"
mydb=> \d xx
Table "public.xx"
Column | Type | Collation | Nullable | Default
--------+-----------------------+-----------+----------+---------
id | integer | | |
name | character varying(10) | | |
mydb=>
mydb=> select * from xx;
id | name
----+------
(0 rows)
授权用户对库、表的权限:
标签:name,用户,xx,user,test,操作,mydb From: https://www.cnblogs.com/cherishthepresent/p/17853225.html