sql >> Database >  >> RDS >> Oracle

Basisbeheer van Oracle 12c Multitenant

Controleer of de database CDB of niet-CDB is


SQL> select cdb from v$database;

CDB
---
YES

Verbinding maken met container


$ export ORACLE_SID=pcdb01
$ sqlplus / as sysdba

SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT

SQL> show con_id

CON_ID
------------------------------
1

SQL> show pdbs;

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PRD_PDB_CON READ WRITE NO
4 PRD_PDB_TEN READ WRITE NO

Navigeer door PDB's


SQL> alter session set container=PDB$SEED;

Session altered.

SQL> alter session set container=PRD_PDB_CON;
Session altered.

SQL>

Informatie over PDB's


SQL> COLUMN PDB_NAME FORMAT A15
SQL> COLUMN PDB_NAME FORMAT A15
SQL> SELECT PDB_ID, PDB_NAME, STATUS FROM DBA_PDBS ORDER BY PDB_ID;

PDB_ID PDB_NAME STATUS
---------- --------------- ---------
2 PDB$SEED NORMAL
3 PRD_PDB_CON NORMAL
4 PRD_PDB_TEN NORMAL

Parameter controleren/wijzigen


SQL> select * from v$system_parameter;
SQL> select * from PDB_SPFILE$;
SQL> alter system set parameter_name=value;
SQL> alter system set parameter_name=value CONTAINER=CURRENT;

Opstarten en afsluiten van PDB

Enkele typische waarden:

OPSTARTEN [NOMOUNT | MONTEREN | BEPERKEN | UPGRADEN | KRACHT | ALLEEN LEZEN]

UITSCHAKELEN [ONMIDDELLIJKE | ABORT]

$ export ORACLE_SID=pcdb01
$ sqlplus / as sysdba

SQL> shutdown immediate;

Stop inplugbare database


SQL> alter pluggable database PRD_PDB_CON close [immediate];
SQL> alter pluggable database ALL EXCEPT PRD_PDB_CON close [immediate];
SQL> alter pluggable database ALL close;
SQL> alter pluggable database PRD_PDB_CON close [immediate] [instances=all];

Of:


SQL> alter SESSION SET CONTAINER = PRD_PDB_CON;
SQL> shutdown immediate;

Start pluggable database

OPSTARTKRACHT

OPSTARTEN OPENEN LEZEN SCHRIJVEN [BEPERK]

OPSTARTEN OPENEN ALLEEN LEZEN [BEPERKEN]

OPSTARTUPGRADE

SHUTDOWN [IMMEDIATE]


SQL> alter pluggable database PDB01 open;
SQL> alter pluggable database ALL EXCEPT PRD_PDB_CON open;
SQL> alter pluggable database ALL open;
SQL> alter pluggable database PDB01 open [instances=all];

Of:


SQL> alter SESSION SET CONTAINER = PRD_PDB_CON;
SQL> startup;

SQL> alter PLUGGABLE DATABASE <pdb-name-clause> OPEN READ WRITE [RESTRICTED] [FORCE];
SQL> alter PLUGGABLE DATABASE <pdb-name-clause> OPEN READ ONLY [RESTRICTED][FORCE];
SQL> alter PLUGGABLE DATABASE <pdb-name-clause> OPEN UPGRADE [RESTRICTED];
SQL> alter PLUGGABLE DATABASE <pdb-name-clause> CLOSE [IMMEDIATE];

Behoud PDB-opstartstatus (12.1.0.2 en verder)


SQL> alter PLUGGABLE DATABASE pdb2 OPEN;
SQL> alter PLUGGABLE DATABASE pdb2 SAVE STATE;

De weergave DBA_PDB_SAVED_STATES geeft informatie weer over de opgeslagen status van containers.



SQL> COLUMN con_name FORMAT A20
SQL> COLUMN instance_name FORMAT A20

SQL> SELECT con_name, instance_name, state FROM dba_pdb_saved_states;

CON_NAME INSTANCE_NAME STATE
-------------------- -------------------- --------------
PRD_PDB_CON pcdb01 OPEN

Grootte van inplugbare database


SQL> COLUMN NAME FORMAT A20
SQL> SELECT DBID, NAME, CON_ID, CON_UID, TOTAL_SIZE FROM V$CONTAINERS ORDER BY CON_ID;

