ORACLE常用命令

lsnrctl start my_lsnr
lsnrctl status
lsnrctl status hq

检查监视器的进程
ps -ef | grep tnslsnr
//
lsnrctl 内停止监视器
set password lsnr_password
stop

//
lsnrctl 内列出所有的服务
set password lsnr_password
services
//
启动或停止一个NTlistener
net start Oracle<version_name>TNSListener
net stop Oracle<version_name>TNSListener

// tnsnames.ora
文件的内容
fld1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)
(HOST = server1.fld.com)(PORT = 1521))
)
(CONNECT_DATA =
(SID = fld1)
)
)
//
操作系统网络的管理

telnet host_name
ping host_name
/etc/hosts
文件
130.110.238.109 nmhost
130.110.238.101 txhost
130.110.238.102 azhost arizona
//oratab
表项
loc:/orasw/app/oracle/product/8.1.5.1:Y
cc1:/orasw/app/oracle/product/8.1.5.1:N
old:/orasw/app/oracle/product/8.1.5.0:Y

//创建一个控制文件命令到跟踪文件
alterdatabasebackupcontrolfiletotrace;

//增加一个新的日志文件组的语句
connectinternalassysdba
alterdatabase
addlogfilegroup4
(’/db01/oracle/CC1/log_1c.dbf’,
’/db02/oracle/CC1/log_2c.dbf’)size5M;

alterdatabase
addlogfilemember’/db03/oracle/CC1/log_3c.dbf’
togroup4;
//ServerManagerMOUNT并打开一个数据库:
connectinternalassysdba
startupmountORA1exclusive;
alterdatabaseopen;

//生成数据字典
@catalog
@catproc

//init.ora中备份数据库的位置
log_archive_dest_1=’/db00/arch’
log_archive_dest_state_1=enable
log_archive_dest_2="service=stby.worldmandatoryreopen=60"
log_archive_dest_state_2=enable
//对用户的表空间的指定和管理相关的语句
createuserUSERNAMEidentifiedbyPASSWORD
defaulttablespaceTABLESPACE_NAME;
alteruserUSERNAMEdefaulttablespaceTABLESPACE_NAME;
alteruserSYSTEMquota0onSYSTEM;
alteruserSYSTEMquota50MonTOOLS;
createuserUSERNAMEidentifiedbyPASSWORD
defaulttablespaceDATA
temporarytablespaceTEMP;
alteruserUSERNAMEtemporarytablespaceTEMP;

//重新指定一个数据文件的大小:
alterdatabase
datafile’/db05/oracle/CC1/data01.dbf’resize200M;

//创建一个自动扩展的数据文件:
createtablespaceDATA
datafile’/db05/oracle/CC1/data01.dbf’size200M
autoextendON
next10M
maxsize250M;

//在表空间上增加一个自动扩展的数据文件:
altertablespaceDATA
adddatafile’/db05/oracle/CC1/data02.dbf’
size50M
autoextendON
maxsize300M;

//修改参数:
alterdatabase
datafile’/db05/oracle/CC1/data01.dbf’
autoextendON
maxsize300M;

//在数据文件移动期间重新命名:
alterdatabaserenamefile
’/db01/oracle/CC1/data01.dbf’to
’/db02/oracle/CC1/data01.dbf’;

altertablespaceDATArenamedatafile
’/db01/oracle/CC1/data01.dbf’to
’/db02/oracle/CC1/data01.dbf’;

alterdatabaserenamefile
’/db05/oracle/CC1/redo01CC1.dbf’to
’/db02/oracle/CC1/redo01CC1.dbf’;

alterdatabasedatafile’/db05/oracle/CC1/data01.dbf’
resize80M;

//创建和使用角色:
createroleAPPLICATION_USER;
grantCREATESESSIONtoAPPLICATION_USER;
grantAPPLICATION_USERtousername;

//回滚段的管理
createrollbacksegmentSEGMENT_NAME
tablespaceRBS;

alterrollbacksegmentSEGMENT_NAMEoffline;

droprollbacksegmentSEGMENT_NAME;

alterrollbacksegmentSEGMENT_NAMEonline;
//回滚段上指定事务
commit;
settransactionuserollbacksegmentROLL_BATCH;
insertintoTABLE_NAME
select*fromDATA_LOAD_TABLE;
commit;

