-- 查看所有数据文件路径以及对应的表空间名
select file_name , tablespace_name from dba_data_files;
SELECT
TABLE_NAME,
TABLESPACE_NAME
FROM
USER_TABLES
SELECT t.tablespace_name, round(SUM(bytes / (1024 * 1024)), 0) ts_size
FROM dba_tablespaces t, dba_data_files d
WHERE t.tablespace_name = d.tablespace_name
GROUP BY t.tablespace_name;
SELECT SUM(bytes) / (1024 * 1024) AS free_space, tablespace_name
FROM dba_free_space
GROUP BY tablespace_name;
SELECT a.tablespace_name,
a.bytes total,
b.bytes used,
c.bytes free,
(b.bytes * 100) / a.bytes "% USED ",
(c.bytes * 100) / a.bytes "% FREE "
FROM sys.sm$ts_avail a, sys.sm$ts_used b, sys.sm$ts_free c
WHERE a.tablespace_name = b.tablespace_name
AND a.tablespace_name = c.tablespace_name;
-- 查看所有表空间,总容量,剩余容量
SELECT tbs 表空间名,
sum(totalM) 总共大小M,
sum(usedM) 已使用空间M,
sum(remainedM) 剩余空间M,
sum(usedM)/sum(totalM)*100 已使用百分比,
sum(remainedM)/sum(totalM)*100 剩余百分比
FROM(
SELECT b.file_id ID,
b.tablespace_name tbs,
b.file_name name,
b.bytes/1024/1024 totalM,
(b.bytes-sum(nvl(a.bytes,0)))/1024/1024 usedM,
sum(nvl(a.bytes,0)/1024/1024) remainedM,
sum(nvl(a.bytes,0)/(b.bytes)*100),
(100 - (sum(nvl(a.bytes,0))/(b.bytes)*100))
FROM dba_free_space a,dba_data_files b
WHERE a.file_id = b.file_id
GROUP BY b.tablespace_name,b.file_name,b.file_id,b.bytes
ORDER BY b.tablespace_name
)
GROUP BY tbs
--创建新的表空间
create tablespace njdata datafile '+WLW_DATA1' size 28000m autoextend on next 100m maxsize 30000m extent management local segment space management auto;
--查看表空间数据文件
select file_name from dba_data_files where tablespace_name='NJDATA';
--扩展表空间
alter tablespace njdata add datafile '+WLW_DATA1' size 28000m autoextend on next 100m maxsize 30000m;
--查询当前用户所属表空间
select username,default_tablespace from user_users;
--创建用户、赋予权限
create user sdj identified by sdj ACCOUNT UNLOCK
DEFAULT TABLESPACE njdata TEMPORARY TABLESPACE TEMP;
grant connect to sdj;
grant resource to sdj;
GRANT CREATE USER,DROP USER,ALTER USER ,CREATE ANY VIEW ,DROP ANY VIEW,EXP_FULL_DATABASE,IMP_FULL_DATABASE,DBA,CONNECT,RESOURCE,CREATE SESSION TO sdj;
select count(*) from sdj.historydata
select * from sdj.historydata order by rtime desc