以下操作请使用sys系统账号操作!
1. 查询物理存储的位置
1 2 3 4 5 6 |
SELECT tablespace_name, file_id, file_name, round(bytes / (1024 * 1024), 0) total_space FROM dba_data_files ORDER BY tablespace_name; |
从图中filename字段可以看到中数据库文件存放在服务器的/opt/oracle/oradata/biee/目录下:
2. 创建用户的临时表空间
临时表空间用于用户执行查询时要使用的缓存空间。
文件路径保存在/opt/oracle/oradata/biee目录
1 2 3 4 5 6 |
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; |
3. 创建用户的表空间
表空间用于存储表的内容的空间。
这里要指定初始代销,自增的大小,以及文件的最大值。
1 2 3 4 5 6 7 8 9 |
create tablespace DW_TEST_TBS logging datafile '/opt/oracle/oradata/biee/DW_TEST_TBS01.dbf' size 7167M autoextend on next 3072M maxsize 32767M autoallocate extent management local segment space management auto; |
4. 创建用户
指定用户的默认表空间为DW_TEST_TBS,临时表空间为DW_TES_TMP_TBS
1 |
create user DW_TEST identified by "DW_TEST" default tablespace DW_TEST_TBS temporary tablespace DW_TEST_TMP_TBS profile DEFAULT; |
5. 修改用户的权限
给用户添加以下权限。
1 2 3 4 5 6 7 8 9 |
GRANT CREATE SESSION, CREATE ANY TABLE, CREATE ANY VIEW ,CREATE ANY INDEX, CREATE ANY PROCEDURE, ALTER ANY TABLE, ALTER ANY PROCEDURE, DROP ANY TABLE, DROP ANY VIEW, DROP ANY INDEX, DROP ANY PROCEDURE, SELECT ANY TABLE, INSERT ANY TABLE, UPDATE ANY TABLE, DELETE ANY TABLE, SELECT ANY SEQUENCE, CREATE ANY SEQUENCE,DROP ANY SEQUENCE,create trigger TO DW_TEST; ALTER user DW_TEST QUOTA UNLIMITED ON DW_TEST_TBS; |
6. 增加表空间大小
通常完成1-5步骤以后,就可以使用DW_TEST用户登录使用了,此时表空间只分配了一个文件。
为了减少运维麻烦,通常在初始创建时创建多个表空间文件,这样可以维持使用很久。
因此,我通常每次都是增加10-20个文件来使用,注意每个文件后面的序号连续。
1 2 3 4 5 6 7 8 9 |
ALTER TABLESPACE DW_TEST_TBS ADD DATAFILE '/opt/oracle/oradata/biee/DW_TEST_TBS02.dbf' SIZE 7167M AUTOEXTEND ON NEXT 3072M MAXSIZE 32767M; ALTER TABLESPACE DW_TEST_TBS ADD DATAFILE '/opt/oracle/oradata/biee/DW_TEST_TBS03.dbf' SIZE 7167M AUTOEXTEND ON NEXT 3072M MAXSIZE 32767M; ALTER TABLESPACE DW_TEST_TBS ADD DATAFILE '/opt/oracle/oradata/biee/DW_TEST_TBS04.dbf' SIZE 7167M AUTOEXTEND ON NEXT 3072M MAXSIZE 32767M; ALTER TABLESPACE DW_TEST_TBS ADD DATAFILE '/opt/oracle/oradata/biee/DW_TEST_TBS05.dbf' SIZE 7167M AUTOEXTEND ON NEXT 3072M MAXSIZE 32767M; ALTER TABLESPACE DW_TEST_TBS ADD DATAFILE '/opt/oracle/oradata/biee/DW_TEST_TBS06.dbf' SIZE 7167M AUTOEXTEND ON NEXT 3072M MAXSIZE 32767M; ALTER TABLESPACE DW_TEST_TBS ADD DATAFILE '/opt/oracle/oradata/biee/DW_TEST_TBS07.dbf' SIZE 7167M AUTOEXTEND ON NEXT 3072M MAXSIZE 32767M; ALTER TABLESPACE DW_TEST_TBS ADD DATAFILE '/opt/oracle/oradata/biee/DW_TEST_TBS08.dbf' SIZE 7167M AUTOEXTEND ON NEXT 3072M MAXSIZE 32767M; ALTER TABLESPACE DW_TEST_TBS ADD DATAFILE '/opt/oracle/oradata/biee/DW_TEST_TBS09.dbf' SIZE 7167M AUTOEXTEND ON NEXT 3072M MAXSIZE 32767M; ALTER TABLESPACE DW_TEST_TBS ADD DATAFILE '/opt/oracle/oradata/biee/DW_TEST_TBS010.dbf' SIZE 7167M AUTOEXTEND ON NEXT 3072M MAXSIZE 32767M; |
7. 查询结果
1 2 3 4 5 6 7 |
SELECT tablespace_name, file_id, file_name, round(bytes / (1024 * 1024), 0) total_space FROM dba_data_files where tablespace_name = 'DW_TEST_TBS' ORDER BY tablespace_name; |