docker使用jaspeen/oracle-11g创建数据库之后,手动添加实例

jaspeen/oracle-11g账户密码

root/install
oracle/install

我这里新建的实例叫做TECHDB,可以批量修改为自己的实例名

  • docker进入到容器内,su - oracle 切换到oracle用户
  • 切换实例

export ORACLE_SID=TECHDB ## TECHDB为实例名+

  • 创建文件夹

mkdir -p $ORACLE_BASE/admin/TECHDB/adump
mkdir -p $ORACLE_BASE/admin/TECHDB/pfile
mkdir -p $ORACLE_BASE/oradata/TECHDB
mkdir -p $ORACLE_BASE/fast_recovery_area/TECHDB

  • 编写ora文件

vi $ORACLE_HOME/dbs/initTECHDB.ora

内容如下

##所有路径请用绝对路径
db_name='TECHDB'
compatible=11.2.0
sga_target=4096m
control_files='/opt/oracle/app/oradata/TECHDB/control01.ctl','/opt/oracle/app/fast_recovery_area/TECHDB/control02.ctl'
audit_file_dest='/opt/oracle/app/admin/TECHDB/adump'
diagnostic_dest='/opt/oracle/app'
db_recovery_file_dest_size=4g
db_recovery_file_dest='/opt/oracle/app/fast_recovery_area'
undo_tablespace='UNDOTBS1'

  • 生成密码文件

orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=tiger

  • 创建数据库

cd $ORACLE_BASE/oradata/TECHDB/

##注意最后不要缺少分号(折腾了一天);

vi createdb.sql 

create database TECHDB
MAXINSTANCES 1
MAXLOGHISTORY 1
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXDATAFILES 100
DATAFILE
'/opt/oracle/app/oradata/TECHDB/system01.dbf' size 100m reuse autoextend on next 1m maxsize unlimited extent management local
sysaux datafile
'/opt/oracle/app/oradata/TECHDB/sysaux01.dbf' size 100m reuse autoextend on next 1m maxsize unlimited
default temporary tablespace TEMP tempfile
'/opt/oracle/app/oradata/TECHDB/temp01.dbf' size 20m reuse autoextend on next 640k maxsize unlimited
undo tablespace UNDOTBS1 datafile
'/opt/oracle/app/oradata/TECHDB/undo01.dbf' size 20m reuse autoextend on next 5M maxsize unlimited
logfile
GROUP 1 ('/opt/oracle/app/oradata/TECHDB/redo1.dbf') size 10m,
GROUP 2 ('/opt/oracle/app/oradata/TECHDB/redo2.dbf') size 10m,
GROUP 3 ('/opt/oracle/app/oradata/TECHDB/redo3.dbf') size 10m
CHARACTER SET AL32UTF8
NATIONAL CHARACTER SET AL16UTF16; 

  • 执行建库、数据字典脚本

linux> sqlplus / as sysdba  ##登录

sql> startup nomount   注意nomount   不可以去掉
sql> @$ORACLE_BASE/oradata/TECHDB/createdb.sql;
sql> @?/rdbms/admin/catalog.sql;  
sql> @?/rdbms/admin/catproc.sql;
sql> @?/rdbms/admin/catexp.sql;

  • 创建用户及表空间

##创建表空间
create tablespace TECHDB datafile '/opt/oracle/app/oradata/TECHDB/TECHDB01.dbf' size 500M autoextend on;
##创建用户
create user EVAL identified by EVAL default tablespace TECHDB quota unlimited on TECHDB;
##授权

grant connect,resource,dba to EVAL ;

  • 启动监听

lsnrctl start listener

启动之后就可以用plsql连接;(ps,不要忘记防火墙开放端口)

  • docker重启容器后实例启停

export ORACLE_SID=TECHDB
sqlplus / as sysdba
sql> startup     ##启动
sql> shutdown    ##停止

  • 如果报错了,查看日志命令

查看前200行日志

tail -200 $ORACLE_BASE/diag/rdbms/techdb/TECHDB/trace/alert_TECHDB.log

你可能感兴趣的:(docker,docker,oracle)