一.用户
创建用户使用create user语句,一般使用create user with password 'xxx' XXX 其中最后的XXX是给予的角色权限
postgres=# \h create user;Command: CREATE USERDescription define a new database roleSyntaxCREATE USER name [ WITH ] option ...]where option can be SUPERUSER | NOSUPERUSER CREATEDB NOCREATEDB CREATEROLE NOCREATEROLE CREATEUSER NOCREATEUSER INHERIT NOINHERIT LOGIN NOLOGIN REPLICATION NOREPLICATION BYPASSRLS NOBYPASSRLS CONNECTION LIMIT connlimit ENCRYPTED UNENCRYPTED PASSWORD 'password' VALID UNTIL 'timestamp' IN ROLE role_name [,...] IN GROUP role_name ROLE role_name ADMIN role_name USER role_name SYSID uid
create user test with password 'test' superuser;
使用\du来查看当前pg中的用户
Role name Attributes Member of -----------+------------------------------------------------------------+----------- brent {} dsg Create DB postgres Superuser,76)"> role DB Replication Bypass RLS suq test Superuser{}
用户的权限分为系统权限和对象权限
对象权限使用grant语句来赋予:
grant selectupdateinsert on pg_catalog.pg_roles to brent;GRANT
alter role brent replicationALTER ROLE
1.创建数据库
\h create database Command CREATE DATABASEDescription create a databaseSyntaxCREATE DATABASE name OWNER [=] user_name TEMPLATE template ENCODING encoding LC_COLLATE lc_collate LC_CTYPE lc_ctype TABLESPACE tablespace_name ALLOW_CONNECTIONS allowconn CONNECTION LIMIT connlimit IS_TEMPLATE istemplate create database brent owner=suq CREATE DATABASE \l List of databases Name Owner Encoding Collate Ctype Access privileges -----------+----------+----------+---------+-------+----------------------- UTF8 C template0 c/postgres + postgres=CTcpostgres template1 postgres