控制Oracle数据库启停的脚本
脚本必须放在主节点和从节点 /etc/sdata/scripts/
#Name stop.sh
#!/bin/sh
su - oracle <<EON
sqlplus /nolog <<EOF
conn / as sysdba
shutdown immediate
quit
EOF
lsnrctl stop
exit
EON
#Name start.sh
#!/bin/bash
su - oracle <<EON
lsnrctl start
sqlplus /nolog <<EOF
conn / as sysdba
startup
quit
EOF
exit
EON
*******************************
[oracle@oracle12c ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Thu Jun 11 09:37:46 2020
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
/u01/app/oracle/oradata/orcl/pdbseed/system01.dbf
/u01/app/oracle/oradata/orcl/pdbseed/sysaux01.dbf
/u01/app/oracle/oradata/orcl/users01.dbf
/u01/app/oracle/oradata/orcl/pdbseed/undotbs01.dbf
/u01/app/oracle/oradata/orcl/pdb01/system01.dbf
/u01/app/oracle/oradata/orcl/pdb01/sysaux01.dbf
/u01/app/oracle/oradata/orcl/pdb01/undotbs01.dbf
/u01/oradata/orcl/TESTDB1.dbf
11 rows selected.
SQL> select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/control01.ctl
/u01/app/oracle/oradata/orcl/control02.ctl
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/redo03.log
/u01/app/oracle/oradata/orcl/redo02.log
/u01/app/oracle/oradata/orcl/redo01.log
*****************************************************************************************************
登录Oracle界面
sqlplus / as sysdba
alter pluggable database pdb01 open;
/* PDB Pluggable Database是12c新特性,CDB中的PDB,默认启动CDB时不会启动所有、PDB,需要手动启动alter pluggable database ALL OPEN;
show pdbs;
alter session set container = pdb01; /*在PDB间切换*/
show con_name;
创建用户
create user wong identified by 888888;
赋权
grant dba to wong;
建表
alter session set container = pdb01; /*在PDB间切换*/
conn wong/888888@pdb01 /*不能遗漏 表示在这个用户下创建表、插入数据*/
create table wong (id number primary key,name char(10),time date) COMPRESS FOR OLTP;
插入数据
begin
for i in 1..100
loop
insert into wong values (i,'wong',sysdate);
commit;
end loop;
end;
/
删除数据
delete from wong where id<30
/
commit
/
更新数据
update wong set name='li' where id<10
/
commit
/
新建其他表
create table student(
id number not null,
name varchar2(10) not null,
create_time timestamp not null
);
create sequence student_id_seq;
insert into student values (student_id_seq.nextval,'xiaojm',systimestamp);
insert into student values (student_id_seq.nextval,'lijw',systimestamp);
insert into student values (student_id_seq.nextval,'tangy',systimestamp);
insert into student values (student_id_seq.nextval,'tangy',systimestamp);
insert into student values (student_id_seq.nextval,'A1111',systimestamp);
commit; /*不要漏*/
Oracle查询数据的命令
select * from student;
备注:
Oracle 12C引入了CDB与PDB的新特性,在ORACLE 12C数据库引入的多租用户环境(Multitenant Environment)中,
允许一个数据库容器(CDB)承载多个可插拔数据库(PDB)。CDB全称为Container Database,中文翻译为数据库容器,
PDB全称为Pluggable Database,即可插拔数据库。在ORACLE 12C之前,实例与数据库是一对一或多对一关系(RAC):
即一个实例只能与一个数据库相关联, 数据库可以被多个实例所加载。而实例与数据库不可能是一对多的关系。
当进入ORACLE 12C后, 实例与数据库可以是一对多的关系。下面是官方文档关于CDB与PDB的关系图。
其实如果对SQL SERVER比较熟悉的话,这种CDB与PDB和SQL SERVER的单实例多数据库架构类似。
像PDB$SEED可以看成是master、msdb等系统数据库,PDBS可以看成用户创建的数据库。
而可插拔的概念与SQL SERVER中的用户数据库的分离、附加其实相似。