Oracle相关数据库操作
1.进入oracle后台操作
su - oracle
2.数据库备份的指定位置
Oracle用sys用户登录查询数据库
select * from dba_directories a where a.directory_name='DATA_PUMP_DIR';
这边不一定是DATA_PUMP_DIR,哪里空间大可以放在哪里,备份的时候指向位置替换下即可
3.Expdp数据泵导出
expdp为数据泵导出,导入时需要impdp
expdp dlfs0824/bs directory=DATA_PUMP_DIR dumpfile=dlfs0824.dmp logfile=dlfs0824.log 【version=11.1.1】
4.Exp导出
exp导出的文件需要imp导入,和数据库版本没有关系
exp dlfs0824/bs file=dlfs0824.dmp owner=dlfs0824
5.Exp导出多张表
exp dlfs/bs file=A.dmp tables="(rp_report,rp_dataset)"
6.Impdp导入
impdp dlfs0830/bs directory=DATA_PUMP_DIR dumpfile=dlfs0824.dmp remap_schema=dlfs0824:dlfs0830 schemas=dlfs0824
7.Imp导入
imp dlfs0830/bs file=dlfs0824.dmp 【log=dlfs0824.log】 full=y
8.查找表空间目录存放
select * from dba_data_files a where a.tablespace_name='USERS'
9.创建表空间
select t1.name,t2.name from v$tablespace t1,v$datafile t2 where t1.ts# = t2.ts#;
创建表空间:
CREATE TABLESPACE "TBS_PLATFORM" LOGGING DATAFILE '+DATA/orcl/datafile/TBS_PLATFORM.ORA' SIZE 100M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO; ALTER DATABASE DATAFILE '+DATA/orcl/datafile/TBS_PLATFORM.ORA' AUTOEXTEND ON NEXT 1M;
按照下图修改
表空间名小写变大写
alter tablespace "fnbank" rename to "FNBANK1"; alter tablespace "FNBANK1" rename to "FNBANK";
扩展表空间:扩展表空间可以新增一个数据文件
ALTER TABLESPACE FS_BASE_TBS ADD DATAFILE '/opt/11g/oracle/oradata/orcl/FS_BASE_TBS01.ORA' SIZE 2G AUTOEXTEND ON NEXT 1G ;
10.杀掉Oracle中的会话
杀掉Oracle中的会话,即“使登录某数据库的电脑退出数据库登录,方便我们删掉数据库”,可以用有dba权限的用户登录,查询到对象,并删除指定的会话(即登录要删除的数据库的机器)
单个处理
---查询要关闭的数据库的使用者 select t.machine,t.status,t.sid,t.serial# from v$session t where t.username='数据库用户名'; ---kill掉要关闭的使用者 alter system kill session 'sid, serial#';
11.必删除
Plsql的command window窗口打开,执行
alter user 用户名 account lock; select t.machine,t.status,t.sid,t.serial# from v$session t where t.username='用户名大写'; alter system kill session '1330, 63025';
12.便捷式
SELECT 'alter system kill session '''||SID || ',' || SERIAL#||' IMMEDIATE'';' FROM V$SESSION t where t.USERNAME='HLJFS0830';
alter system kill session '85,58875'IMMEDIATE; alter system kill session '317,25587'IMMEDIATE; alter system kill session '321,56899'IMMEDIATE; alter system kill session '788,33507'IMMEDIATE; alter system kill session '865,36649'IMMEDIATE; alter system kill session '1061,25555'IMMEDIATE; alter system kill session '1293,5887'IMMEDIATE; alter system kill session '1406,13859'IMMEDIATE; alter system kill session '1445,57841'IMMEDIATE; alter system kill session '1485,5809'IMMEDIATE;
14.数据库锁表
select * from v$locked_object;
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;
15.查询含同一字段所有表
select column_name,table_name,data_type,data_length,data_precision,data_scale from user_tab_columns where column_name like 'FINCOMESORT%'
16.批量导出
打开PLSQL,选择Tools/Export User Opjects
导出后稍做修改
有库名的删掉
17.单个导出
复制黏贴
18.表数据查重
--查询表中是否有重复记录(财政票据的两张表可能存在重复) select * from fba_set a where (a.fmemo) in (select fmemo from fba_set group by fmemo having count(*) > 1) ; select * from fba_dict a where (a.fname) in (select fname from fba_dict group by fname having count(*) > 1) ;
19.字符集相关查询
select * from nls_instance_parameters where parameter='NLS_LANGUAGE'; ---oracle客户端 select userenv('language') from dual; ---oracle服务端,如果字符集不是AMERICAN _ AMERICA. ZHS16GBK,实例删掉重建比较快 (在unix主机上):---dmp字符集 cat dmp文件名.dmp |od -x|head -1|awk '{print $2 $3}'|cut -c 3-6 返回结果“0354”,则在数据库操作: SQL> select nls_charset_name(to_number('0354','xxxx')) from dual;
20.Oracle找表名
select * from user_tab_comments t where t.comments like '%用户%'
21.导库报错原因
Ora-39143:说明dmp用exp导出 Ora-39142:版本太低