创建oracle_11g数据库脚本

阅读更多

#找到spfile$sid.ora文件,一般文件地址在
$ORACLE_BASE/product/11.2.0/dbhome_1/dbs/

#spfile文件复制重命名一份($SID需与环境变量中保持一致)
$strings spfile$SID.ora > init$SID.ora

orcl.__db_cache_size=331350016
orcl.__java_pool_size=4194304
orcl.__large_pool_size=4194304
orcl.__oracle_base='/opt/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=343932928
orcl.__sga_target=507510784
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=159383552
orcl.__streams_pool_size=0
*.audit_file_dest='/opt/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/opt/oracle/oradata/orcl/control01.ctl','/opt/oracle/flash_reco
very_area/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain='localdomain'
*.db_name='orcl'
*.db_recovery_file_dest='/opt/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=4039114752
*.diagnostic_dest='/opt/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.memory_target=849346560
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'

 在命令模式下替换,以以上文件为例替换方式为($SID自行替换)
:%s/orcl/$SID/g

 

#无用户进入数据库
[ora10@localhost dbs]$sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jul 19 20:52:59 2012
Copyright (c) 1982, 2005, Oracle.  All rights reserved.

#连接数据库
SQL>conn  /as sysdba
Connected to an idle instance.

#通过pfile文件生成spfile文件
SQL>create spfile from pfile;
File created.

#启动数据库
SQL>startup nomount;
ORACLE instance started.
Total System Global Area  205520896 bytes
Fixed Size                  1218532 bytes
Variable Size              75499548 bytes
Database Buffers          125829120 bytes
Redo Buffers                2973696 bytes

#调用创建数据库命令文件(在执行crdb01.sql文件之前需先清除掉脚本中需要创建的文件)
SQL>@/opt/oracle/product/11.2.0/dbhome_1/dbs/crdb01.sql;
Database created.    ----经过等待后数据库创建成功!

#创建用户文件
SQL>create tablespace mytbs datafile '/opt/oracle/oradata/orcl/orclmytbs01.dbf' SIZE  100M extent management local;
Tablespace created.

#创建数据字典
SQL>@/opt/oracle/product/11.2.0/dbhome_1/rdbms/admin/catalog.sql;
SQL>@/opt/oracle/product/11.2.0/dbhome_1/rdbms/admin/catproc.sql;
SQL>@/opt/oracle/product/11.2.0/dbhome_1/sqlplus/admin/pupbld.sql;
 这三个sql文件是必须执行。也有可先项catblock.sql;catoctk.sql;owminst.plb;catclust.sql;

 

#创建数据库登陆用户
create user user_name identified by user_pwd default tablespace tablespace_name;

#授权
grant connect,resource,dba,sysdba to user_name;

#删除用户
drop user user_name cascade;

 

相关问题

#客户端连接oracle比较慢的情况
1.检查listener.ora和tnsnames.ora文件中的host指向的IP是否一致
2.检查/etc/resolv.conf文件中的nameserver指向的IP是否和步骤一中的一致


#启动监听lsnrctl start,提示
sqlplus: error while loading shared libraries: /opt/oracle/product/11.2.0/dbhome_1/lib/libclntsh.so.11.1: cannot restore segment prot after reloc: Permission denied

这个问题是由于SELINUX的设置太过严格导致的引起的。 解决的办法是在root用户下,修改/etc/selinux/config 文件:
编辑/etc/sysconfig/selinux配置文件, 把SELINUX=enforcing 改为 SELINUX=disabled。
保存后重启系统

 

#Io 异常: The Network Adapter could not establish the connection
hosts中缺少localhost.localdomain导致监听启动时间超长
修改文件内容/etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=localhost.localdomain

查看命令more /etc/hosts
$ifconfig_ip localhost.localdomain localhost

修改文件内容/opt/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
(ADDRESS = (PROTOCOL = TCP)(HOST = $ifconfig_ip)(PORT = 1521)

TRACE_LEVEL_LISTENER = 16
TRACE_FILE_LISTENER= LISTENER_TRC
TRACE_DIRECTORY_LISTENER=/tmp

修改文件内容/opt/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
(ADDRESS = (PROTOCOL = TCP)(HOST = $ifconfig_ip)(PORT = 1521)

关闭防火墙操作
Redhat使用了SELinux来增强安全,关闭的办法为:
1. 永久有效
修改 /etc/selinux/config 文件中的 SELINUX="" 为 disabled ,然后重启。
2. 即时生效
setenforce 0

关闭防火墙的方法为:
1. 永久性生效
开启:chkconfig iptables on
关闭:chkconfig iptables off
2. 即时生效,重启后失效
开启:service iptables start
关闭:service iptables stop

#web应用连接oracle数据库时,经常在查询数据时发生Listener refused the connection with the following error: ORA-12519, TNS:no appropriate service handler found The Connection descriptor used by the client was: 127.0.0.1:1521:ORCL
这种错误,网上查了很多,都说是ip地址改变之后的问题,要把tnsnames.ora中的实例配置中改为计算机名,我试过之后问题还是不能解决,今天终于找到问题所在了,是数据库连接数量的问题,12519错误为监听不能提供服务,通常为数据库进程达到上限导致。
可以先执行下
select count(*) from v$process;
看下现在系统有多少连接数,然后再查询
select value from v$parameter where name = 'processes';
看下oracle设置中设置了多少连接数,一般一个应用都会使用20个,所以如果你开了几个应用的话(web、pl/sql、……)就会出这个问题了,这时只需要执行下
alter system set processes = 300 scope = spfile;
就可以了,当然300可以根据实际情况设置

 

crdb01.sql文件内容:

spool dbcreate.log;
CREATE DATABASE "orcl"
        MAXDATAFILES  500
        MAXINSTANCES  8
        MAXLOGFILES   32
        CHARACTER SET "UTF8"
        NATIONAL  CHARACTER SET AL16UTF16
        ARCHIVELOG
        DATAFILE
          '/opt/oracle/oradata/orcl/system01.dbf'  SIZE  300M
        SYSAUX DATAFILE
          '/opt/oracle/oradata/orcl/sysaux01.dbf'  SIZE  120M
        EXTENT MANAGEMENT LOCAL
        DEFAULT TEMPORARY TABLESPACE temp TEMPFILE '/opt/oracle/oradata/orcl/tempts01.dbf' SIZE 100M  EXTENT MANAGEMENT LOCAL
        UNDO TABLESPACE "UNDOTBS1"
        DATAFILE '/opt/oracle/oradata/orcl/undotbs01.dbf' SIZE 200M
        LOGFILE
     GROUP 1(
        '/opt/oracle/oradata/orcl/redo01a.rdo',
        '/opt/oracle/oradata/orcl/redo01b.rdo'
        ) SIZE  100M,
     GROUP 2(
        '/opt/oracle/oradata/orcl/redo02a.rdo',
        '/opt/oracle/oradata/orcl/redo02b.rdo'
        ) SIZE  100M,
     GROUP 3(
        '/opt/oracle/oradata/orcl/redo03a.rdo',
        '/opt/oracle/oradata/orcl/redo03b.rdo'
        ) SIZE 100M;
spool off

 

你可能感兴趣的:(oracle)