select username,sid,serial# from v$session;--找到对应的用户名的进程号alter system killsession'***,***';--删除此用户名下的所有表和视图dropuser qmssun cascade;--删除用户dropuser qmssun;--删除表空间droptablespace qmssun including contents and datafiles;--改变alterdatabase datafile 'qms711.DBF' offline drop;--解锁用户alteruser xm80501 account unlock;--获取oracle表空间在电脑中的创建地址select t1.name,t2.name from v$tablespace t1,v$datafile t2 where t1.ts# = t2.ts#;
2.统一表空间
--统一表空间SELECT('alter table '||a.TABLE_NAME||' move tablespace 新表空间名;')AS col
FROM user_tables a
WHERE tablespace_name='老的表空间名称'--ps:在转空间的过程中会产生失效的索引,应rebuild下可在toad操作,也可执行以下查询SELECT'ALTER INDEX '||t.INDEX_NAME||' REBUILD;'sqlFROM user_indexes t WHEREstatus='UNUSABLE'
3.oracle11g导出少表解决办法
--( ORACLE 11G中有个新特性,当表无数据时,不分配segment,以节省空间。)--1)设置deferred_se1gment_creation参数--只对设置之后的表起作用alter system set deferred_segment_creation=false;alter system set deferred_segment_creation=false scope=both;--2)批量处理空表select'alter table '||table_name||' allocate extent;'from user_tables where segment_created='NO'--3)----(1) 查询当前用户下的所有空表select table_name from user_tables where num_rows='0';----(2) 用以下SQL语句执行查询select'alter table '||table_name||' allocate extent;'from user_tables where num_rows=0;select'alter table '||table_name||' allocate extent;'from user_tables where num_rows=0or num_rows isnull;----假设我们这里有空表TABLE_1,TABLE_2,TABLE_3,TABLE_4,则查询结果如下:altertable TABLE_1 allocate extent;altertable TABLE_2 allocate extent;altertable TABLE_3 allocate extent;altertable TABLE_4 allocate extent;----(3) 把上面的 alter SQL语句执行就可以了----(4) 再查询当前用户下的所有空表,这时应该就没有空表了select'analyze table '||table_name||' compute statistics;'from user_tables;select table_name from user_tables where num_rows='0';
4.给数据库增加数据文件(原因:一个数据文件最大32G)
--1、查看数据库表空间如何查看表空间占用比SELECT a.tablespace_name "表空间名",
total "表空间大小",
free "表空间剩余大小",(total - free)"表空间使用大小",
total /(1024*1024*1024)"表空间大小(G)",
free /(1024*1024*1024)"表空间剩余大小(G)",(total - free)/(1024*1024*1024)"表空间使用大小(G)",round((total - free)/ total,4)*100"使用率 %"FROM(SELECT tablespace_name,SUM(bytes) free
FROM dba_free_space
GROUPBY tablespace_name) a,(SELECT tablespace_name,SUM(bytes) total
FROM dba_data_files
GROUPBY tablespace_name) b
WHERE a.tablespace_name = b.tablespace_name
--2、给数据库增加数据文件AlTERtablespace test ADD DATAFILE 'D:\data\test1.dbf' size 500M autoextend onnext50M maxsize unlimited;
5.设置密码无使用期限(默认180天)
//查看密码使用期限select*from dba_profiles s where s.profile='DEFAULT'and resource_name='PASSWORD_LIFE_TIME'//设置密码使用为无限制,不需要重启数据库(全部)alter profile defaultlimit password_life_time unlimited;//不用更换密码(已失效的)alteruser 用户名 identified by 原来的密码 account unlock;