手动建库跟能让你深入理解ORACLE架构
设置好数据库安装用户的环境变量
#add for install oracle
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=yang
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ADR_BASE=$ORACLE_BASE/diag
export LD_LIBRARY_PATH=/usr/lib:$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH
创建参数文件
内容如下,放到$ORACLE_HOME/dbs目录下,命名为
init$sid.ora 即 inityang.ora
db_name=yang
db_block_size=8192
memory_target=300M
memory_max_target=300M
processes=200
control_files=(/u01/dbfile/yang/control01.ctl,/u02/dbfile/yang/control02.ctl)
job_queue_processes=10
open_cursors=500
fast_start_mttr_target=500
undo_management=AUTO
undo_tablespace=UNDOTBS1
remote_login_passwordfile=EXCLUSIVE
创建数据目录并赋权
$ mkdir -p /u01/dbfile/yang
$ mkdir -p /u02/dbfile/yang
$ mkdir -p /u01/oraredo/yang
$ mkdir -p /u02/oraredo/yang
# chown -R oracle:dba /u01
# chown -R oracle:dba /u02
启动实例
[oracle@bogon dbs]$ sqlplus "/ as sysdba"
SQL*Plus: Release 11.2.0.4.0 Production on Tue Feb 2 20:53:22 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 313159680 bytes
Fixed Size 2252824 bytes
Variable Size 209719272 bytes
Database Buffers 96468992 bytes
Redo Buffers 4718592 bytes
SQL>
创建数据库
将下面的sql粘贴到打开的实例中执行。
CREATE DATABASE yang
MAXLOGFILES 16
MAXLOGMEMBERS 4
MAXDATAFILES 1024
MAXINSTANCES 1
MAXLOGHISTORY 680
CHARACTER SET AL32UTF8
DATAFILE
'/u01/dbfile/yang/system01.dbf'
SIZE 500M REUSE
EXTENT MANAGEMENT LOCAL
UNDO TABLESPACE undotbs1 DATAFILE
'/u01/dbfile/yang/undotbs01.dbf'
SIZE 800M
SYSAUX DATAFILE
'/u01/dbfile/yang/sysaux01.dbf'
SIZE 500M
DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE
'/u01/dbfile/yang/temp01.dbf'
SIZE 500M
DEFAULT TABLESPACE USERS DATAFILE
'/u01/dbfile/yang/users01.dbf'
SIZE 20M
LOGFILE GROUP 1
('/u01/oraredo/yang/redo01a.rdo',
'/u02/oraredo/yang/redo01b.rdo') SIZE 50M,
GROUP 2
('/u01/oraredo/yang/redo02a.rdo',
'/u02/oraredo/yang/redo02b.rdo') SIZE 50M,
GROUP 3
('/u01/oraredo/yang/redo03a.rdo',
'/u02/oraredo/yang/redo03b.rdo') SIZE 50M
USER sys IDENTIFIED BY syspass00
USER system IDENTIFIED BY systempass00;
创建数据库目录
前面的sql语句只是搭了个空架子,就好比一个公司要运营,只是画了块地儿,把楼盖或者车间盖起来了,创造价值的工具和人还没到位呢。真正实用的东西在这个地方用sys用户执行下面的语句,来创建一系列的字典,这个地方一言难尽,可以参考下盖国强的《深入解析Oracle:数据库的初始化》。
SQL> spool create_dd.lis
SQL> @?/rdbms/admin/catalog.sql
SQL> @?/rdbms/admin/catproc.sql
SQL> alter database open;
SQL> connect system/systempass00
SQL> @?/sqlplus/admin/pupbld
SQL> spool off
创建listener文件,启动监听器
cd $ORACLE_HOME/network/
vi listener.ora
#内容如下:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.163.134)(PORT = 1521))
)
)
)
#如果监听器是静态注册需要加入下面的这段,一般都是动态注册所有实例,所以不需要加入
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = yang)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = yang)
)
)
#启动监听
[oracle@bogon network]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 03-FEB-2016 10:59:40
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Starting /u01/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Log messages written to /u01/app/oracle/diag/tnslsnr/bogon/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bogon)(PORT=1521)))
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 03-FEB-2016 10:59:40
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Log File /u01/app/oracle/diag/tnslsnr/bogon/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bogon)(PORT=1521)))
The listener supports no services
The command completed successfully
#等上一分钟,执行下面的命令,看下服务
[oracle@bogon network]$ lsnrctl services
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 03-FEB-2016 11:00:34
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "yang" has 1 instance(s).
Instance "yang", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
The command completed successfully
#看下监听器的状态,是成功创建的
[oracle@bogon network]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 03-FEB-2016 11:01:41
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 03-FEB-2016 10:59:40
Uptime 0 days 0 hr. 2 min. 1 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Log File /u01/app/oracle/diag/tnslsnr/bogon/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bogon)(PORT=1521)))
Services Summary...
Service "yang" has 1 instance(s).
Instance "yang", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@bogon network]$
#连接测试下:sqlplus system/systempass00@'localhost:1521/yang'
[oracle@bogon network]$ sqlplus system/systempass00@'localhost:1521/yang'
SQL*Plus: Release 11.2.0.4.0 Production on Wed Feb 3 11:07:13 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
#创建tnsnames.ora
yang =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA = (SERVICE_NAME = yang))
)
创建密码文件
$ cd $ORACLE_HOME/dbs
#$ orapwd file=orapw<ORACLE_SID> password=<sys password>
orapwd file=orapwyang password=syspass00