1.创建用户user1、user2、user3,授予user1、user2、user3数据库系统的SYSADMIN权限
omm@modb:~$ gs_ctl status [2022-11-27 20:25:30.469][382][][gs_ctl]: gs_ctl status,datadir is /var/lib/opengauss/data gs_ctl: server is running (PID: 1) /usr/local/opengauss/bin/gaussdb omm@modb:~$ gsql -r gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:00 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. omm=# \db omm=# List of tablespaces Name | Owner | Location ------------+-------+---------- pg_default | omm | pg_global | omm | (2 rows) omm=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+-------+----------+---------+-------+------------------- omm | omm | UTF8 | C | C | postgres | omm | UTF8 | C | C | omm=# template0 | omm | UTF8 | C | C | =c/omm + | | | | | omm=CTc/omm template1 | omm | UTF8 | C | C | =c/omm + | | | | | omm=CTc/omm (4 rows) --进入数据库omm,创建表空间、测试数据库 omm=# CREATE TABLESPACE music_tbs2 RELATIVE LOCATION 'tablespace/music_tbs2'; CREATE TABLESPACE omm=# CREATE DATABASE musicdb2 WITH TABLESPACE = music_tbs2; CREATE DATABASE --执行下面的SQL语句,创建用户user1、user2、user3: omm=# CREATE USER user1 IDENTIFIED BY 'kunpeng@2022'; NOTICE: The encrypted password contains MD5 ciphertext, which is not secure. CREATE ROLE omm=# CREATE USER user2 IDENTIFIED BY 'kunpeng@2022'; NOTICE: The encrypted password contains MD5 ciphertext, which is not secure. CREATE ROLE omm=# CREATE USER user3 IDENTIFIED BY 'kunpeng@2022'; NOTICE: The encrypted password contains MD5 ciphertext, which is not secure. CREATE ROLE --授予user1、user2、user3数据库系统的SYSADMIN权限: omm=# ALTER USER user1 SYSADMIN; ALTER ROLE omm=# ALTER USER user2 SYSADMIN; omm=# ALTER ROLE ALTER USER user3 SYSADMIN; ALTER ROLE --执行下面的命令,查看有哪些用户: omm=# \du List of roles Role name | Attributes | M ember of -----------+------------------------------------------------------------------------------------------------------------------+-- --------- gaussdb | Sysadmin | { } omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyadmin, UseFT | { } user1 | Sysadmin | { } user2 | Sysadmin | { } user3 | Sysadmin | { }
2.分别使用user1、user2、user3访问数据库musicdb2,创建各自的表,并插入数据。表名和数据如下:
表名分别为: products1、 products2、 products3
| 字段名 | 数据类型 | 含义 |
|---|---|---|
| product_id | INTEGER | 产品编号 |
| product_name | Char(20) | 产品名 |
| category | Char(30) | 种类 |
向表中插入数据:
| product_id | product_name | category |
|---|---|---|
| 1502 | olympus camera | electrncs |
| 1601 | lamaze | toys |
| 1700 | wait interface | Books |
| 1666 | harry potter | toys |
--执行下面的SQL语句,创建用户user1、user2、user3: --以用户user1的身份在数据库musicdb2中创建表products1,并插入一条数据: omm=# \c musicdb2 user1 Password for user user1: musicdb2=> Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "musicdb2" as user "user1". musicdb2=> create table products1(product_id integer,product_name char(20),category char(30)); CREATE TABLE musicdb2=> insert into products1 values(1502,'olympus camera','electrncs'); INSERT 0 1 musicdb2=> select * from products1; product_id | product_name | category ------------+----------------------+-------------------------------- 1502 | olympus camera | electrncs (1 row) --以用户user2的身份在数据库musicdb2中创建表products2,并插入一条数据: musicdb2=> \c musicdb2 user2 Password for user user2: Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "musicdb2" as user "user2". musicdb2=> create table products2(product_id integer,product_name char(20),category char(30)); CREATE TABLE musicdb2=> insert into products2 values(1601,'lamaze','toys'); INSERT 0 1 musicdb2=> select * from products2; musicdb2=> product_id | product_name | category ------------+----------------------+-------------------------------- 1601 | lamaze | toys (1 row) --以用户user3的身份在数据库musicdb2中创建表products3,并插入一条数据: musicdb2=> \c musicdb2 user3 Password for user user3: Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "musicdb2" as user "user3". musicdb2=> create table products3(product_id integer,product_name char(20),category char(30)); CREATE TABLE musicdb2=> insert into products3 values(1700,'wait interface','Books'); INSERT 0 1 musicdb2=> insert into products3 values(1666,'harry potter','toys'); INSERT 0 1 musicdb2=> select * from products3; product_id | product_name | category ------------+----------------------+-------------------------------- 1700 | wait interface | Books 1666 | harry potter | toys (2 rows)
3.使用user1、user2、user3用户中的任何一个,查看当前数据库musicdb2有哪些表
musicdb2=> \dt List of relations Schema | Name | Type | Owner | Storage --------+-----------+-------+-------+---------------------------------- public | products1 | table | user1 | {orientation=row,compression=no} public | products2 | table | user2 | {orientation=row,compression=no} public | products3 | table | user3 | {orientation=row,compression=no} (3 rows)




