Centos4.4+oracle10.1
oracle 安装:
vi /etc/sysctl.conf
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default=262144
net.core.rmem_max=262144
net.core.wmem_default=262144
net.core.wmem_max=262144
vi /etc/security/limits.conf
* soft nproc 2047
* hard nproc 16384
* soft nofile 1024
* hard nofile 65536
vi /etc/pam.d/login
session required /lib/security/pam_limits.so
安装软件包:
yum -y install compat-libstdc++-33.i386
yum -y install compat-gcc-32.i386
yum -y install compat-gcc-32-c++.i386
yum -y install libaio.i386
usermod -g oinstall -G dba oracle
or:
useradd -g oinstall -G dba oracle
mkdir -p /u01/app/oracle
mkdir /u01/oradata
chown -R oracle:oinstall /u01/app/oracle /u01/oradata
chmod -R 775 /u01/app/oracle /u01/oradata
vi .bash_profile (oracle用户)
# Oracle Settings
ORACLE_SID=dgdemo;
ORACLE_BASE=/u01;
ORACLE_HOME=/u01/app/oracle;
export ORACLE_SID ORACLE_BASE ORACLE_HOME
PATH=/usr/sbin:$PATH;
export PATH
PATH=$ORACLE_HOME/bin:$PATH;
export PATH
vi /etc/profile
add:
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
create database:
dbca
配制网络连接:
netcn:
lsnode1
dgdemo
dgdemo
lsnode2
data guard install:
参考:http://download.oracle.com/docs/cd/B14117_01/server.101/b10823/create_ps.htm#63563
3.1.1 Enable Forced Logging
SQL> ALTER DATABASE FORCE LOGGING;
建立参数文件:
create pfile='/u01/app/oracle/dbs/initdgdemo.ora' from spfile ;
修改:
add:
DB_UNIQUE_NAME=uqn_node1
LOG_ARCHIVE_CONFIG='DG_CONFIG=(uqn_node1,uqn_node2)'
LOG_ARCHIVE_DEST_2='SERVICE=lsnode2 VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=uqn_node2'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
FAL_SERVER=lsnode2
FAL_CLIENT=lsnode1
STANDBY_FILE_MANAGEMENT=AUTO
3.1.4 Enable Archiving(if noarchive )
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP MOUNT;
SQL> ALTER DATABASE ARCHIVELOG;
SQL> ALTER DATABASE OPEN;
3.2.2 Create a Control File for the Standby Database
SQL> shutdown immediate
SQL> STARTUP MOUNT;
SQL> ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/u01/oradata/wilson.ctl';
SQL> alter database open;
创建新的spfile;
create spfile='/u01/app/oracle/dbs/spfiledgdemo.ora' from pfile='/u01/app/oracle/dbs/initdgdemo.ora'
用应新spfile:
SQL> shutdown immediate;
SQL> startup open;
SQL> show parameter spfile;
3.2.4 Copy Files from the Primary System to the Standby System
COPY文件:
cd /u01/app/oracle/dbs
cp initdgdemo.ora /u01/oradata/ (复制参数件到/data/oradata目录下 ,方便以后的CP)
cp orapwdgdemo /u01/oradata/ (复制密码件到/data/oradata目录下)
cd /u01
scp -r admin oradata node2:/u01
3.2.3 Prepare an Initialization Parameter File for the Standby Database (以下是在node2 操作)
cd /u01/oradata/dgdemo/
替换控制文件:
rm control0*
cp ../wilson.ctl control01.ctl
cp ../wilson.ctl control02.ctl
cp ../wilson.ctl control03.ctl
替换参数文件和口令件:(其实在node2中就没有这两个文件)
cd /u01/app/oracle/dbs
cp /u01/oradata/initdgdemo.ora .
cp /u01/oradata/orapwdgdemo .
修改参数文件initdgdemo.ora :(就是把1与2对调)
DB_UNIQUE_NAME=uqn_node2
LOG_ARCHIVE_DEST_2='SERVICE=lsnode1 VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=uqn_node1'
FAL_SERVER=lsnode1
FAL_CLIENT=lsnode2
Step 3 Configure listeners for the primary and standby databases(两台机子)
% lsnrctl stop
% lsnrctl start
3.2.6 Start the Physical Standby Database
先启动主库:
SQL> startup open;
在node2上测试:
sqlplus system/oracle@lsnode1
Step 1 Start the physical standby database
SQL> startup mount;
Step 3 Start Redo Apply.(根据主库的redo来更新从库的数据文件)
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
--------------------------------------END-----------------------------------------------------------------------------------------------
继:
8.2.2 Opening a Physical Standby Database for Read-Only Access
To open a standby database for read-only access when it is currently performing Redo Apply or real-time apply:
Cancel Redo Apply or real-time apply:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
Open the database for read-only access:
SQL> ALTER DATABASE OPEN;
在Read-Only 状态不能收到主库的数据,主与从库不同步,从新让从库同步主库用以下方法:
To change the standby database from being open for read-only access to performing Redo Apply:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
测试部分:
Step 1 Identify the existing archived redo log files (node2):
SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
Step 2 Force a log switch to archive the current online redo log file.(node1)
SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
测试:在主库上建一个表,看是否在从库上会自动建同样的表:
node1:
SQL> create table comtv(id integer, name char(10));
SQL> insert into comtv values(101,'zxw');
SQL> insert into comtv values(102,'lyq');
SQL> commit;
SQL> ALTER SYSTEM SWITCH LOGFILE;
node2:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL> alter database open;
SQL> select * from comtv;
重新同步:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;