Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

DBA - Miscellaneous

Back


Run script in SQL*PLUS

select 1 from dual;         # any sql
save file_name              # the path will be thw pwd where login sqlplus.

save_script


@file_name

run_script


cd target_path
sqlplus sys/pwd@tns_name file_name


# example
cd ~/Desktop
sqlplus sys@orcl @test.sql

run_script02


Oracle Data Dictionary

Data Dictionary Objects User
CDB_ in the CDB and PDBs DBA account*
DBA_ in a container or PDB DBA account*
ALL_ accessible by the current user any user
USER_ owned by current user any user

Lab: Query Data Dictionary

show con_name
#CON_NAME
#------------------------------
#CDB$ROOT

select con_id,name,open_mode from v$pdbs;
#2	PDB$SEED	READ ONLY
#3	ORCLPDB	READ WRITE

--make sure that the pluggable database is open
alter pluggable database ORCLPDB open;
--this will show all the tables in the CDB and PDBS
select owner,table_name,con_id from cdb_tables
order by 1,2;

--count of tables per container
SELECT con_id, COUNT(table_name)
FROM cdb_tables
GROUP BY con_id;

show con_name
-- root

-- return the current container
SELECT  COUNT(table_name)
FROM DBA_tables;

# change session to PDB
ALTER session set container=ORCLPDB;

show con_name
#CON_NAME
#------------------------------
#ORCLPDB

# return the PDB container
SELECT  COUNT(table_name)
FROM DBA_tables;

alter session set container=cdb$root;

show con_name


Dynamic Performance Views (v$ views)


Lab: V$ view

show con_name

alter pluggable database orclpdb open;

alter session set container=orclpdb;

show con_name


select
oracle_username
os_user_name,
locked_mode,
object_name,
object_type
from
v$locked_object a,dba_objects b
where
a.object_id = b.object_id
select * from hr.employees;

# update a row
update hr.employees
set salary=salary+1
where employee_id=100;

select
oracle_username
os_user_name,
locked_mode,
object_name,
object_type
from
v$locked_object a,dba_objects b
where
a.object_id = b.object_id;

lab_v_view01


rollback;

select
oracle_username
os_user_name,
locked_mode,
object_name,
object_type
from
v$locked_object a,dba_objects b
where
a.object_id = b.object_id

Architecure

multi-tennant


Lab: Query the information about the database

select name,cdb,con_id ,OPEN_MODE
from V$DATABASE;

show parameter db_name;

lab_database

lab_database


select banner from v$version;

lab_database


select *
from v$instance;

show parameter instance_name;

lab_database

lab_database


Lab: V$CONTAINER


show con_name;

select con_id,name,open_mode from V$CONTAINERS;

lab_container


alter session set container=orclpdb;

select con_id,name,open_mode from V$CONTAINERS;

lab_container


Lab: CDB_PDBS


show con_name

select pdb_id,pdb_name, status
from cdb_PDBS;

lab_pdbs


alter session set container=orclpdb;

show con_name;

select pdb_id,pdb_name, status
from cdb_PDBS;

lab_pdbs


TOP