• 数据库管理实用语句


    1、查看表空间文件占用比例

    select b.file_id

      as 文件ID,
      b.tablespace_name
      as 表空间,
      b.file_name
      as 物理文件名,
      b.bytes/1024/1024/1024
      as 总字节数,
      (b.bytes-sum(nvl(a.bytes,0)))/1024/1024/1024
      as 已使用,
      sum(nvl(a.bytes,0))/1024/1024/1024       
    as 剩余,
      sum(nvl(a.bytes,0))/(b.bytes)*100 
    as 剩余百分比
      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 ;

    2、一键查询有表分区的表

    SELECT TABLE_NAME,PARTITION_NAME,TABLESPACE_NAME
    FROM USER_TAB_PARTITIONS;

    3、查询oracle当前被锁对象

    select a.session_id, c.serial#, a.locked_mode, a.oracle_username, a.os_user_name, c.machine,
    c.terminal, b.object_name, c.logon_time
    from v$locked_object a, all_objects b, v$session c
    where a.object_id = b.object_id and a.session_id = c.sid
    order by c.sid, c.serial#;

    根据查出来的数据KILL掉

    alter system kill session '24,111'; 

    -4.察看TAXI用户的TAXIIDXTBS表空间有什么数据段
    select * from DBA_SEGMENTS where owner = 'TAXI' and tablespace_name = 'TAXIIDXTBS' order by header_block desc;
    --5.收缩数据文件
    select a.file#,a.name,a.bytes/1024/1024 CurrentMB,
    ceil(HWM * a.block_size)/1024/1024 ResizeTo,
    (a.bytes - HWM * a.block_size)/1024/1024 ReleaseMB,
    'alter database datafile '''||a.name||''' resize '||
    ceil(HWM * a.block_size/1024/1024) || 'M;' ResizeCMD
    from v$datafile a,
    (select file_id,max(block_id+blocks-1) HWM
    from dba_extents
    group by file_id) b
    where a.file# = b.file_id(+)
    and (a.bytes - HWM *block_size)>0
    order by 5
    --6.增加表空间
    ALTER TABLESPACE "SMCXKH" ADD DATAFILE 'F:APPADMINISTRATORORADATAORCL estdbf1' SIZE 100M AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED
    给SMCXKH表空间,增加testdbf1的数据文件,初始100M,每次增长100M,最大长到32G

    --7更改数据库密码

    -免密登入数据库:sqlplus "/as sysdba"
    更改密码:alter user sys identified by oracle;

    关闭/重启数据库

    shutdown immediate; --关闭数据库
    startup; --重启数据库

    --8查询当前用户使用的表空间
    select default_tablespace from dba_users where username='登录用户';

    --9数据库块对应的表查询

    SELECT A.TABLE_NAME,
           A.COLUMN_NAME,
           B.SEGMENT_NAME,
           B.SEGMENT_TYPE,
           B.TABLESPACE_NAME,
           B.BYTES / 1024 / 1024,
           B.BLOCKS,
           B.EXTENTS
      FROM USER_LOBS A, USER_SEGMENTS B
    WHERE A.SEGMENT_NAME = B.SEGMENT_NAME
    ORDER BY B.BYTES DESC;

    --10表按时间来查询统计数字
    select count(*) from TORN t where t.TXN_TIME> to_date('2019-06-17','yyyy-mm-dd')
    and t.TXN_TIME<to_date('2019-06-19','yyyy-mm-dd');

    --11查看用户及表空间占用大小

     select se.segment_name,se.segment_type,se.tablespace_name,se.header_block, se.BYTES

    from DBA_SEGMENTS se where owner = 'TAXI'
    and tablespace_name = 'TAXITBS'
    order by BYTES desc;

    --12、开启密码复杂度验证函数

    sqlplus / as sysdba

    @?/rdbms/admin/utlpwdmg.sql
    你要先去配置utlpwdmg.sql文件


    ---13-查看当前有哪些用户正在使用数据
    SELECT osuser, a.username,cpu_time/executions/1000000||'s',b.sql_text,machine
    from v$session a, v$sqlarea b
    where a.sql_address =b.address order by cpu_time/executions desc;   

    ---14-是把B表的所有数据,插入到A表

     insert into A表 select * from B表; 
     
     

    ---15- 复制表结构及其数据:

    create table table_name_new as select * from table_name_old

    ---16-  只复制表结构:

    create table table_name_new as select * from table_name_old where 1=2;

    或者:

    create table table_name_new like table_name_old

    ---17-  按时间查询筛选:

    select count(*) from CARD t where t.TXN_TIME> to_date('2019-06-17','yyyy-mm-dd')
    and t.TXN_TIME<to_date('2019-06-19','yyyy-mm-dd');

    ---18---一键查询有表分区的表


    SELECT TABLE_NAME,PARTITION_NAME,TABLESPACE_NAME
    FROM USER_TAB_PARTITIONS;

     
     
  • 相关阅读:
    base64 转blob,base64 转文件
    下载附件时防止连点
    windows更新失败
    ValidationError: webpack Dev Server Invalid Options
    导入,导出
    软件的结构
    VueRouter(一)
    根据IP判断所在地区
    phpcms v9 非超级管理员 发布不了内容的解决办法
    VIM 快捷键
  • 原文地址:https://www.cnblogs.com/torn/p/11683767.html
Copyright © 2020-2023  润新知