Oracle Database Administration
Oracle Database Administration
• Oracle Database: Think of this as the actual library building and all the books (data) inside
it. It's made up of physical files stored on your computer's disks.
o Data Files: These are like the bookshelves holding the actual information – your
tables, indexes, and all user data.
o Control Files: These are like the library's master catalog. They know where all the
data files are, the database's name, and critical information needed to start and run
the database. They are super important; lose them, and you're in big trouble.
o Online Redo Log Files: Imagine a security log that records every single change
made in the library (every book borrowed, returned, or page written). This is crucial
for recovering the database if something goes wrong (like a power outage).
• Oracle Instance: This is like the library staff (librarians, security guards, etc.) and the space
they work in (desks, computers). It's the set of memory structures and background
processes that actually manage and access the database files.
o One instance typically manages one database.
o SGA (System Global Area): A large, shared memory area used by all the "library
staff" (Oracle processes). It's like a central workroom.
▪ Database Buffer Cache: A part of the SGA where frequently accessed data
from data files is kept temporarily. This speeds things up because reading
from memory is much faster than reading from disk.
▪ Shared Pool: Another part of the SGA that stores recently used SQL
commands and program code, so Oracle doesn't have to re-process them
every time. Also holds data dictionary information (metadata about database
objects).
▪ Redo Log Buffer: A small area in the SGA that temporarily holds those
"change records" before they are written out to the Online Redo Log Files.
o PGA (Program Global Area): Each "librarian" (server process working for a user)
gets their own private workspace (memory) for tasks like sorting data or holding
session-specific information.
o Background Processes: These are like specialized "staff members" that run
continuously in the background, performing essential tasks to keep the database
running smoothly.
Efficiency,
Main shared workspace for the
SGA Memory performance by
Oracle instance.
sharing resources.
Reduces parsing
SGA Stores parsed SQL, PL/SQL
Shared Pool overhead, speeds up
Component code, and data dictionary cache.
query execution.
| - Background Staff |
+----------+------------+
| (Reads/Writes)
+-----------------------+
| Oracle Database |
+-----------------------+
content_copydownload
Use code with caution.
LOGICAL STORAGE (How Oracle sees it) PHYSICAL STORAGE (How your OS sees
it)
------------------------------------ -----------------------------------
----
Tablespace "SALES_DATA" <-------------> Datafile "sales01.dbf" (e.g.,
C:\oradata\sales01.dbf)
| (Made of many OS blocks)
+-- Segment: Table "ORDERS"
| |
| +-- Extent 1 (e.g., 64KB of data blocks)
| | |
| | +-- Data Block (e.g., 8KB)
| | +-- Data Block
| | ...
| +-- Extent 2 (e.g., another 64KB of data blocks)
| ...
|
+-- Segment: Index "ORDERS_PK_IDX"
...
content_copydownload
Use code with caution.
content_copydownload
Use code with caution.
Instanc
e
Impact on
Recover When to
Option What Happens Users &
y Use
Transactions
Needed
?
Ideal for
Waits for all Very polite, but
planned
currently can take a long
maintenan
connected users to time if users
ce when
NORMAL disconnect don't log off. No
you can
themselves. No Transactions
afford to
new connections complete
wait
allowed. normally.
indefinitely.
Most
Prevents new
commonly For most
connections. Rolls
used. Quick routine
back any active,
and clean. shutdowns,
IMMEDIATE uncommitted No
Users are patches, or
transactions.
kicked off, work quick
Disconnects all
not saved is restarts.
current users.
lost.
Emergenc
Stops the instance Abrupt. Data in
y only! If
immediately, like memory buffers
the
pulling the plug. is lost. Yes, on
database
ABORT No clean Database will be next
is hung or
dismount, no in an startup.
other
rollback of inconsistent
methods
transactions. state.
fail.
Tablespace
Primary Purpose Is it Critical?
Name
Often the default tablespace for new users if No, for user
USERS
you don't specify another one. data.
Stores "undo" information. This is used to roll
UNDOTBS1 (or
back transactions and for read consistency (so Absolutely Yes!
similar)
queries see data as it was at a point in time).
content_copydownload
• User: An account that can connect to the Oracle database. Each user typically has a
schema of the same name where their objects (tables, views, etc.) are created.
• CREATE USER (Creating a new database account):
o Purpose: To define a new user who can log in and potentially own objects or access
data.
o Key Clauses Explained in Table Below.
o Important: After creating a user, they usually need the CREATE SESSION privilege
granted to them before they can actually log in. GRANT CREATE SESSION TO
new_user;
^
+---------------------+ Grants Privileges +--------------------
-+ | (User B, C, D
| Object Privileges | ------------------------> | Role X
| --- Assigns Role X to ---+ get all
| (e.g., SELECT on | | (e.g.,
"SALES_READ")| | privileges of
| SALES_TABLE, | +--------------------
-+ | Role X)
| EXECUTE on |
V
| CALC_REVENUE_PROC) |
+----------+
+---------------------+
| User C |
+----------+
V
+----------+
| User D |
+----------+
content_copydownload
• How to Grant All System Privileges to a User (Generally Not Recommended for regular
users):
o GRANT ALL PRIVILEGES TO username;
o This grants a very wide range of system privileges. It does not grant object privileges
on other users' objects unless those object privileges are part of the "ALL
PRIVILEGES" set (which is rare for specific objects). For full admin capability, users
often get roles like DBA . Use with extreme caution.
• How to Grant SELECT Object Privilege on a specific table:
o GRANT SELECT ON schema_name.table_name TO user_name; (e.g., GRANT
SELECT ON hr.employees TO intern_user; )
o To grant SELECT on all tables in a specific schema to another user, you usually need
to write a small PL/SQL script that dynamically generates and executes
the GRANT statements for each table.
• How to Unlock a User Account:
o ALTER USER username ACCOUNT UNLOCK;
o If you also want to reset their password at the same time (common if locked due to
failed attempts):
ALTER USER username IDENTIFIED BY new_temporary_password ACCOUNT
UNLOCK;
• How to List Users in the Oracle Database:
o Query the DBA_USERS data dictionary view (requires appropriate privileges):
SELECT username, account_status, default_tablespace, created FROM
dba_users ORDER BY username;
▪ account_status will show if the account is OPEN , LOCKED , EXPIRED , etc.
• Role: A named collection of privileges. Instead of granting many individual privileges to each
user, you can:
1. Create a role.
2. Grant all the necessary privileges to that role.
3. Grant the role to users.
o This makes managing permissions much simpler. If you need to change permissions
for a group of users, you just change the privileges granted to the role, and it affects
all users who have that role. (See Diagram 5 above).
• CREATE ROLE (Creating a new group of privileges):
o Purpose: To define a new role that can then have privileges granted to it.
o Syntax: CREATE ROLE sales_read_only_role;
▪ IDENTIFIED BY password : You can make a role password-protected. The
user would need to provide this password when enabling the role in their
session using SET ROLE .
▪ NOT IDENTIFIED (default): No password needed to enable the role.
o After creating the role, grant privileges to it:
GRANT SELECT ON sales_data TO sales_read_only_role;
GRANT SELECT ON products TO sales_read_only_role;
o Then, grant the role to users:
GRANT sales_read_only_role TO user_jane, user_john;
• SET ROLE (Activating/Deactivating Roles in Your Current Session):
o Purpose: When a user logs in, their default roles are usually enabled. However, they
can use SET ROLE to enable specific roles (especially password-protected ones) or
disable roles for their current session.
o Syntax:
▪ SET ROLE role_name; (Enables a specific non-password-protected role)
▪ SET ROLE role_name IDENTIFIED BY role_password; (Enables a
password-protected role)
▪ SET ROLE ALL; (Enables all roles granted to the user, except those
requiring a password if not provided)
▪ SET ROLE NONE; (Disables all roles for the current session, except the
mandatory PUBLIC role and any default roles unless they are also explicitly
disabled)
• ALTER ROLE (Modifying an Existing Role):
o Purpose: To change properties of a role, most commonly to add or remove a
password.
o Syntax:
▪ ALTER ROLE sales_read_only_role NOT IDENTIFIED; (Removes
password protection)
▪ ALTER ROLE admin_tasks_role IDENTIFIED BY
new_secure_password; (Adds/changes password)
• DROP ROLE (Deleting a Role):
o Purpose: To remove a role from the database. When a role is dropped, it's
automatically revoked from all users and other roles to whom it was granted.
o Syntax: DROP ROLE sales_read_only_role;
Limit Typical
Parameter What it Controls
Type Use Case
Prevent
resource
Maximum number of hogging by
Resource
SESSIONS_PER_USER concurrent sessions a one user
Limits
user can have. opening
many
sessions.
Stop
Maximum CPU time runaway
(in 1/100ths of a queries
CPU_PER_SESSION
second) a single from
session can use. consuming
all CPU.
Prevent
Max data blocks read
very I/O
from memory/disk for
LOGICAL_READS_PER_CALL intensive
a single database call
single
(parse, exec, fetch).
operations.
Protect
Number of
against
Password consecutive failed
FAILED_LOGIN_ATTEMPTS brute-force
Limits login tries before the
password
account is locked.
attacks.
Enforce
Number of days a regular
password remains password
PASSWORD_LIFE_TIME
valid before it must be changes
changed. for
security.
Give users
Days a user gets a a chance
warning before their to change
PASSWORD_GRACE_TIME
password expires password
(they can still log in). before
expiry.
Prevent
Minimum number of
immediate
days before an old
PASSWORD_REUSE_TIME reuse of
password can be
old
reused.
passwords.
content_copydownload
content_copydownload
content_copydownload
content_copydownload
Tables owned
by
USER_TABLES the currently None (you can always see your own).
connected
user.
Tables that
the currently
connected
user has
permission to
ALL_TABLES None.
access (either
they own them,
or someone
granted them
privileges).
All tables in
the entire
database, Typically DBA role, or SELECT ANY
DBA_TABLES
regardless of DICTIONARY / SELECT_CATALOG_ROLE privilege.
owner or
permissions.
o Example: SELECT table_name, owner FROM all_tables WHERE owner =
'HR';
• How To Fix the “ORACLE initialization or shutdown in progress” error:
o What it means: The database instance is not fully open and ready for normal
operations. It's stuck in one of the startup or shutdown phases.
o Common Causes:
▪ A previous SHUTDOWN ABORT or an instance crash (e.g., server power loss).
The database needs recovery.
▪ The database was intentionally started to NOMOUNT or MOUNT state and not
yet opened.
▪ A shutdown command ( NORMAL , TRANSACTIONAL , IMMEDIATE ) is currently
in progress and hasn't completed.
o General Fix Steps (Connect as SYSDBA or SYSOPER ):
1. Check current status: SELECT status FROM v$instance; (Might
show MOUNTED , STARTED (for NOMOUNT), etc.)
2. If a normal shutdown seems stuck or you suspect a problem, a clean
abort and restart is often the quickest way (but be aware this forces
instance recovery):
SHUTDOWN ABORT;
STARTUP; (This will automatically attempt instance recovery if needed and
then open the database.)
3. If STARTUP; fails or you want more control:
▪ STARTUP MOUNT;
▪ Then check the alert log for errors.
▪ If no major errors, try: ALTER DATABASE OPEN;
4. Always check the Alert Log: The alert log file (location varies but often
in $ORACLE_BASE/diag/rdbms/your_db_name/your_instance_name/t
race/alert_your_instance_name.log ) contains detailed error
messages and is crucial for diagnosing startup problems.
• Understand the "Why": Don't just memorize commands; understand why you would use a
particular command or feature.
• Key Differences: Be clear on distinctions like Database vs. Instance, System vs. Object
Privileges, SHUTDOWN IMMEDIATE vs. ABORT .
• Core Components: Know the main SGA parts (Buffer Cache, Shared Pool) and the primary
roles of key background processes (PMON, SMON, DBWn, LGWR, CKPT).
• Practical Scenarios: Think about when you'd create a tablespace, add a user, grant a role,
or use Data Pump.
• Read Carefully: Ensure you understand what the exam question is asking before
answering.
• Relax! You've prepared. Take a deep breath.