1.導(dǎo)庫(kù):導(dǎo)出和導(dǎo)入整個(gè)數(shù)據(jù)庫(kù)
2.導(dǎo)表空間:導(dǎo)出和導(dǎo)入表空間
3.導(dǎo)表用戶:導(dǎo)出和導(dǎo)入用戶中所有對(duì)象
4.導(dǎo)表:導(dǎo)出和導(dǎo)入表或表分區(qū)

(1)commit=y 插入并提交,頻繁提交會(huì)影響數(shù)據(jù)庫(kù)效率。提交數(shù)據(jù)庫(kù)過(guò)大時(shí)可以添加。
(2)ignore=y/n 該參數(shù)表示忽略創(chuàng)建錯(cuò)誤,并繼續(xù)執(zhí)行。
(3)full=y 是否完全導(dǎo)入。

1.導(dǎo)出導(dǎo)入表
備份測(cè)試表:
create tables emp_test as select * from emp_test;

exp導(dǎo)出數(shù)據(jù)庫(kù)表:
exp scott/123456@orcl file=/oracle/bak_oracle/emp_test.dmp tables="emp_test"
按條件進(jìn)行選擇性導(dǎo)出
exp scott/123456@10.1.1.10:1521/orcl file=/oracle/bak_oracle/emp_test.dmp tables="emp_test" query=\\\\"where sal between \\\’1000\\\’ and \\\’2000\\\’\\\\" log=/oracle/bak_oracle/emp_test.log
用有權(quán)限用戶導(dǎo)出不同用戶的不同表
exp \\\\\\\’sys/syste as sysdba\\\\\\\’ file=/oracle/bak_oracle/emp_test.dmp tables="scott.emp_test,test.tab_test"

注:oracle用戶登錄并且配置了TNSNAME可以直接scott/123456
不是本機(jī)備份scott/123456@10.1.1.10:1521/orcl

刪除測(cè)試表
drop table emp_test ;
參數(shù)purge

imp導(dǎo)入數(shù)據(jù)庫(kù)表:
查詢?cè)撚脩舸娣艛?shù)據(jù)的缺省表空間:select username,default_tablespace from dba_users where username = \\\’SCOTT\\\’;
在特殊情況下有些用戶的數(shù)據(jù)需要放到特殊的表空間中,使用如下的命令進(jìn)行修改。
修改該用戶存放數(shù)據(jù)的缺省表空間:alter user scott default tablespace XXX;
imp scott/123456 file=/oracle/bak_oracle/emp_test.dmp
用有權(quán)限用戶導(dǎo)出不同用戶的不同表導(dǎo)入到一個(gè)用戶表中
imp \\\\\\\’sys/system as sysdba\\\\\\\’ file=/oracle/bak_oracle/emp_test.dmp fromuser=scott;

查詢表是否刪除和導(dǎo)入成功
select count(*) from emp_test;

2.導(dǎo)出導(dǎo)入用戶
導(dǎo)出一個(gè)用戶下面的數(shù)據(jù)
exp scott/123456 file=/oracle/bak_oracle/scott.dmp owner=scott;
刪除一個(gè)用戶
SQL> drop user scott cascade;
drop user scott cascade
*
ERROR at line 1:
ORA-01940: cannot drop a user that is currently connected
(1)查看是否有SQL語(yǔ)句在占用這張表
select sess.INST_ID, sess.machine,
sess.program, sess.sql_id,
sess.sid, sess.serial#,
sess.PROCESS
lo.oracle_username, lo.os_user_name,
lo.locked_mode,
ao.object_name, ao.object_type,
ao.status,
from gv$locked_object lo, dba_objects ao, gv$session sess
where ao.object_id = lo.object_id
and lo.session_id = sess.sid
and sess.username = \\\’SCOTT\\\’
–殺掉進(jìn)程 sid,serial#
alter system kill session\\\’10,11562\\\’;

