当前位置 博文首页 > iloki的博客:oracle表空间、用户

    iloki的博客:oracle表空间、用户

    作者:[db:作者] 时间:2021-08-25 12:40

    --创建表空间NR
    create tablespace NR datafile 'D:\NR.ora' size 3000m;
    --自动扩展表空间
    alter database datafile 'D:\NR.ora'  autoextend on; 
    --1.创建用户
    --使用管理员登录,打开sql窗口
    --推荐 Oracle10G 及以上, 准备项目自己的空用户, 假设叫 release
    -- 表空间默认用 users (发布时最好指定专用的表空间,假设叫NR)
    create user release identified by release default tablespace NR;
    --授予DBA权限
    grant connect,resource,dba  to release;
    -- Oracle10G 里创建视图必须显式授权
    grant create view to release;
    -- javamelody 能够查询数据库状态信息
    grant select any dictionary to release;
    
    --有删除权限,删除表用户及其文件
    drop user user_name cascade;
    --如果没有删除用户的权限,则可以执行:
    select 'drop table '||table_name||';'  from cat where table_type='TABLE'
    --将会输出一批删除表的sql语句,这些SQL语句执行一下就可以了。(需要有drop table的权限)
    
    --删除表空间及其文件
    drop tablespace NR including contents and datafiles;
    --增加表空间
    alter tablespace NR add datafile  'D:\NR.ora' size 2000m;
    --查询当前数据库中表空间NR是否为自动扩展
    select tablespace_name,file_name,autoextensible from dba_data_files where tablespace_name = 'NR';
    
    --查看表空间剩余大小
    SELECT a.tablespace_name as "表空间名", 
    total AS "总空间bytes", 
    free AS "剩余空间bytes", 
    (total - free) AS "已用空间bytes", 
    total / (1024 * 1024 * 1024) AS "总空间GB", 
    free / (1024 * 1024 * 1024) AS "剩余空间GB", 
    (total - free) / (1024 * 1024 * 1024) AS "已用空间GB", 
    (round((total - free) / total, 4) * 100)||'%' AS "已用空间百分比" 
    FROM (SELECT tablespace_name, SUM(bytes) free 
    FROM dba_free_space 
    GROUP BY tablespace_name) a, 
    (SELECT tablespace_name, SUM(bytes) total 
    FROM dba_data_files
    GROUP BY tablespace_name) b 
    WHERE a.tablespace_name = b.tablespace_name 
    
    cs
    下一篇:没有了