Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

12C Common SQL statements of Multi-tenancy about CDB and PDB

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

View current container and current user

Show con_name user

Select sys_context ('userenv',' con_name'), sys_context (' userenv','session_user') from dual

View all PDB

Show pdbs

Select con_id, dbid, guid, name, open_mode from v$pdbs

Start PDB:

Alter pluggable database all open;-enable all PDB

Alter pluggable database PDBNAME open;-enable PDB with the name PDBNAME

Alter session set container=PDBNAME;-- switches the PDB named PDBNAME to open it.

Startup

Turn off PDB:

Alter pluggable database all close immediate;-disable all PDB. Default normal is if you don't add immediate.

Alter pluggable database PDBNAME close immediate;-- disables the PDB named PDBNAME. The default normal is if immediate is not added.

Alter session set container=PDBNAME;-- switches the PDB named PDBNAME to close it.

Shutdown immediate

Create a new PDB: (if db_create_file_dest already exists)

Create pluggable database test admin user admin identified by admin

Alter pluggable database test open;-Open test

Create a new PDB based on the seed template (if there is no db_create_file_dest, you must add file_name_convert)

Create pluggable database pdb1 admin user pdb1 identified by pdb1 file_name_convert= ('/ u01qqapqqoracleUniqoradataOnOnOnOnOnOnActionoradataOnOnU01ActionoradataCoreadataActionoradata ('/ u01ActionActionoradataloradata')

Alter pluggable database pdb1 open;-Open test

Clone PDB

Create pluggable database test2 from test;-- test must be open before it can be used as a clone source

Alter pluggable database test2 open;-- and then open the pdb

Delete PDB

Alter pluggable database test2 close immediate;-cannot be deleted until it is closed

Drop pluggable database test2 including datafiles;-Delete PDB test2 and delete the data file from disk at the same time. You must add including datafiles. If you don't add including datafiles or keep datafiles, you will get an error ORA-65179: cannot keep datafiles for a pluggable database that is not unplugged

Unplug unplugs a database (must be into to a specific xml format file)

The data file of the pdb cannot be found by executing cdb_data_files after SQL > alter pluggable database pocp1 close immediate;--, but the data file of the pdb is still there, and the pdb can be seen by show pdbs.

The data file of the pdb cannot be found by executing cdb_data_files after SQL > alter pluggable database pocp1 unplug into'/ home/oracle/pocp1.xml';--, but the data file of the pdb is still there, and the pdb can be seen by show pdbs.

SQL > drop pluggable database pocp1;-after unplug, the drop database without including datafiles is the default keep datafiles;. The data file of the pdb is still there. If the show pdbs cannot see that the pdb; is added with including datafiles, the data file of the pdb is deleted.

Drop pluggable database pocp1=drop pluggable database pocp1 keep datafiles

Plug in the database (if the above unplug operation does not perform the third step drop operation, the following statement will report an error ORA-65012: Pluggable database pocp1 already exists. If the above unplug operation implements step 3, adding including datafiles will cause an error ORA-19505: failed to identify file,ORA-27037: unable to obtain file status)

SQL > create pluggable database pocp1 using'/ home/oracle/pocp1.xml' nocopy tempfile reuse

SQL > alter pluggable database pocp1 open

You can change the PDB name when you plug in a database. / home/oracle/pocp1.xml is created by pocp1, and the xml file shows POCP1, but you can use the xml to create a PDB with another name, such as TDB101.

SQL > create pluggable database TDB101 using'/ home/oracle/pocp1.xml' nocopy tempfile reuse

Query data files of CDB$ROOT

Select file_name from cdb_data_files where con_id=1

Query the data file of a PDB

Select file_name from cdb_data_files a cdbstores pdbs b where a.con_id=b.con_id and b.pdbkeeper nameplates

Query the PDB corresponding to a data file

Select pdb_name from cdb_data_files a cdbstores pdbs b where a.con_id=b.con_id and a.file_name like'% XX%'

Query data files of PDB$SEED

Alter session set "_ exclude_seed_cdb_view" = FALSE

Select file_name from cdb_data_files where con_id=2

Each PDB executes the following statement to see only the data files under its own container before CDB can see the data files of all containers

Select file_name,file_id,CON_ID from cdb_data_files

Each container can only see the data file under its own container by executing the following statement, and CDB can only see its own data file under this container.

Select file_name,file_id,CON_ID from cdb_data_files

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report