oracle数据库表空间介绍及常用SQL
create tablespace data_test datafile 'e:\oracle\oradata\test\data_1.dbf' size 2000M; create tablespace idx_test datafile 'e:\oracle\oradata\test\idx_1.dbf' size 2000M;
1.2、 创建临时表空间,临时表空间用于用户执行查询时要使用的缓存空间。
文件路径保存在/opt/oracle/oradata/biee目录
CREATE TEMPORARY TABLESPACE DW_TEST_TMP_TBS TEMPFILE '/opt/oracle/oradata/biee/DW_TEST_TMP_TBS01.dbf' SIZE 32M AUTOEXTEND ON NEXT 32M MAXSIZE 2048M EXTENT MANAGEMENT LOCAL;
create user study identified by study default tablespace data_test;
CREATE USER cici IDENTIFIED BY cici PROFILE DEFAULT DEFAULT TABLESPACE CICI ACCOUNT UNLOCK; create user jykl identified by jykl default tablespace jykl_data temporary tablespace jykl_temp;
GRANT connect, resource TO cici; grant create session to cici;
grant connect,resource to study; --表示把 connect,resource权限授予study用户 grant dba to study; --表示把 dba权限授予给 study
5. 可以查询表空间使用状况的SQL
SELECT a.tablespace_name 表空间名称, total 总计, total - free 已使用, free 空闲, round((total - free) / total * 100, 2) 使用占比 FROM ( SELECT tablespace_name , round(SUM(bytes) / 1024 / 1024) AS total FROM dba_data_files GROUP BY tablespace_name ) a LEFT JOIN ( SELECT tablespace_name , round(SUM(bytes) / 1024 / 1024) AS free FROM dba_free_space GROUP BY tablespace_name ) b ON a.tablespace_name = b.tablespace_name ORDER BY (total - free) / total DESC;
查询结果如下,这样就可以清晰的看到数据库的具体使用情况啦。
6. 查看表空间的名称及大小
SELECT t.tablespace_name , round(SUM(bytes / (1024 * 1024)), 0) AS ts_size FROM dba_tablespaces t, dba_data_files d WHERE t.tablespace_name = d.tablespace_name GROUP BY t.tablespace_name;
7. 查看表空间物理文件的名称及大小
SELECT tablespace_name, file_id, file_name, round(bytes / (1024 * 1024), 0) total_space FROM dba_data_files ORDER BY tablespace_name;
参考链接:https://www.cnblogs.com/wyf0518/p/11319868.html
https://www.cnblogs.com/qmfsun/p/3817344.html
https://www.cnblogs.com/30go/p/7910690.html