//查询回滚段的大小和优化参数
select*fromDBA_SEGMENTS
whereSegment_Type=’ROLLBACK’;
selectN.Name,/*rollbacksegmentname*/
S.OptSize/*rollbacksegmentOPTIMALsize*/
fromV$ROLLNAMEN,V$ROLLSTATS
whereN.USN=S.USN;

//回收回滚段
alterrollbacksegmentR1shrinkto15M;
alterrollbacksegmentR1shrink;

//例子
settransactionuserollbacksegmentSEGMENT_NAME

altertablespaceRBS
defaultstorage
(initial125Knext125Kminextents18maxextents249)

createrollbacksegmentR4tablespaceRBS
storage(optimal2250K);
alterrollbacksegmentR4online;

selectSessions_HighwaterfromV$LICENSE;
grantselectonEMPLOYEEtoPUBLIC;

//用户和角色
createroleACCOUNT_CREATOR;
grantCREATESESSION,CREATEUSER,ALTERUSER
toACCOUNT_CREATOR;

alteruserTHUMPERdefaultroleNONE;
alteruserTHUMPERdefaultroleCONNECT;
alteruserTHUMPERdefaultroleallexceptACCOUNT_CREATOR;

alterprofileDEFAULT
limitidle_time60;

createprofileLIMITED_PROFILElimit
FAILED_LOGIN_ATTEMPTS5;
createuserJANEidentifiedbyEYRE
profileLIMITED_PROFILE;
grantCREATESESSIONtoJANE;

alteruserJANEaccountunlock;
alteruserJANEaccountlock;

alterprofileLIMITED_PROFILElimit
PASSWORD_LIFE_TIME30;

alteruserjanepasswordexpire;

//创建操作系统用户
REMCreatingOPS$accounts
createuserOPS$FARMER
identifiedbySOME_PASSWORD
defaulttablespaceUSERS
temporarytablespaceTEMP;

REMUsingidentifiedexternally
createuserOPS$FARMER
identifiedexternally
defaulttablespaceUSERS
temporarytablespaceTEMP;

//执行ORAPWD
ORAPWDFILE=filenamePASSWORD=passwordENTRIES=max_users

createroleAPPLICATION_USER;
grantCREATESESSIONtoAPPLICATION_USER;
createroleDATA_ENTRY_CLERK;
grantselect,insertonTHUMPER.EMPLOYEEtoDATA_ENTRY_CLERK;
grantselect,insertonTHUMPER.TIME_CARDStoDATA_ENTRY_CLERK;
grantselect,insertonTHUMPER.DEPARTMENTtoDATA_ENTRY_CLERK;
grantAPPLICATION_USERtoDATA_ENTRY_CLERK;
grantDATA_ENTRY_CLERKtoMCGREGOR;
grantDATA_ENTRY_CLERKtoBPOTTERwithadminoption;

//设置角色
setroleDATA_ENTRY_CLERK;
setroleNONE;

//回收权利:
revokedeleteonEMPLOYEEfromPETER;
revokeallonEMPLOYEEfromMCGREGOR;

//回收角色:
revokeACCOUNT_CREATORfromHELPDESK;

dropuserUSERNAMEcascade;

grantSELECTonEMPLOYEEtoMCGREGORwithgrantoption;
grantSELECTonTHUMPER.EMPLOYEEtoBPOTTERwithgrantoption;
revokeSELECTonEMPLOYEEfromMCGREGOR;

createuserMCGREGORidentifiedbyVALUES’1A2DD3CCEE354DFA’;

alteruserOPS$FARMERidentifiedbyVALUES’noway’;

//备份与恢复
使用export程序
expsystem/managerfile=expdat.dmpcompress=Yowner=(HR,THUMPER)
expsystem/managerfile=hr.dmpowner=HRindexes=Ycompress=Y
impsystem/managerfile=hr.dmpfull=Ybuffer=64000commit=Y

//备份表
expsystem/managerFILE=expdat.dmpTABLES=(Thumper.SALES)
//备份分区
expsystem/managerFILE=expdat.dmpTABLES=(Thumper.SALES:Part1)

//输入例子
impsystem/managerfile=expdat.dmp
impsystem/managerfile=expdat.dmpbuffer=64000commit=Y

