Database 12C creates PDB tablespace user and authorization (DEMO)

Create PDB tablespaces and users (do not create generic users)

In Oracle12c, the concept of pluggable database, namely PDB, is added, allowing one database container (CDB) to host multiple pluggable databases (PDB). The full name of CDB is ContainerDatabase, which is translated into database container in Chinese. The full name of PDB is PluggableDatabase, which is a pluggable database. Prior to ORACLE 12C, instances and databases had a one-to-one or many-to-one relationship (RAC): that is, an instance could only be associated with one database, and the database could be loaded by multiple instances. An instance and a database cannot have a one-to-many relationship. When entering ORACLE 12C, the instance and the database can have a one-to-many relationship. The following is the official document on the relationship between CDB and PDB.




 

Common user and local user are related to the pluggable database (PDB), a new feature of oracle 12c. The user created in the PDB is the local user. As can be seen from the above figure, common user must start with uppercase or lowercase c##. The following is the relationship diagram of the official document User.



 

step:

1. Installation, the basic default, the default installation will install a PDB (orclpdb) by default,

2. Log in after installation. After logging in, the default is CDB, and the table space for CDB is created. ( I have tried to create a table space under PDB, and then the user cannot specify the table space, which means that CDB and PDB must have the same Table space can be specified only if the name of the table is empty, otherwise TEMP and USERS are used by default );

 

 

>sqlplus sys/password as sysdba

SQL> show con_name;

SQL> select con_id,dbid,name,open_mode from v$pdbs;
 --View current PDB containers

--Create CDB temporary table space (if you use the default temporary table space TEMP, you can ignore this step)
SQL> create temporary tablespace wmstest_temp
tempfile 'C:\app\Administrator\virtual\oradata\wmstest_temp.dbf'
size 128m
autoextend on
next 128m maxsize 20480m
extent management local;
 

--Create CDB data tablespace (if you use the default tablespace USERS, you can ignore this step)
SQL>create tablespace wmstest_data
logging
datafile 'C:\app\Administrator\virtual\oradata\wmstest_data.dbf'
size 128m
autoextend on
next 128m maxsize 20480m
extent management local;

 

 

 

3. Create the PDB that needs to be used. I do not use the default PDB. Create a PDB (wmstestpdb) through the Datebase Configuration Assistant. After the creation, you can use the em interface to create tablespace users and authorization.



 

You can save a lot of trouble through the em interface



 

 

4. If you do not go through the em interface and use the command line, you need to perform the following steps

 

--Switch to the specified library, the PDB just created is (WMSTESTPDB);
SQL>  alter session set container=WMSTESTPDB;

-- Check whether it is under PDB after switching, the previous step will be displayed, this step is purely boring
SQL> show con_name;
SQL> select con_id,dbid,name,open_mode from v$pdbs;

--If the newly created PDB has been opened by default, but you can execute the startup command to confirm, anyway, if it has been opened, it will not be opened repeatedly
SQL> startup;


--Create a temporary tablespace (with the same name as CDB, different tempfile, files), in fact, there are more optional parameters in the EM interface
SQL> create temporary tablespace wmstest_temp
tempfile 'C:\app\Administrator\virtual\oradata\wmstestpdb_temp.dbf'
size 128m
autoextend on
next 128m maxsize 20480m
extent management local;

--Create a data tablespace (with the same name as CDB, different tempfile, files can be)
SQL> create tablespace wmstest_data
logging
datafile 'C:\app\Administrator\virtual\oradata\wmstestpdb_data.dbf'
size 128m
autoextend on
next 128m maxsize 20480m
extent management local;

-- 1 Now it is under PDB, create a user and make a tablespace
-- WMSTEST_DATA , WMSTEST_TEMP must exist in both CDB and PDB, otherwise an error will be reported
SQL> create user wmstest identified by wms123 default tablespace WMSTEST_DATA temporary tablespace WMSTEST_TEMP;

-- 2 Use the default tablespace (USERS, TEMP exist by default in the CDB, and the newly created PDB also exists by default)
SQL> create user wmstest identified by wms123 default tablespace USERS temporary tablespace TEMP;

--Grant permissions to users, grant all permissions
SQL>  grant all to wmstest;

 

 

other sql

 

--other
--delete users
SQL>  drop user wmstest cascade;

-- delete tablespace
SQL> DROP TABLESPACE wmstest_temp INCLUDING CONTENTS AND  DATAFILES;
SQL> DROP TABLESPACE wmstest_data INCLUDING CONTENTS AND  DATAFILES;

-- view tablespace
SQL> select tablespace_name, file_id, file_name,
   round(bytes/(1024*1024),0) total_space
  from dba_data_files
  order by tablespace_name;

-- view users
SQL> select * from dba_users;

 

 

5. Use PLSQL to connect

configure

tnsnames.ora

 

 

# wmstest/wms123
wmstestpdb =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = IP  )(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = WMSTESTPDB)
    )
  )

 

 

So you can connect and operate the database.

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326291011&siteId=291194637