oracle 12c 常用命令

1、查看有多少pdb数据库:
SQL> show pdbs;
2、切换到指定容器数据库:
SQL> alter session set container=ORCLPDB;
3、启动容器数据库:
SQL> alter pluggable database ORCLPDB open;
4、关闭容器数据库:
SQL> alter pluggable database ORCLPDB close immediate;
5、查看数据库名字:
SQL> show con_name;
6、数据库的创建及删除:
--创建或克隆前要指定文件映射的位置(需要CBD下sysdba权限)
alter system set db_create_file_dest='/u01/app/oracle/oradata/orcl/orcl2';

--创建一个新的PDB:(需要CBD下sysdba权限)
create pluggable database test admin user admin identified by admin;

--不指定直接创建库;
create pluggable database salespdb admin user admin identified by admin file_name_convert=('/u01/app/oracle/oradata/orcl12c/pdbseed/','/u01/app/oracle/oradata/orcl12c/salespdb/');
--克隆PDB(需要CBD下sysdba权限)
create pluggable database orcl2 from orcl1; --test_pdb必须是打开的,才可以被打开

--删除PDB(需要CBD下sysdba权限)

alter pluggable database orcl2 close; --关闭之后才能删除
drop pluggable database orcl2 including datafiles; --删除PDB orcl2

--设置CDB启动PDB自动启动(在这里使用的是触发器)
CREATE OR REPLACE TRIGGER open_pdbs
AFTER STARTUP ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN';
END open_pdbs;
7、PDB创建用户(链接到pdb数据库后创建用户):
create user hanfuyou identified by hanfuyou default tablespace users temporary tablespace temp;
grant connect,resource,unlimited tablespace to hanfuyou;

拔插与删除 PDB

1、拔出SALESPDB #必须连接到CDB$ROOT
#首先关闭SALESPDB
SQL> alter pluggable database SALESPDB close immediate;
SQL> alter pluggable database SALESPDB unplug into '/home/oracle/salespdb.xml';
#XML文件中包含了每个数据文件的位置,以及初始化参数等信息。
2、drop PDB
#关闭并且拔出PDB后才可以进行删除,删除时可以一起删除数据文件:
#同样需要连接到CDB$ROOT容器,执行下列语句:
SQL> drop pluggable database SALESPDB keep datafiles;
3、plug an unplugged PDB
#本机插入PDB
SQL> create pluggable database SALESPDB02 using '/home/oracle/salespdb.xml' nocopy tempfile reuse;
SQL> alter pluggable database SALESPDB02 open;

4、本机不同存放位置插入PDB
mkdir /u01/app/oracle/oradata/orcl12c/salespdb01/;

SQL> create pluggable database SALESPDB01 using '/home/oracle/salespdb.xml'
SOURCE_FILE_NAME_CONVERT=('/u01/app/oracle/oradata/orcl12c/salespdb/','/u01/app/salespdb/')
MOVE FILE_NAME_CONVERT=('/u01/app/salespdb/','/u01/app/oracle/oradata/orcl12c/salespdb01/')
PATH_PREFIX='/u01/app/oracle/oradata/orcl12c/salespdb01/' STORAGE (MAXSIZE 2G MAX_SHARED_TEMP_SIZE 100M);
这里xml文件中指示数据文件在/u01/app/oracle/oradata/orcl12c/salespdb/中,
而实际上数据文件在/u01/app/salespdb/中,
且最终我们要将数据文件放在/u01/app/oracle/oradata/orcl12c/salespdb01/中。

乱码问题解决方法:
export NLS_LANG=american_america.AL32UTF8(把语句添加环境变量)
权限授权:
https://www.cnblogs.com/g253187360/p/8110442.html
https://www.cnblogs.com/SummerinShire/p/6539607.html
https://blog.csdn.net/Darker2016/article/details/84147293

你可能感兴趣的:(oracle 12c 常用命令)