--修改時間戳:sql
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';session
commit;app
--db2數據庫修改時間戳:ide
update sys_user t set t.login_date=to_timestamp('18/04/10 09:09:45','YYYY/MM/DD HH24:MI:SS')ui
where t.login_name='admin';spa
commit;索引
--數據庫鎖表了(解鎖,殺進程):進程
查詢出鎖表的session信息get
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