(2)查看是否有會(huì)話沒有結(jié)束
SQL> select username,sid,serial#,paddr,status from v$session where username=\\\’SCOTT\\\’;
USERNAME SID SERIAL# PADDR STATUS


SCOTT 1 281 000000008E51C510 KILLED
SCOTT 20 362 000000008E491150 INACTIVE
SCOTT 21 175 000000008E48D050 INACTIVE
SCOTT 28 169 000000008E51C510 KILLED

SQL> select PROGRAM from v$process where addr=\\\’000000008E490110\\\’;
PROGRAM
oracle@master.example.com

–殺掉進(jìn)程 sid,serial#
alter system kill session \\\’1,281\\\’;
alter system kill session \\\’20,362\\\’;
alter system kill session \\\’21,175\\\’;
alter system kill session \\\’28,169\\\’;
SQL> drop user scott cascade;
User dropped.
導(dǎo)入一個(gè)用戶下面的數(shù)據(jù)
先授權(quán)(連接數(shù)據(jù)庫(kù)和DBA的權(quán)限)再導(dǎo)入(用戶SCOTT下面的所有表)
grant connect,resource to scott identified by 123456;
grant dba to scott;
imp scott/123456 file=/oracle/bak_oracle/scott.dmp full=y;

用有權(quán)限的用戶導(dǎo)入表給用戶
imp \\\’sys/system@10.1.1.10:1521/orcl as sysdba\\\’ file=/oracle/bak_oracle/scott.dmp fromuser=scott touser=scott
注:touser=可以給不同的用戶

3.導(dǎo)入導(dǎo)出表空間

—未完待續(xù)

需要備份的數(shù)據(jù)量大時(shí)建議選擇數(shù)據(jù)泵
數(shù)據(jù)庫(kù)的邏輯備份和恢復(fù):expdp和impdp
數(shù)據(jù)泵只能在數(shù)據(jù)庫(kù)的服務(wù)器端使用
在服務(wù)器上面創(chuàng)建目錄,用于導(dǎo)入導(dǎo)出時(shí)存放數(shù)據(jù)
create directory DATA_BAK as \\\’/oracle\\\’;
為目錄授權(quán)用戶讀和寫的權(quán)限
grant read,write on directory DATA_BAK to TEST;
查看目錄和擁有者、路徑
select * from dba_directories

expdp 用戶名/密碼@IP/網(wǎng)絡(luò)服務(wù)名 schemas=用戶名 directory=創(chuàng)建的目錄 dumpfile=數(shù)據(jù)表名.dmp logfile=數(shù)據(jù)表名.log
expdp test/test@10.1.1.10:1521/orcl schemas=\\\’TEST\\\’ directory=\\\’DATA_BAK\\\’ dumpfile=/oracle/xxx.dmp logfile=/oracle/xxx.log
schemas:用戶名,directory:創(chuàng)建的存放數(shù)據(jù)的目錄,dumpfile:將要導(dǎo)出的數(shù)據(jù)庫(kù)備份dmp文件,logfile:存放導(dǎo)出日志文件,compression:導(dǎo)出時(shí)對(duì)文件進(jìn)行壓縮

用腳本文件導(dǎo)出數(shù)據(jù)庫(kù)文件:
[oracle@master oracle]$ cat aa.par
userid=" test/test"
#userid=" / as sysdba" 用dba導(dǎo)出
directory=DATA_BAK
dumpfile=emp_test2.dmp
logfile=emp_test2.log
#parallel=5
compression=all
#nologfile=no
schemas=test
job_name=emp_test2_expdp
使用命令調(diào)用:
nohup expdp parfile=aa.par &

用命令導(dǎo)出數(shù)據(jù)庫(kù)文件:
expdp test/test@10.1.1.10/orcl directory=DATA_BAK dumpfile=emp_test2.dmp logfile=emp_test2.log schemas=test

數(shù)據(jù)泵導(dǎo)入數(shù)據(jù)庫(kù)語(yǔ)句:
impdp test/test@10.1.1.10:1521/orcl REMAP_SCHEMA = test:test table_exists_action = replace directory=DATA_BAK dumpfile=emp_test2.dmp logfile=emp_test2.log

