Oracle DBA · Lesson 5B
Working in the Right Container
Your session is always in one container. Confirm it with SHOW CON_NAME before you create users or objects — then switch if you are in the wrong place.
Watch on YouTube
Oracle DBA Lesson 5B — Working in the Right Container
AI Ops Pro
Session context is the habit
Lesson 5A named the pieces: root, seed, and user PDBs. This lesson is the daily practice — before you create a local user, a tablespace, or an object, you name the container you are in.
A session lives in one container at a time. Guessing from the connection string is not enough. Confirm it.
Confirm with SHOW CON_NAME
SHOW CON_NAME prints the current container for this session. Make it the first check after connect, and again after any switch.
SHOW CON_NAME
Returns the container this session is in right now — for example CDB$ROOT, SALES, or HR.
Wrong container, wrong object
Suppose SHOW CON_NAME returns SALES, and the next ticket is “create an HR local user.” SALES is the wrong place. Creating the user there either fails the intent or leaves an account the HR app cannot use as a local PDB user.
Move to the required target first. Do the work second.
Switch with ALTER SESSION SET CONTAINER
From a privileged session that can see other containers, switch in place:
ALTER SESSION SET CONTAINER = hr;
SHOW CON_NAME;
Moves this session into the HR PDB, then confirms the name. Replace hr with your PDB name.
Or connect to the PDB service
Another clean path: connect with a service that lands you in the PDB you need. Then confirm again with SHOW CON_NAME. Either route is fine — the rule is the same: prove the container before DDL.
-- After connect to the HR service:
SHOW CON_NAME;
-- Expect: HR (or your PDB name)
Root vs PDB work
Some tasks belong in CDB$ROOT (startup, common users, CDB-wide views). Application local users and app tablespaces belong in the application PDB. Match the task to the container — then confirm you are actually there.
Gotchas
- Do not create an HR local user while your session is still in SALES (or root).
- A connection identifier is a hint, not proof — always
SHOW CON_NAME. - After
ALTER SESSION SET CONTAINER, confirm again before DDL. - Put the container name in the ticket or change note so the next person is not guessing.
Quick quiz
Choose one answer per question, then submit. You’ll see the correct answer and a short why.
No comments:
Post a Comment