expsystem/managerfile=thumper.datowner=thumpergrants=N
indexes=Ycompress=Yrows=Y
impsystem/managerfile=thumper.datFROMUSER=thumperTOUSER=flower
rows=Yindexes=Y
impsystem/managerfile=expdat.dmpfull=Ycommit=Ybuffer=64000
impsystem/managerfile=expdat.dmpignore=Nrows=Ncommit=Ybuffer=64000

//使用操作系统备份命令
REMTARexamples
tar-cvf/dev/rmt/0hc/db0[1-9]/oracle/CC1
tar-rvf/dev/rmt/0hc/orasw/app/oracle/CC1/pfile/initcc1.ora
tar-rvf/dev/rmt/0hc/db0[1-9]/oracle/CC1/orasw/app/oracle/CC1/pfile/initcc1.ora

//离线备份的shell脚本
ORACLE_SID=cc1;exportORACLE_SID
ORAENV_ASK=NO;exportORAENV_ASK
.oraenv
svrmgrl<<EOF1
connectinternalassysdba
shutdownimmediate;
exit
EOF1
insertbackupcommandslikethe"tar"commandshere
svrmgrl<<EOF2
connectinternalassysdba
startup
EOF2

//ServerManager上设置为archivelogmode:
connectinternalassysdba
startupmountcc1;
alterdatabasearchivelog;
archivelogstart;
alterdatabaseopen;

//ServerManager上设置为archivelogmode:
connectinternalassysdba
startupmountcc1;
alterdatabasenoarchivelog;
alterdatabaseopen;

selectName,
Value
fromV$PARAMETER
whereNamelike’log_archive%’;

//联机备份的脚本
#
#SampleHotBackupScriptforaUNIXFileSystemdatabase
#
#Setupenvironmentvariables:
ORACLE_SID=cc1;exportORACLE_SID
ORAENV_ASK=NO;exportORAENV_ASK
.oraenv
svrmgrl<<EOFarch1
connectinternalassysdba
REM
REM
备份SYSTEMtablespace
REM
altertablespaceSYSTEMbeginbackup;
!tar-cvf/dev/rmt/0hc/db01/oracle/CC1/sys01.dbf
altertablespaceSYSTEMendbackup;
REM
REMTheSYSTEMtablespacehasnowbeenwrittentoa
REMtarsavesetonthetapedevice/dev/rmt/0hc.The
REMrestofthetarsmustusethe"-rvf"clausetoappend
REMtothatsaveset.
REM
REM
备份RBStablespace
REM
altertablespaceRBSbeginbackup;
!tar-rvf/dev/rmt/0hc/db02/oracle/CC1/rbs01.dbf
altertablespaceRBSendbackup;
REM
REM
备份DATAtablespace
REMForthepurposesofthisexample,thistablespace
REMwillcontaintwofiles,data01.dbfanddata02.dbf.
REMThe*wildcardwillbeusedinthefilename.
REM
altertablespaceDATAbeginbackup;
!tar-rvf/dev/rmt/0hc/db03/oracle/CC1/data0*.dbf
altertablespaceDATAendbackup;
REM
REM
备份INDEXEStablespace
REM
altertablespaceINDEXESbeginbackup;
!tar-rvf/dev/rmt/0hc/db04/oracle/CC1/indexes01.dbf
altertablespaceINDEXESendbackup;
REM
REM
备份TEMPtablespace
REM
altertablespaceTEMPbeginbackup;
!tar-rvf/dev/rmt/0hc/db05/oracle/CC1/temp01.dbf
altertablespaceTEMPendbackup;
REM
REMFollowthesamepatterntobackuptherest
REMofthetablespaces.
REM
REM
REMStep2.
备份归档日志文件.
archivelogstop
REM
REMExitServerManager,usingtheindicatorsetearlier.
exit
EOFarch1
#
#Recordwhichfilesareinthedestinationdirectory.
#Dothisbysettinganenvironmentvariablethatis
#equaltothedirectorylistingforthedestination
#directory.
#Forthisexample,thelog_archive_destis
#/db01/oracle/arch/CC1.
#
FILES=`ls/db01/oracle/arch/CC1/arch*.dbf`;exportFILES
#
#NowgobackintoServerManagerandrestartthe
#archivingprocess.Setanindicator(calledEOFarch2
#inthisexample).
#
svrmgrl<<EOFarch2
connectinternal
archivelogstart;

ORACLE常用命令:

http://blog.chinaunix.net/u3/94400/showart.php?id=1924141

你可能感兴趣的:(oracle)