DBID NAME CON_IDCON_UID TOTAL_SIZE
---------- ------------------------------ ---------- ---------- ----------
2732069181 CDB$ROOT 1 1 0
3552543733 PDB$SEED 2 3552543733 775946240
4008367944 PRD_PDB_CON 3 4008367944 1203765248
2667104724 PRD_PDB_TEN 4 2667104724 1182793728

Opstarttijd van inplugbare database


SQL> set linesize 180
SQL> col name for a30
SQL> col open_time for a33
SQL> select con_id,name,dbid,open_mode,open_time from v$containers;

CON_ID NAME DBID OPEN_MODE OPEN_TIME
---------- ---------------- -------------- ---------- ---------- ---------------------------------
1 CDB$ROOT 456650806 READ WRITE 17-MAR-18 11.59.36.176 PM -03:00
2 PDB$SEED 2688102972 READ ONLY 17-MAR-18 11.59.36.182 PM -03:00
3 PDB_PN1O0101 1079206163 READ WRITE 18-MAR-18 12.00.00.589 AM -03:00
4 PDB_BATCHWEB 2340495643 READ WRITE 18-MAR-18 12.00.03.485 AM -03:00

4 rows selected.

Uptime van inplugbare database


SQL> set linesize 180
SQL> col name for a30
SQL> col open_time for a28

SQL> select name,floor(sysdate-cast(open_time as date))||'Days '||floor(((sysdate-cast(open_time as date))-floor(sysdate-cast(open_time as date)))*24)||'hours '||round(((sysdate-cast(open_time as date)-floor(sysdate-cast(open_time as date) )*24)-floor((sysdate-cast(open_time as date)-floor(sysdate-cast(open_time as date))*24)))*60)||'minutes' "Database Uptime"
from v$containers;

NAME Database Uptime
--------------- ---------------------------
CDB$ROOT 1331Days 11hours 28minutes
PDB$SEED 1331Days 11hours 28minutes
PDB_PN1O0101 1331Days 11hours 28minutes
PDB_BATCHWEB 1331Days 11hours 28minutes

4 rows selected.

Naam van diensten


SQL> COLUMN NAME FORMAT A30
SQL> SELECT NAME,CON_ID,PDB FROM V$SERVICES ORDER BY CON_ID;

NAME CON_ID PDB
------------------------------ ---------- ------------------------------
pcdb01XDB 1 CDB$ROOT
SYS$BACKGROUND 1 CDB$ROOT
SYS$USERS 1 CDB$ROOT
pcdb01 1 CDB$ROOT
prd_pdb_con 3 PRD_PDB_CON
prd_pdb_ten 4 PRD_PDB_TEN

6 rows selected.


Gemeenschappelijke gebruikers maken met toegang tot alle pdbs

SQL> CREATE USER c##user1 IDENTIFIED BY password1 CONTAINER=ALL;

User created.

SQL> GRANT CREATE SESSION TO c##user1 CONTAINER=ALL;

Grant succeeded.

Gemeenschappelijke gebruikers maken zonder toegang tot pdbs

SQL> CREATE USER c##user2 IDENTIFIED BY password1;

User created.

SQL> GRANT CREATE SESSION TO c##user2;

Grant succeeded.

Maak een lokale gebruiker aan met alleen toegang tot pdb


SQL> CREATE USER user3 IDENTIFIED BY password3 CONTAINER=CURRENT;

User created.

SQL> GRANT CREATE SESSION TO user3 CONTAINER=CURRENT;

Grant succeeded.

Gemeenschappelijke rol maken


SQL> CONN / AS SYSDBA
SQL> CREATE ROLE c##role1;

Role created.

SQL> GRANT CREATE SESSION TO c##role1;

Grant succeeded.

Rol toekennen aan een gewone gebruiker


SQL> GRANT c##role1 TO c##user1 CONTAINER=ALL;

Grant succeeded.

Rol toekennen aan een gewone gebruiker aan een lokale gebruiker


SQL> alter SESSION SET CONTAINER = PRD_PDB_CON;

Session altered.

SQL> GRANT c##role1 TO user2;

Grant succeeded.

Lokale rollen


