--1.1上傳oracle軟件包及安裝環境檢查
--redhat6.8下載連接:https://pan.baidu.com/s/1eTyw102 密碼:cpfs
--虛擬機使用獨立磁盤時不能拍攝快照
--建立swap空間 -v顯示詳細信息
--上傳軟件包到/opt
df -h
mkdir -pv /u01/swap
dd if=/dev/zero of=/u01/swap/swap1 bs=1024M count=1
--dd if=/dev/zero of=/u01/swap/swap1 bs=1024M count=16(實際環境)
mkswap /u01/swap/swap1
--生效交換分區
swapon /u01/swap/swap1
echo swapon /u01/swap/swap1>>/etc/rc.localjava
df -h
fdisk -l
fdisk /dev/sdb 輸入 n p 1 enter enter w
--建立文件系統並格式化分區
mkfs.ext3 /dev/sdbmysql
--反掛載
--umount /dev/sdb
--硬盤分區並掛載到/u01下
mount /dev/sdb /u01
df -hlinux
--查詢UUID 配置開機掛載存儲
blkid
vi /etc/fstab
UUID=3ba1d7f6-cf6c-4d9e-83df-aeff405e74a0 /u01 ext3 defaults 1 2c++
--查詢配置
free
df -h
fdisk -l
cat /etc/issue
uname -asql
--1.2安裝所需包 (用互聯網yum或者是本地yum) 虛擬機中可能yum源有問題,不能批量安裝
--用第一個centos6.8鏡像包
cd /media/CentOS_6.8_Final/Packages --或配置yum源shell
yum -y install binutils-* compat-libstdc++-* gcc-* gcc-c++-* glibc-* glibc-devel libaio-* libaio-devel libgcc-4.1.2 libstdc++-* \
libstdc++-devel make sysstat elfutils-libelf-devel unixODBC-* unixODBC-devel-* elfutils-libelf-devel數據庫
cd /opt
rpm -ivh pdksh-5.2.14-30.x86_64.rpmvim
--參考
yum -y install 包名(支持*) :自動選擇y,全自動
yum install 包名(支持*) :手動選擇y or n
yum remove 包名(不支持*)
yum search 包名
yum list 包名關鍵字 查詢已安裝包
rpm -ivh 包名(支持*):安裝rpm包
rpm -e 包名(不支持*):卸載rpm包
yum grouplist 查看可能批量安裝的列表windows
--若yum源中的包不全,能夠rpm先查詢出包而後rpm逐一安裝
--或者rpm -q 或按包全名中的關鍵字查詢rpm -qa | grepbinutils
yum list binutils \
compat-libstdc \
gcc \
gcc-c \
glibc \
glibc-devel \
libaio \
libaio-devel \
libgcc \
libstdc \
libstdc++-devel \
make \
sysstat \
elfutils-libelf-devel \
unixODBC \
unixODBC-devel \
elfutils-libelf-develcentos
--Available Packages下面顯示未安裝軟件包 能夠用yum -y install安裝 -y靜默安裝
--因此所需安裝的軟件包爲
yum -y install elfutils-libelf-devel.x86_64
yum -y install libaio-devel.x86_64
yum -y install libstdc++-devel.x86_64
yum -y install unixODBC.x86_64
yum -y install unixODBC-devel.x86_64
--額外安裝軟件包pdksh pdksh-5.2.14-30.x86_64.rpm
--1.3 相關內核參數修改 當前服務器內存:16G
--(若是是內存不同須要修改kernel.shmall,kernel.shmmax,kernel.shmmax應大於sga)
--修改/etc/sysctl.conf
--註釋掉以前參數
sed -i '/kernel\.shmmax/s/^/#/' /etc/sysctl.conf
sed -i '/kernel\.shmall/s/^/#/' /etc/sysctl.conf
--編輯/etc/sysctl.conf
echo -e "#oracle insert\n">>/etc/sysctl.conf
echo "fs.aio-max-nr = 1048576">>/etc/sysctl.conf
echo "fs.file-max = 6815744">>/etc/sysctl.conf
echo "kernel.shmall = 4194304">>/etc/sysctl.conf
echo "kernel.shmmax = 15536870912">>/etc/sysctl.conf
echo "kernel.shmmni = 4096">>/etc/sysctl.conf
echo "kernel.sem = 250 32000 100 128">>/etc/sysctl.conf
echo "net.ipv4.ip_local_port_range = 9000 65500">>/etc/sysctl.conf
echo "net.core.rmem_default = 262144">>/etc/sysctl.conf
echo "net.core.rmem_max = 4194304">>/etc/sysctl.conf
echo "net.core.wmem_default = 262144">>/etc/sysctl.conf
echo "net.core.wmem_max = 1048586">>/etc/sysctl.conf
--運行如下命令使配置生效
sysctl -p
--修改/etc/security/limits.conf 增長如下內容
vi /etc/security/limits.conf
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
--編輯/etc/pam.d/login增長如下參數
vi /etc/pam.d/login
session required pam_limits.so
--1.4 修改服務器主機名及hosts
--更改主機名
hostname hostname-92-33
vim /etc/sysconfig/network
vim /etc/hosts
--修改完重啓服務器
1.5.增長相關用戶及目錄
groupadd oinstall
groupadd oper
groupadd dba
useradd -g oinstall -G dba,oper oracle
echo "oracle" | passwd --stdin oracle
mkdir -p /u01/app/oracle
mkdir -p /u01/app/oracle/soft
chown -R oracle:oinstall /u01/
--配置vnc 須要安裝tigervnc
rpm -qa |grep vnc
yum search vnc
yum -y install tigervnc-server.x86_64
rpm -qa |grep vnc
vim /etc/sysconfig/vncservers 增長
VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 1000x700"
--禁用防火牆和selinux
service iptables stop
chkconfig iptables off
vi /etc/selinux/config 改成
SELINUX=disabled
1.6修改用戶配置文件
su - oracle
vi ~/.bash_profile
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1; export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH
TNS_ADMIN=$ORACLE_HOME/network/admin;export TNS_ADMIN
NLS_LANG=AMERICAN_AMERICA.AL32UTF8; export NLS_LANG
SQLPATH=/u01/app/oracle/product/11.2.0/db_1/sqlplus/admin;export SQLPATH
stty erase ^H
export PATH
--二.安裝數據庫軟件
--解壓軟件包
exit
mv /opt/p* /u01/app/oracle/soft
ll /u01/app/oracle/soft/
chown -R oracle:oinstall /u01/app/oracle/soft
su - oracle
cd /u01/app/oracle/soft
unzip p13390677_112040_Linux-x86-64_1of7.zip
unzip p13390677_112040_Linux-x86-64_2of7.zip
cd database/
--若用xshell調用遠程界面 須要設置 DISPLAY variable
su -
xhost +
su - oracle
export DISPLAY=192.168.92.2:0
--2.1安裝數據庫軟件 靜默方式
/*
--配置響應文件respons file
[root@bspdev ~]# cd /etc
[root@bspdev etc]# vi oraInst.loc
inventory_loc=/u01/app/oracle
inst_group=oinstall
~
[root@bspdev etc]# chown oracle:oinstall oraInst.loc
[root@bspdev etc]# chmod 664 oraInst.loc
注意:這個步驟在GUI版本時候,是不強制的。
咱們首先須要安裝Oracle軟件,建立單獨的響應文件。
[oracle@bspdev response]$ cp enterprise.rsp creat.rsp
使用vi打開編輯,修改各類選項。模板響應文件設置的很好,每一個選項都提供了詳細的解釋和設置法則。咱們能夠根據本身的須要進行修改,例如:
#------------------------------------------------------------------------------
#Name : UNIX_GROUP_NAME
#Datatype : String
#Description: Unix group to be set for the inventory directory.
#Example : UNIX_GROUP_NAME = "install"
#------------------------------------------------------------------------------
UNIX_GROUP_NAME=ointall
在配置過程當中,同GUI安裝Oracle Software同樣,咱們是能夠選擇在安裝Software過程當中建立數據庫的。注意,通常咱們不推薦這樣作。咱們本篇中單獨有介紹dbca的響應文件使用部分。
以後,咱們就能夠啓動runInstaller程序進行安裝。
[oracle@bspdev database]$ ./runInstaller -silent -force -noconfig-responseFile /upload/database/response/creat.rsp
*/
./runInstaller -silent -debug -force \
FROM_LOCATION=/u01/app/oracle/soft/database/stage/products.xml \
oracle.install.option=INSTALL_DB_SWONLY \
UNIX_GROUP_NAME=oinstall \
INVENTORY_LOCATION=/u01/app/oracle/oraInventory \
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 \
ORACLE_BASE=/u01/app/oracle \
oracle.install.db.InstallEdition=EE \
oracle.install.db.isCustomInstall=false \
oracle.install.db.DBA_GROUP=dba \
oracle.install.db.OPER_GROUP=dba \
DECLINE_SECURITY_UPDATES=true
--安裝完成後以root用戶運行
/oracle/app/oraInventory/orainstRoot.sh
/oracle/app/oracle/product/12.1.0/db_1/root.sh
2.2 數據庫patch安裝
mv /u01/app/oracle/soft/p6880880_112000_Linux-x86-64.zip $ORACLE_HOME/
mv $ORACLE_HOME/OPatch $ORACLE_HOME/OPatch_BAK
cd $ORACLE_HOME
unzip p6880880_112000_Linux-x86-64.zip
cd /u01/app/oracle/soft
unzip p24006111_112040_Linux-x86-64.zip
cd 24006111
/u01/app/oracle/product/11.2.0/db_1/OPatch/opatch prereq CheckConflictAgainstOHWithDetail -ph ./
--打補丁
/u01/app/oracle/product/11.2.0/db_1/OPatch/opatch apply
--打補丁選項
Do you want to proceed? [y|n] 鍵入y
Email address/User Name: 回車鍵
Do you wish to remain uninformed of security issues ([Y]es, [N]o) [N]: 鍵入y
Is the local system ready for patching? [y|n] 鍵入y
--三. DBCA建庫
--若是dbca靜默建庫
dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbname ogg1 -sid ogg1 -sysPassword lhr -systemPassword lhr -responseFile NO_VALUE -datafileDestination /u01/app/oracle/oradata -redoLogFileSize 50 -recoveryAreaDestination /u01/app/oracle/flash_recovery_area -storageType FS -characterSet ZHS16GBK -nationalCharacterSet AL16UTF16 -sampleSchema true -memoryPercentage 30 -totalMemory 200 -databaseType OLTP -emConfiguration NONE -automaticMemoryManagement true
--注意相關數據庫參數設置
sga:10240M
pga:2048M
process:800
歸檔路徑:/u01/archive
字符集:AMERICAN_AMERICA.AL32UTF8
redo:四組每組100M
--四.手工配置監聽
vi $ORACLE_HOME/network/admin/listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = mysql-92.34)(PORT = 1521))
)
ADR_BASE_LISTENER = /u01/app/oracle
DIAG_ADR_ENABLED_LISTENER = OFF
--啓動監聽
lsnrctl start
--1. 若是用手工建庫
--創建audit_dump等全部目錄:
mkdir -p /u01/app/oracle/admin/orcl/adump
mkdir -p /u01/app/oracle/oradata/orcl
mkdir -p /u01/app/oracle/oradata/orcl/disk1
mkdir -p /u01/app/oracle/oradata/orcl/disk2
mkdir -p /u01/app/oracle/oradata/orcl/disk3
--須要建立/u01/app/oracle/fast_recovery_area
mkdir -p /u01/app/oracle/fast_recovery_area/orcl
--手工建後能夠執行dbca
vi /etc/oratab
orcl:/u01/app/oracle/product/11.2.0/db_1:Y
--創建password file:
orapwd file=/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl force=y password=oracle ignorecase=n
--編輯初始化參數文件: 當數據庫內存爲1G時 11G2040的表空間變爲undotbs1
--生產環境pfile參數 須要建立/u01/app/oracle/fast_recovery_area存放control02.ctl
--control02.ctl能夠設置在閃回區 當數據庫名用小寫且歸檔設置在閃回區時歸檔會存放在大寫的SID下
vi /u01/app/oracle/product/11.2.0/db_1/dbs/initorcl.ora
orcl.__db_cache_size=641728512
orcl.__java_pool_size=2097152
orcl.__large_pool_size=4194304
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=134217728
orcl.__sga_target=859832320
orcl.__shared_io_pool_size=67108864
orcl.__shared_pool_size=134217728
orcl.__streams_pool_size=4194304
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='NONE'
*.compatible='11.2.0.4.0'
*.control_file_record_keep_time=30
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/oradata/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.instance_name=orcl
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=10737418240
*.deferred_segment_creation=FALSE
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.log_archive_dest_1='LOCATION=/u01/app/oracle/archivelog'
*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=300
*.open_links=100
*.open_links_per_instance=100
*.pga_aggregate_target=134217728
*.sga_max_size=859832320
*.processes=800
*.remote_login_passwordfile='EXCLUSIVE'
*.sessions=885
*.sga_target=859832320
*.undo_retention=10800
*.undo_tablespace='UNDOTBS1'
--啓動實例到nomount狀態:字符集 AL32UTF8 國家字符集 AL16UTF16
sqlplus / as sysdba
startup nomount
--手工建庫過程當中不能指定sga和pga的大小
--數據庫名應該用大寫,不然影響:若啓用fast_recovery_dest時,歸檔目錄仍建立大寫的對應文件夾名
CREATE DATABASE orcl
MAXINSTANCES 8
MAXLOGHISTORY 1
MAXLOGFILES 40
MAXLOGMEMBERS 5
MAXDATAFILES 200
DATAFILE '/u01/app/oracle/oradata/orcl/system01.dbf' SIZE 300M AUTOEXTEND ON MAXSIZE 2G
EXTENT MANAGEMENT LOCAL
SYSAUX DATAFILE '/u01/app/oracle/oradata/orcl/sysaux01.dbf' SIZE 250M AUTOEXTEND ON MAXSIZE 2G
DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf' SIZE 100M AUTOEXTEND ON MAXSIZE 2G
UNDO TABLESPACE UNDOTBS1 DATAFILE '/u01/app/oracle/oradata/orcl/undotbs01.dbf' SIZE 100M AUTOEXTEND ON MAXSIZE 2G
CHARACTER SET AL32UTF8
NATIONAL CHARACTER SET AL16UTF16
LOGFILE
GROUP 1 ('/u01/app/oracle/oradata/orcl/disk1/redo01a.log',
'/u01/app/oracle/oradata/orcl/disk2/redo01b.log',
'/u01/app/oracle/oradata/orcl/disk3/redo01c.log') SIZE 100M,
GROUP 2 ('/u01/app/oracle/oradata/orcl/disk1/redo02a.log',
'/u01/app/oracle/oradata/orcl/disk2/redo02b.log',
'/u01/app/oracle/oradata/orcl/disk3/redo02c.log') SIZE 100M,
GROUP 3 ('/u01/app/oracle/oradata/orcl/disk1/redo03a.log',
'/u01/app/oracle/oradata/orcl/disk2/redo03b.log',
'/u01/app/oracle/oradata/orcl/disk3/redo03c.log') SIZE 100M
USER SYS IDENTIFIED BY oracle USER SYSTEM IDENTIFIED BY oracle;
/*
--若建庫出錯後刪除了數據庫的文件不能startup或create database
shutdown immediate
startup pfile=/u01/app/oracle/product/11.2.0/db_1/dbs/initorcl.ora
*/
--執行相關的腳本: catalog.sql catproc.sql 比較花時間 無執行順序區別 也能夠按照onlinhelp上面執行,也能夠不執行
--官方文檔執行catalog.sql catproc.sql pupbld.sql
conn / as sysdba
@/u01/app/oracle/product/11.2.0/db_1/rdbms/admin/catalog.sql;
@/u01/app/oracle/product/11.2.0/db_1/rdbms/admin/catblock.sql;
--忽略drop table的報錯
@/u01/app/oracle/product/11.2.0/db_1/rdbms/admin/catproc.sql;--cost long time
@/u01/app/oracle/product/11.2.0/db_1/rdbms/admin/catoctk.sql;
@/u01/app/oracle/product/11.2.0/db_1/rdbms/admin/owminst.plb;
connect system/oracle
@/u01/app/oracle/product/11.2.0/db_1/sqlplus/admin/pupbld.sql;
@/u01/app/oracle/product/11.2.0/db_1/sqlplus/admin/help/hlpbld.sql helpus.sql;
--重編譯失效對象:若報錯找不到recomp_serial 應該以sys用戶執行
conn / as sysdba
execute utl_recomp.recomp_serial();
create spfile from pfile;
shutdown immediate;
startup;
--切換日誌到歸檔目錄
alter system switch logfile;
/
--參考 從pfile啓動oracle
--startup pfile=/u01/app/oracle/product/11.2.0/db_1/dbs/initorcl.ora
--五.修改數據庫參數
--修改數據庫參數(其餘參數必須在dbca中已經改了sga,pga dbfile redo size processes archivelog)
su - oracle
mkdir /u01/app/oracle/archivelog
sqlplus / as sysdba
alter system set log_archive_dest_1='location=/u01/app/oracle/archivelog';
alter profile default limit password_life_time unlimited;
alter system set deferred_segment_creation=false;
alter system set open_links=100 scope=spfile;
alter system set open_links_per_instance=100 scope=spfile;
alter system set audit_trail=none scope=spfile;
alter system set control_file_record_keep_time=30 scope=spfile;
alter system set undo_retention=10800;
alter system set db_recovery_file_dest_size=10240m;
shutdown immediate;
startup;
/*
alter database datafile '/u01/app/oracle/oradata/orcl/undotbs01.dbf' resize 8G;
alter database datafile '/u01/app/oracle/oradata/orcl/undotbs01.dbf' autoextend off;
alter tablespace undotbs1 add datafile '/u01/app/oracle/oradata/orcl/undotbs02.dbf' size 8G autoextend off;
alter database tempfile '/u01/app/oracle/oradata/orcl/temp01.dbf' resize 8G;
alter database tempfile '/u01/app/oracle/oradata/orcl/temp01.dbf' autoextend off;
alter tablespace temp add tempfile '/u01/app/oracle/oradata/orcl/temp02.dbf' size 8G autoextend off;
*/
--若是是手工建庫 另外更改的參數
--六.部署數據
--6.1建立directory
--查詢源端目錄
select * from dba_directories;
--查詢源端字符集
select * from nls_database_parameters;
--查詢源端用戶對應的表空間
select username,default_tablespace from dba_users order by 1;
--導出源端數據
create tablespace sde datafile '/u01/app/oracle/oradata/orcl/sde.dbf' size 100m autoextend off extent management local segment space management auto;
expdp test/test.2017@orcl directory=dumpdir dumpfile=test20170527.dmp logfile=test20170527.log
mkdir –pv /u01/dumpdir
sqlplus / as sysdba
create directory dumpdir as '/u01/dumpdir';
grant read,write on directory dumpdir to sys;
6.2建立和源端用戶同名的表空間
create tablespace test datafile '/u01/app/oracle/oradata/orcl/test01.dbf' size 8G autoextend off;
alter tablespace test add datafile '/u01/app/oracle/oradata/orcl/test02.dbf' size 8G autoextend off;
6.3 導入數據 可能版本不一樣須要先建立用戶(logfile日誌中會有錯誤信息提示)
impdp \'sys/Sendinfo2017@orcl as sysdba\' directory=dumpdir dumpfile=hht20170527.dmp logfile=hht20170527.log
--若expdp不成功,則先建立用戶
--目標端建立用戶並配置權限
sqlplus / as sysdba
create user test identified by test default tablespace sde;
grant connect to test;
grant create indextype to test;
grant create job to test;
grant create materialized view to test;
grant create procedure to test;
grant create public synonym to test;
grant create sequence to test;
grant create session to test;
grant create table to test;
grant create trigger to test;
grant create type to test;
grant create view to test;
--授予私有database link權限
grant create database link to test;
grant unlimited tablespace to test;
--權限檢查
conn gglcxticketbd/gglcxticketbd@orcl
--查看當前用戶的角色和權限
select * from user_role_privs;
select * from session_privs;
--查看當前用戶的系統權限和表級權限
select * from user_sys_privs;
select * from user_tab_privs;
--查詢警告信息
SHOW ERRORS [{ FUNCTION | PROCEDURE | PACKAGE |
PACKAGE BODY | TRIGGER | VIEW
| TYPE | TYPE BODY | DIMENSION
| JAVA SOURCE | JAVA CLASS } [schema.]name]
show error procedure test."NEXT_VAL"
show error package test.PDTYPES
select text from dba_source t where t.name='NEXT_VAL';
select text from dba_source t where t.name='PDTYPES';
--查詢用戶的默認表空間是否正確
select username,default_tablespace from dba_users order by 1;
--查詢數據
select t.supply_name from test.order_info t where rownum<=10;
--七.修改默認統計信息時間
--查詢默認job時間,修改完可查詢一下
set line 500;
set pagesize 100;
col window_name format A50;
col REPEAT_INTERVAL format A50;
col duration format A50;
select t1.window_name,t1.repeat_interval,t1.duration from dba_scheduler_windows t1,dba_scheduler_wingroup_members t2
where t1.window_name=t2.window_name and t2.window_group_name in ('MAINTENANCE_WINDOW_GROUP','BSLN_MAINTAIN_STATS_SCHED');
BEGIN
DBMS_SCHEDULER.DISABLE(
name=>'"SYS"."SATURDAY_WINDOW"',
force=>TRUE);
END;
/
--1200->240
BEGIN
DBMS_SCHEDULER.SET_ATTRIBUTE(
name=>'"SYS"."SATURDAY_WINDOW"',
attribute=>'DURATION',
value=>numtodsinterval(240, 'minute'));
END;
/
BEGIN
DBMS_SCHEDULER.SET_ATTRIBUTE(
name=>'"SYS"."SATURDAY_WINDOW"',
attribute=>'REPEAT_INTERVAL',
value=>'freq=daily;byday=SAT;byhour=22;byminute=0; bysecond=0');
END;
/
BEGIN
DBMS_SCHEDULER.ENABLE(
name=>'"SYS"."SATURDAY_WINDOW"');
END;
/
BEGIN
DBMS_SCHEDULER.DISABLE(
name=>'"SYS"."SUNDAY_WINDOW"',
force=>TRUE);
END;
/
--1200->240
BEGIN
DBMS_SCHEDULER.SET_ATTRIBUTE(
name=>'"SYS"."SUNDAY_WINDOW"',
attribute=>'DURATION',
value=>numtodsinterval(240, 'minute'));
END;
/
BEGIN
DBMS_SCHEDULER.SET_ATTRIBUTE(
name=>'"SYS"."SUNDAY_WINDOW"',
attribute=>'REPEAT_INTERVAL',
value=>'freq=daily;byday=SUN;byhour=22;byminute=0; bysecond=0');
END;
/
BEGIN
DBMS_SCHEDULER.ENABLE(
name=>'"SYS"."SUNDAY_WINDOW"');
END;
/
--八.部署腳本
--備庫部署腳本時須要更改對應的ORACLE_SID,備庫直讀模式不支持expd
su - root
service ntpd stop
chkconfig ntpd off
crontab -e
*/5 * * * * /usr/sbin/ntpdate 192.168.92.33>/tmp/ntp.log 2>&1
--如下不用添加
服務器一: 1.cn.pool.ntp.org
服務器二: 2.asia.pool.ntp.org
服務器三: 3.asia.pool.ntp.org
su - oracle
crontab -e
00 00 * * * /bin/bash /u01/scripts/by_listener.sh >/u01/scripts/by_listener.log 2>&1
30 03 * * * /bin/bash /u01/scripts/rman_backup.sh >/u01/scripts/rman_backup.log 2>&1
00 01 * * * /bin/bash /u01/scripts/expdpuser.sh >/u01/scripts/expdpuser.log 2>&1
00 01 * * * /bin/bash /u01/scripts/del_arc.sh >/u01/scripts/del_arc.log 2>&1
chmod 755 del_arc.sh
chmod 755 by_listener.sh
chmod 755 expdpuser.sh
chmod 755 rman_backup.sh
--建立相關目錄
mkdir –pv /u01/scripts
mkdir –pv /u01/backupsets
-------------------------------------------------------------------------------------------------------
--1. rman_backup.sh
##################################################################
## V_2011-2-18 ##
##################################################################
#!/bin/ksh
export LANG=en_US
BACKUP_DATE=`date +%d`
RMAN_LOG_FILE=/u01/scripts/rmanbackup.out
TODAY=`date`
USER=`id|cut -d "(" -f2|cut -d ")" -f1`
echo "-----------------$TODAY-------------------">$RMAN_LOG_FILE
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_HOME
RMAN=$ORACLE_HOME/bin/rman
export RMAN
ORACLE_SID=orcl
export ORACLE_SID
ORACLE_USER=oracle
export ORACLE_USER
echo "ORACLE_SID: $ORACLE_SID">>$RMAN_LOG_FILE
echo "ORACLE_HOME:$ORACLE_HOME">>$RMAN_LOG_FILE
echo "ORACLE_USER:$ORACLE_USER">>$RMAN_LOG_FILE
echo "==========================================">>$RMAN_LOG_FILE
echo "BACKUP DATABASE BEGIN......">>$RMAN_LOG_FILE
echo " ">>$RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE
WEEK_DAILY=`date +%a`
case "$WEEK_DAILY" in
"Mon")
BAK_LEVEL=0
;;
"Tue")
BAK_LEVEL=0
;;
"Wed")
BAK_LEVEL=0
;;
"Thu")
BAK_LEVEL=0
;;
"Fri")
BAK_LEVEL=0
;;
"Sat")
BAK_LEVEL=0
;;
"Sun")
BAK_LEVEL=0
;;
"*")
BAK_LEVEL=error
esac
export BAK_LEVEL=$BAK_LEVEL
echo "Today is : $WEEK_DAILY incremental level= $BAK_LEVEL">>$RMAN_LOG_FILE
RUN_STR="
BAK_LEVEL=$BAK_LEVEL
export BAK_LEVEL
ORACLE_HOME=$ORACLE_HOME
export ORACLE_HOME
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
$RMAN nocatalog TARGET / msglog $RMAN_LOG_FILE append <<EOF
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup as compressed backupset incremental level= $BAK_LEVEL skip inaccessible filesperset 6 Database format='/u01/backupsets/orcl_lev"$BAK_LEVEL"_%U_%T' tag='orcl_lev"$BAK_LEVEL"' ;
sql 'alter system archive log current';
backup archivelog all tag='arc_bak' format='/u01/backupsets/arch_%U_%T' skip inaccessible filesperset 6 not backed up 1 times delete input;
backup current controlfile tag='bak_ctlfile' format='/u01/backupsets/ctl_file_%U_%T';
backup spfile tag='spfile' format='/u01/backupsets/orcl_spfile_%U_%T';
release channel c2;
release channel c1;
}
allocate channel for maintenance device type disk;
crosscheck backup;
delete noprompt expired backup;
report obsolete;
delete noprompt obsolete;
list backup summary;
release channel;
EOF
"
# Initiate the command string
if [ "$CUSER" = "root" ]
then
echo "Root Command String: $RUN_STR" >> $RMAN_LOG_FILE
su - $ORACLE_USER -c "$RUN_STR" >> $RMAN_LOG_FILE
RSTAT=$?
else
echo "User Command String: $RUN_STR" >> $RMAN_LOG_FILE
/bin/sh -c "$RUN_STR" >> $RMAN_LOG_FILE
RSTAT=$?
fi
# ---------------------------------------------------------------------------
# Log the completion of this script.
# ---------------------------------------------------------------------------
if [ "$RSTAT" = "0" ]
then
LOGMSG="ended successfully"
else
LOGMSG="ended in error"
fi
echo >> $RMAN_LOG_FILE
echo Script $0 >> $RMAN_LOG_FILE
echo ==== $LOGMSG on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
#/u01/scripts/upload_rman.sh
exit $RSTAT
---------------------------------------------------------------
--2. expdpuser.sh by zhuyj保留最近2天的dmp備份 啓用壓縮和並行 全schema
##################################################################
## V_2016 ##
##################################################################
#刪除2天前的文件
#find /root/test/ -name *.dmp -mtime +2 -exec rm -rf {} \;
#find /root/test/ -name *.log -mtime +2 -exec rm -rf {} \;
#!/bin/bash
BAK_DIR=/u01/dumpdir
DUMPDIR=dumpdir
FTP_HOST=x.x.x.x
FTP_USER=db_bak
FTP_PASS="xxxxxx"
FILE_NAME=orcl`date +%Y%m%d`.dmp
LOG_NAME=orcl`date +%Y%m%d`.log
SCHEMAS=orcl
REV_DATE=+7
source /home/oracle/.bash_profile
#begin start
expdp \"/ as sysdba\" directory="$DUMPDIR" dumpfile="$FILE_NAME" logfile="$LOG_NAME" full=y compression=all parallel=4
#ftp upload
#cd $BAK_DIR
#echo "Begin start Ftp Trans"
#ftp -n -i $FTP_HOST <<EOF
#user $FTP_USER $FTP_PASS
#passive
#prompt
#prompt
#mput $FILE_NAME
#quit
#EOF
#echo $?
#delete expire file
if [ $? -eq 0 ];then
find ${BAK_DIR:=/tmp} -type f -name "*.dmp" -mtime $REV_DATE |xargs rm -rvf
find ${BAK_DIR:=/tmp} -type f -name "*.log" -mtime $REV_DATE |xargs rm -rvf
echo "Backup Success"
else
echo "Backup fail please check log!!!"
exit 1
fi
---------------------------------------------------------------
--3. by_listener.sh
####################################################
## Date:2016-01-01 ##
####################################################
#!/bin/bash
source /home/oracle/.bash_profile
listenlog=$ORACLE_HOME/network/log
oldlistener=listenerold`date +%Y%m%d`.log
rev_date=15
lsnrctl set log_status off
cd $listenlog
mv listener.log $oldlistener
lsnrctl set log_status on
find ${listenlog:=/tmp} -type f -name "listenerold*.log" -mtime +$rev_date |xargs rm -rvf
---------------------------------------------------------------
--3. by_listener.sh
--先檢查歸檔日誌,把物理刪除的信息從控制文件刪除,而後執行物理刪除
vi /u01/scripts/del_arc.sh
#! /bin/bash
source ~/.bash_profile
#記錄歸檔刪除的日誌
exec >> /u01/scripts/del_arch`date +%F-%H`.log
$ORACLE_HOME/bin/rman target / <<EOF
#檢查歸檔
crosscheck archivelog all;
#刪除無效歸檔
delete noprompt expired archivelog all;
#刪除3天前的歸檔
delete noprompt archivelog until time 'sysdate-3';
#刪除全部的歸檔
#delete noprompt archivelog all;
exit;
EOF
---------------------------------------------------------------
--5. upload_rman.sh
##################################################################
## DESCRIPTION: upload_rman.sh ##
## Author:Netdata ##
## Author:2016-05-23 ##
##################################################################
#!/bin/bash
BACKUP_DIR=/oradata/backupsets
ORACLE_SID=orcl
REV_DATE=+7
FTP_HOST=10.46.20.134
FTP_USER=db_bak
FTP_PASS="t<pO86ugfpuzInhvpzwt"
FILE_NAME="$ORACLE_SID"_rman_`date +%Y%m%d`.tar.bz2
TAR_FILE=*`date +%Y%m%d`
#tar rman backupsets
cd $BACKUP_DIR
tar -jcvf $FILE_NAME $TAR_FILE
if [ $? -eq 0 ];then
#ftp upload
cd $BACKUP_DIR
echo "Begin start Ftp Trans"
ftp -n -i $FTP_HOST <<EOF
user $FTP_USER $FTP_PASS
passive
prompt
prompt
mput $FILE_NAME
quit
EOF
else
echo "Upload File please check log!!!"
exit 1
fi
#delete rev_date_file
if [ $? -eq 0 ];then
find ${BACKUP_DIR:=/tmp} -type f -name "*.tar.bz2" -mtime $REV_DATE |xargs rm -rvf
echo "Upload Success"
else
echo "Upload fail please check log!!!"
exit 1
fi
-----------------------------------------------------------------------------------
如下操做用root用戶登陸
一、編輯 /etc/oratab,把全部的 instance 的重啓動標誌設置成 'Y',如:
orcl:/u01/app/oracle/product/11.2.0/db_1:Y
二、作一個啓動腳本 /etc/init.d/oracle ,以下所示:
#!/bin/sh
# chkconfig: 345 99 10
# description: script for the Oracle Instance, Listener
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
ORA_HOME=/u01/app/oracle/product/11.2.0/db_1
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi
case "$1" in
'start')
# Start the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
;;
'stop')
# Stop the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
;;
'restart')
$0 stop
$0 start
;;
esac
在腳本中如下兩行必須存在
# chkconfig: 345 99 10
# description: script for the Oracle Instance, Listener
------------------備註說明---------------------------------
# chkconfig: 345 99 10
指出3,4,5級別啓動這個服務,99是在相應的/etc/rc.d/rcN.d(N爲前面指定的
級別,這裏是345)目錄下生成的連接文件的序號(啓動優先級別)S99oracle,
10爲在除前面指出的級別對應的/etc/rc.d/rcN.d(N爲除345以外的級別)目錄生成的
連接文件的序號(服務中止的優先級別)K10oracle
三、賦予執行權限
chmod 751 /etc/init.d/oracle
四、添加服務
chkconfig --add oracle
chkconfig --list oracle
--chkconfig --del oracle
五、啓動服務
添加服務服務後,不會當即啓動服務,若是須要當即啓動服務,須要執行
service oracle start #啓動服務
service oracle stop #中止服務
service oracle restart #重啓服務
-----------------------------------------------------------------------------------
--生產環境pfile配置 mem=8G 定製內存 sga:pga=4:1
/*
[oracle@HHTDB01-238-31 dbs]$ more initorcl.ora |more
orcl.__db_cache_size=5133828096
orcl.__java_pool_size=16777216
orcl.__large_pool_size=33554432
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=1073741824
orcl.__sga_target=6878658560
orcl.__shared_io_pool_size=536870912
orcl.__shared_pool_size=1073741824
orcl.__streams_pool_size=33554432
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='NONE'
*.compatible='11.2.0.4.0'
*.control_file_record_keep_time=30
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/f
ast_recovery_area/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.instance_name=orcl
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=10737418240
*.deferred_segment_creation=FALSE
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.log_archive_dest_1='LOCATION=/u01/app/oracle/archivelog'
*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=300
*.open_links=100
*.open_links_per_instance=100
*.pga_aggregate_target=1073741824
*.processes=800
*.remote_login_passwordfile='EXCLUSIVE'
*.sessions=885
*.sga_target=6871318528
*.undo_retention=10800
*.undo_tablespace='UNDOTBS1'
--若須要更改參數su - oraclemkdir /u01/app/oracle/fast_recovery_areashutdown immediatestartup pfile=/u01/app/oracle/product/11.2.0/db_1/dbs/initorcl.oracreate spfile from pfile;shutdown immediatestartup*/