国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > 数据库 > 数据库应用 > 工作中的oracle常用维护

工作中的oracle常用维护

来源:程序员人生   发布时间:2015-01-20 08:56:30 阅读次数:2510次

http://blog.csdn.net/lili72


背景:由于历史缘由,公司部份业务还在使用oracle中。1出问题就是弄的很麻烦。由于长时间使用的是mysql hiveHbase等,1些oracle的命令渐渐的也是忘记了,但是公司某些在oracle上的业务,突然出现问题,每次查找问题都查得比较费力,现把经常使用命令记录下来。

   常遇到的oracle的问题:

     1.0 远程登录到oracle

       1.0.1  ssh  root@192.168.119.132 -p22330

             su  oracle

       1.0.2  ps -ef | grep  oracle  

              

找到oracle的位置

进入sqlplus  

 sqlplus /nolog 

 conn /as  sysdba

     1.1  oracle密码过期,连接失败

         1.1.1 查看用户

 select * from dba_profiles where resource_type='PASSWORD';

         1.1.2 设置无过期

alter profile DEFAULT limit unlimited;  

alter profile DEFAULT limit password_reuse_time unlimited;

     1.2  oracle的表分区超限,插入数据失败  由于oracle的范围分区

新增表分区:

alter table bi_test_1215_test_del add partition t_range_p132 values less than (to_date('20150110','yyyymmdd')) tablespace USERS storage ( initial 64K minextents 1 maxextents unlimited ) ;

 

     1.3  oracle的表空间满了,需要扩大。

        1.3.2 查看表空间占用情况:

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  

      1.3.2 扩大表空间:

       --增加数据文件

   alter tablespace USERS add datafile '/data2/oracle/users02.dbf' size 50m; 

     1.4  oracle的锁表处理

select sess.sid, 

    sess.serial#, 

    lo.oracle_username, 

    lo.os_user_name, 

    ao.object_name, 

    lo.locked_mode 

    from v$locked_object lo, 

    dba_objects ao, 

    v$session sess 

where ao.object_id = lo.object_id and lo.session_id = sess.sid; 

 

或:

select * from v$session t1, v$locked_object t2 where t1.sid = t2.SESSION_ID; 

删掉锁表语句:

alter system kill session '198'; 

     1.5  oracle语句优化,新增索引,建分区表

      1.5.1 首先斟酌查询条件 建索引。

    创建: create index inde_name on table_name  (col_name) tablespace users  storage  (  initial 500k  next 500k  pctincrease 0  ) 

  查询:select * from dba_indexes where table_name ='t_li72';

      1.5.2 数据量实比较大,斟酌建分区表。

create table li72_test_deal

(

  LOGDATE DATE,

  FILENAME VARCHAR2(600)

)

partition by range(logdate)(

partition t_range_p1 values less than (to_date('20140901','yyyymmdd')),

partition t_range_p2 values less than (to_date('20140902','yyyymmdd')),

 

 

   


Sqooporacle的语句:从hiveoracle

按分区选择列同步数据到oracle

sqoop export --connect jdbc:oracle:thin:@192.1.118.210:1521:orcl --username biuser --password biusertmp --table li72.tmp_SRC_PLAY_LH_1203_temp --columns LOGDATE,FILENAME,SINGER,SONG,SEARCHOVERPLAY,SEARCHPLAY,OVERPLAY,UNINPUTKEY,INPUTPARTKEY,INPUTALLKEY,MP3OVERPLAY,MVOVERPLAY,MVRANDOMPLAY,MP3RANDOMPLAY,TRYPLAY,DOWNLOAD,SEARCHCLICK,SEARCH,PLAY --export-dir /user/hive/warehouse/bi_test.db/li72_hoer_sear_play/dt=${vDay} --input-fields-terminated-by '|'

 

从oracle到hive中:

sqoop import--hive-import --connect jdbc:oracle:thin:@192.116.80.118:1521:CUSTOMER2--username biuser --password biusertmp --verbose -m 1 --table class_type

 

生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生