zoukankan      html  css  js  c++  java
  • Oracle和db2数据库基础操作

    --修改时间戳:

    update sys_user t set t.login_date=to_timestamp('18-04-10 09:09:45.546000000','RR-MM-DD HH24:MI:SS:FF')

    where t.login_name='admin';

    commit;

    --db2数据库修改时间戳:

    update sys_user t set t.login_date=to_timestamp('18/04/10 09:09:45','YYYY/MM/DD HH24:MI:SS')

    where t.login_name='admin';

    commit;

    --数据库锁表了(解锁,杀进程):

    查询出锁表的session信息

    select * from v$session  where sid=(select sid from v$lock where id1 = ( select object_id from user_objects where object_name=upper('IE_001_GYB_TMP')));

    杀死会话

    alter system kill session '248,61915';--alter system kill session 'SID,SERIAL#';

    --Oracle数据库清空回收站:

    purge recyclebin;

    --查看当前数据库连接数:select count(*) from v$process;

    --查看当前数据库的最大连接数:select value from v$parameter where name='processes';

    --查看数据库字符集:select userenv('language') from dual;

    --创建表空间:
    create tablespace tableSpaceName datafile '/u01/aaa/bbb/a.dbf' size 512M autoextend on next 512M maxsize 2048M;

    --查看表空间的数据文件在哪里:select * from v$datafile;

    --查看临时表空间的数据文件在哪里:select * from v$tempfile;

    --扩大表空间:

    alter tablespace tableSpacename add datafile '/u01/aaa/bbb/ccc.dbf' size  20480M;(--数据文件最大为32G)

    alter tablespace tmpspaceName add tempfile '/u02/aaa/bbb/ccc.dbf' size 2048M;--扩大临时表空间大小

    修改表空间大小:alter database datafile '/u02/aaa/bbb/ccc.dbf' autoextend on maxsize 307200M;

    修改临时表空间大小:alter database tempfile '/u02/aaa/bbb/ccc.dbf' resize 30720M;

    --创建用户:

    create user aaa identified by aaa default tablespace tablespaceName;

    --给用户赋权限:

    grant create session ,alter session to aaa;

    grant create sequence to aaa;

    grant create table to aaa;

    grant create view to aaa;

    grant create any procedure,execute any procedure to aaa;

    grant select any dictionary to aaa;

    grant unliminted tablespace to aaa;--慎用

    --系统用户赋dba权限

    grant connect ,resource,dba to aaa;

    --撤销dba权限:

    revoke dba from aaa;

    --数据库导出dump文件:

    对所有的表进行move操作:select 'alter table '||table_name ||'move;' from user_tables;

    对所有的索引重建rebuildIndex操作:select 'alter index '||index_name||' rebuild;' from user_indexes;

    如果move不成功,是分区的化需要加上分区参数:select 'alter table '||table_name||' move partition '||'partition_name'||';' from user_tab_partitions;

    move核对:select segment_type,count(*) from user_segments group by segment_type having segment_type='TABLE'; 与 select count(1) from user_tables;

    不一致的化进行相减:select table_name from user_tables minus select segment_name from user_segments where segment_type='TABLE';

    查看重建索引时失效个数:select status,count(1) from user_indexes group by status;

    重建失效索引:select 'alter index '|| index_name ||'rebuild;' from user_indexes where status='UNUSABLE';

    索引不成功:先删再重建:

    alter table tableName DROP constraint 'pk_t01_ind_cust' DROP index;

    alter table tableName ADD constraint 'pk_t01_ind_cust' PRIMARY KEY (INDIC_KEY) using index;

    --开始导出dump操作:

    export ORACLE_SID=AAA

    sqlplus userName/password@192.168.8.235:1521/INSNAME owner=username file=/tmp/fileName statistics=none;

    或者指定导出某一张表:

    sqlplus userName/password@192.168.8.235:1521/INSNAME tables=tableName1,tableName2 file=/tmp/fileName statistics=none;

    --导入命令:

    export ORACLE_SID=INSNAME

    imp userName/password@192.168.8.235:1521/INSNAME fromuser=user1 touser=user2 file=/tmp/file.dmp ignore=y;--如果存在该表直接忽略导入该表,一般表结构未修改的化,可以使用此种导入方式

    如果为了保持和dmp文件一致的话:先将原来库的信息导出dmp文件进行备份,然后在将库清空,再导入dmp文件:

    sqlplus userName/password@192.168.8.235:1521/INSNAME owner=username file=/tmp/fileName statistics=none;

    如果导入dmp报错:IMP_00013:表示只有DBA角色才能导入其他DBA导出的文件:
    alter user cerification default role DBA;

    --数据库重启:
    sql> sthudown immediate

    sql> startup

    sql>lsnrctl status  --监听状态

    sql>lsnrctl start    --启动监听

    sql>lsnrctl stop    --停止监听

    -------db2导出数据数据:

    db2 connect to INSname user userName using password

    db2look -d INSname -z schemaName -e -o /tmp/movedata/db2_aaa.sql  --导出的是建表语句

    db2move INSname export -sn schemaName  --导出schemaName对应的数据

    db2move INSname export -tn tableName -tc schemaName -l /tmp/aaa/; --导出某一个表的数据,导出的路径中有一个db2move.list文件,如果导入不同的schema中需要修改成需要导入到的schema名字

    db2move -help :查看帮助手册,可以了解更多的db2move命令

    db2look -help:查看帮助手册,可以了解更多的db2look命令

    --db2导入数据:

    db2 -tsvf /tmp/movedata/db2_aaa.sql  --导入建表语句

    db2move INSname import;  --导入数据

    --db2创建表空间:

    db2 "create tablespace 表空间名 managed by database using( file '/u04/aa/bbb/ccc')"

    --db2扩大表空间:

    db2 "alter tablespace 表空间名 resize(file '/u04/aaa/bbb/ccc' 6G)"--修改表空间对应文件大小为6G

    db2 导出查询结果:

    db2 "export to /tmp/aaa.csv of del select * from aaa where a=1";

    --db2列出表空间:

    db2 list tablespaces show detail;

    db2 list tablespaces containers for 5 ; 5是tablespaceId

    --查看当前约束所有表的记录数

    select * from syscat.tables where TABSCHEMA='AAA';

    --查看锁

    db2 pd -db INSname -locks show detail;

    --获取锁信息

    db2 get snapshot for locks on INSname

    --删除链接

    db2 force application(242) 或者删除所有的应用

    db2 force application all

    --清除后台进程

    db2 terminate

  • 相关阅读:
    Java 概述
    快速开始
    Essential Java.《Java 编程要点》
    SpringBoot属性配置-第三章
    SpringBoot项目属性配置-第二章
    SpringBoot学习-第一章
    spring boot configuration annotation processor not found in classpath
    IntelliJ IDEA 2017 完美注册方法及破解方法
    springmvc-初次接触
    mybatis的多表联查
  • 原文地址:https://www.cnblogs.com/yehuili/p/9437692.html
Copyright © 2011-2022 走看看