课后作业
1.创建表空间newtbs1、 ds_location1,查看表空间
2.创建一个数据库newdb1,默认表空间为newtbs1
3.创建用户user5,并授予SYSADMIN权限,访问数据库newdb1,在表空间ds_location1上,创建一个表newt1(表结构自定义)
4.查看表所在的表空间
5.查看表空间newtbs1、 ds_location1上的对象
1. 测试环境准备
--进入数据库omm,创建表空间、测试数据库
drop DATABASE IF EXISTS musicdb;
drop DATABASE IF EXISTS musicdb1;
drop DATABASE IF EXISTS musicdb2;
drop DATABASE IF EXISTS musicdb3;
drop tablespace IF EXISTS music_tbs;
revoke all on database omm from user1;
drop owned by user1 cascade;
drop user user1;
\c postgres
revoke all on database postgres from user1;
drop owned by user1 cascade;
drop user user1;
--检查表属主
select relname,relnamespace,relkind from pg_class
where relowner=(select oid from pg_roles where rolname='user1')
order by 3 desc;
--检查用户的系统权限
SELECT * FROM pg_roles WHERE rolname='user1';
--检查用户的表权限
select * from information_schema.table_privileges where grantee='user1';
--检查用户的usage权限
select * from information_schema.usage_privileges where grantee='user1';
--检查用户在存储过程函数的执行权限
select * from information_schema.routine_privileges where grantee='user1';
--检查用户在表的列上的权限
select * from information_schema.column_privileges where grantee='user1';
--检查用户自定义类型上授予的USAGE权限
select * from information_schema.udt_privileges where grantee='user1';
--执行下面的SQL语句,创建用户user5:
CREATE USER user5 IDENTIFIED BY 'kunpeng@1234';
--授予user5数据库系统的SYSADMIN权限:
ALTER USER user5 SYSADMIN;

2.创建实验数据库和表空间
CREATE TABLESPACE newtbs1 RELATIVE LOCATION 'tablespace/newtbs1_1';
CREATE TABLESPACE ds_location1 RELATIVE LOCATION 'tablespace/ds_location1_1';
CREATE DATABASE newdb1 WITH TABLESPACE = newtbs1;
--查看实例当前有哪些表空间:
\db

3. 使用 user5 用户,访问 newdb1 数据库 ,在表空间 ds_location1 上创建表newt1
\c newdb1 user5
create table newt1 (col1 char(10)) tablespace ds_location1;
-- 查看musicdb数据库目前有哪些表:
select table_catalog, table_schema, table_name, table_type from information_schema.tables
where table_schema not in ('pg_catalog', 'information_schema','dbe_perf');
-- 查看表newt1所在的表空间:
select * from pg_tables where tablename = 'newt1';
-- 创建表newt12未指定表空间,则在默认表空间(不显示默认表空间名)
create table newt12 (col1 char(10));
select * from pg_tables where tablename = 'newt12';

4. 查看数据库的默认表空间
select datname,dattablespace,spcname from pg_database d, pg_tablespace t where d.dattablespace=t.oid;

5. 查询对象
-- 查询数据库的默认表空间上的对象
select relname, relkind, relpages,pg_size_pretty(pg_relation_size(a.oid)),reltablespace,relowner
from pg_class a where a.relkind in ('r', 'i') and reltablespace='0'
order by a.relpages desc;
-- 查询表空间'ds_location1','newtbs1'上的对像
\c newdb1 user5
select relname, relkind, relpages,pg_size_pretty(pg_relation_size(a.oid)),reltablespace,relowner
from pg_class a, pg_tablespace tb
where a.relkind in ('r', 'i') and a.reltablespace=tb.oid and tb.spcname in ('ds_location1','newtbs1') order by a.relpages desc;

最后修改时间:2022-12-01 14:56:25
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