數(shù)據(jù)庫(kù)的批量導(dǎo)入:SQL*Loader
連接用戶
查看表結(jié)構(gòu)

?
控制文件:
[oracle@master oracle]$ cat EMP_LOADERTEST2.ctl
LOAD DATA
INFILE \\\’/oracle/EMP_LOADERTEST2.ctl \\\’
TRUNCATE INTO TABLE EMP_LOADERTEST2
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY \\\’"\\\’
(EMPNO,ENAME,JOB)
數(shù)據(jù)文件:
[oracle@master oracle]$ cat EMP_LOADERTEST2.dat
11,a1,1,11,22,33,44,55
11,a2,2,11,22,33,44,55
11,a3,2,11,22,33,44,55
11,a4,3,11,22,33,44,55
導(dǎo)入時(shí),數(shù)據(jù)文件中的數(shù)據(jù),需要和控制文件中相對(duì)應(yīng)
需要導(dǎo)入的表中的字段類型需要一致
sqlldr test/test control=/oracle/EMP_LOADERTEST2.ctl data=EMP_LOADERTEST2.dat

產(chǎn)生了sqlldr的日志文件

查看日志文件中數(shù)據(jù)庫(kù)導(dǎo)入的情況

檢查表中是否有數(shù)據(jù)

擴(kuò)展表空間

系統(tǒng)表空間會(huì)自動(dòng)擴(kuò)大,如果系統(tǒng)表空間莫名其妙的大
1.查詢審計(jì)功能是否開著,審計(jì)表內(nèi)數(shù)據(jù)大影響的
查看審計(jì)功能是否打開
show parameter audit;
2.關(guān)閉審計(jì)功能命令
SQL> alter system set audit_sys_operations=FALSE scope=spfile;
System altered.
SQL> alter system set audit_trail=NONE scope=spfile;
System altered.
重啟數(shù)據(jù)庫(kù)生效

注:audit_sys_operations的參數(shù)設(shè)置:
none 禁用數(shù)據(jù)庫(kù)審計(jì)
os 啟用數(shù)據(jù)庫(kù)審計(jì),并將數(shù)據(jù)庫(kù)審計(jì)記錄定向到操作系統(tǒng)審計(jì)記錄
db 啟用數(shù)據(jù)庫(kù)審計(jì),并將數(shù)據(jù)庫(kù)所有審計(jì)記錄定向到數(shù)據(jù)庫(kù)的SYS.AUD$表
xml 啟用數(shù)據(jù)庫(kù)審計(jì),并將所有記錄寫到XML格式的操作系統(tǒng)文件中。
xml,extended 啟用數(shù)據(jù)庫(kù)審計(jì),輸出審計(jì)記錄的所有列,包括SqlText和SqlBind的值。

3.查詢統(tǒng)計(jì)信息是否過(guò)多
統(tǒng)計(jì)信息時(shí)間默認(rèn)為31天,時(shí)間可以修改為10天或一周,過(guò)期的統(tǒng)計(jì)信息系統(tǒng)自動(dòng)刪除
SQL> select dbms_stats.get_stats_history_retention from dual;
SQL> conn / as sysdba
Connected.
SQL> exec dbms_stats.alter_stats_history_retention(10);

更多關(guān)于云服務(wù)器域名注冊(cè),虛擬主機(jī)的問題,請(qǐng)?jiān)L問三五互聯(lián)官網(wǎng):www.shinetop.cn

贊(0)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享網(wǎng)絡(luò)內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。郵箱:3140448839@qq.com。本站原創(chuàng)內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明出處:三五互聯(lián)知識(shí)庫(kù) » IMP/EXP,數(shù)據(jù)泵,SQL*Loader ,rman,oracle數(shù)據(jù)庫(kù)備份

登錄

找回密碼

注冊(cè)