SQL> CONN / AS SYSDBA

SQL> alter SESSION SET CONTAINER = PRD_PDB_CON;

Session altered.

SQL> CREATE ROLE role1;

Role created.

SQL> GRANT CREATE SESSION TO role1;

Grant succeeded.

PDB's maken


SQL> create pluggable database HMLPDB admin user admin identified by PassDw1 roles = (DBA);
SQL> create pluggable database DSVPDB admin user admin identified by Manager1roles = (DBA) storage (MAXSIZE 1G) 
FILE_NAME_CONVERT=('/u01/app/oracle/oradata/pcdb01/pcdb01_pdbseed_','/u01/app/oracle/oradata/dsvpdb/dsvpdb_');
SQL> create pluggable database DSVPDB1 from DSVPDB file_name_convert=('/DSVPDB/','/DSVPDB1/');

Exclusief PDB's

SQL> alter pluggable database DSVPDB1 close [immediate] [instances=all];
SQL> drop pluggable database DSVPDB1 including datafiles;

PDB's loskoppelen

$ sqlplus / as sysdba

SQL> alter pluggable database PRD_PDB_CON close;
SQL> alter pluggable database PRD_PDB_CON unplug into '/tmp/prd_pdb_con.xml';

PDB's aansluiten

$ sqlplus / as sysdba

SQL> create pluggable database PRD_PDB_CON using '/tmp/prd_pdb_con.xml' FILE_NAME_CONVERT=('/oradata/cdb1/prd_pdb_con', '/oradata/cdb2/prd_pdb_con');
SQL> alter pluggable database PRD_PDB_CON open;

Services configureren op Oracle RAC met CDB's

$ srvctl add service -db CDB01 -service new_service -pdb PRD_PDB_CON
$ srvctl modify service -db CDB01 -service new_service -pdb PRD_PDB_CON
$ srvctl remove service -db CDB01 -service new_service


BEGIN
DBMS_SERVICE.CREATE_SERVICE(
service_name => 'new_service',
network_name => 'new_service.com');
END;
/

BEGIN
DBMS_SERVICE.DELETE_SERVICE(
service_name => 'new_service');
END;
/

Met rootcontainer hebben we cdb_tablespaces en cdb_data_files toont de tablespace en databestanden van alle containers in de CDB.

Wanneer verbonden met een PDB, tonen cdb_tablespaces en cdb_data_files dezelfde informatie als dba_tablespaces, dba_data_files voor de PDB.


SQL> alter session set container=CDB$ROOT;

Session altered.

SQL> select tablespace_name, con_id from cdb_tablespaces order by con_id;

TABLESPACE_NAME CON_ID
------------------------------ --------
SYSTEM 1
SYSAUX 1
UNDOTBS2 1
TEMP 1
USERS 1
UNDOTBS1 1
SYSTEM 3
SYSAUX 3
TBS_GEN_01 3
TEMP 3
TBS_CON_IDX_01 3
TBS_CON_DT_01 3
USERS 3
SYSTEM 4
SYSAUX 4
TBS_GEN_01 4
USERS 4
TEMP 4

18 rows selected.


SQL> select tablespace_name from dba_tablespaces;

TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
UNDOTBS2

6 rows selected.

Hoe te controleren op de functie Lokaal ongedaan maken in 12.2

In Oracle Database 12c Release 1 deelden alle containers in een instantie dezelfde tabelruimte voor ongedaan maken.

In Oracle 12c Release 2 kan elke container in een instance zijn eigen undo tablespace gebruiken.


SQL> shutdown immediate;
SQL> startup upgrade;

SQL> alter database local undo on;

SQL> shutdown immediate;
SQL> startup;


SQL> col property_name format a30
SQL> col property_value format a30

SQL> select property_name, property_value from database_properties where property_name = 'LOCAL_UNDO_ENABLED';

PROPERTY_NAME PROPERTY_VALUE
---------------- -------------- 
LOCAL_UNDO_ENABLED TRUE

 

Referenties

https://docs.oracle.com


  1. SQL NIET IN werkt niet

  2. Hoe ik een installatieprogramma voor de website kan maken. PHP mysql

  3. Databases migreren naar Azure SQL Database

  4. Oracle:is de kolomvolgorde van belang in een index?