MTITEK.com
Oracle Database / Oracle Foundations

Instance vs Database

Multitenant Architecture: CDB and PDBs

The database is organized as a container database hosting one or more pluggable databases.

A session is always positioned in exactly one container. Admins can move between them:

-- show where you are
SHOW CON_NAME;

-- switch between CDB root and the PDB
ALTER SESSION SET CONTAINER = XEPDB1;
ALTER SESSION SET CONTAINER = CDB$ROOT;

Database, Schema, User

In Oracle, user and schema are essentially the same thing. This differs from databases like PostgreSQL, where users and schemas are independent objects.
If you create a user called MTITEK, Oracle also creates a schema called MTITEK.
MTITEK.MY_TABLE_1 means the table MY_TABLE_1 owned by the schema MTITEK.

User Types

-- common user: exists across all containers
ALTER SESSION SET CONTAINER = CDB$ROOT;
CREATE USER C##ADMIN IDENTIFIED BY CADMINPWD CONTAINER = ALL;
GRANT DBA TO C##ADMIN CONTAINER = ALL;
-- local user: exists only in the current PDB
ALTER SESSION SET CONTAINER = XEPDB1;
CREATE USER MTITEK IDENTIFIED BY MTITEKPWD;
GRANT CONNECT, RESOURCE TO MTITEK;

Roles

Connection roles are selected at connect time (the "Role" field in SQL Developer or the AS SYSDBA clause in sqlplus).
They allow you to connect to a database instance (even when it's idle/closed) and perform system operations.
They are not stored in the database's data dictionary; instead, they are controlled outside the database (via OS groups or password files).

Database roles are standard database-level permissions that are granted to users and live inside the database.
They are predefined, groupable sets of permissions created to manage the everyday tasks of developers, application owners, and database administrators (schema management and security).
They are listed in the DBA_ROLES view and can be granted to users.

Connection Roles

Database Roles

Connecting: Services, SID, and the Listener

Services

A service is a named access point to a database, used in connection strings. Oracle XE 21c exposes these services out of the box:

For a local XE installation you only need these two services: XE for admin work and XEPDB1 for application work.

SID vs Service Name

A SID connects directly to the instance with no flexibility.
A service name supports load balancing and PDBs.
PDB connections (e.g., XEPDB1) require a service name. Oracle does not register a SID for individual PDBs — only the CDB has a SID — so PDBs cannot be reached using SID-style connection syntax.

SID syntax:
host:port:SID
jdbc:oracle:thin:@localhost:1521:XE
Service Name syntax:
host:port/service
jdbc:oracle:thin:@//localhost:1521/XEPDB1

Listener and TNS

Connection Examples

Admin work:
username=SYS
role=SYSDBA
service=XE
Application work:
username=MTITEK
role=DEFAULT
service=XEPDB1
Common user (granted at CDB level):
username=C##ADMIN
role=DEFAULT
service=XEPDB1
Roles and services combinations:
SYSDBA  + XE      = CDB root, full admin access across all PDBs
SYSDBA  + XEPDB1  = directly into the PDB as admin
DEFAULT + XEPDB1  = normal application user connection

Physical Storage: Tablespaces

Analogy: the tablespace is the physical filing cabinet (where data lives on disk); the schema is the labeled folder inside the cabinet (who owns which documents).

ALTER SESSION SET CONTAINER = XEPDB1;
CREATE TABLESPACE MTITEK_DATA_TS DATAFILE '/opt/oracle/oradata/XE/XEPDB1/mtitek_data_ts_1.dbf' SIZE 500M AUTOEXTEND ON;

CREATE USER MTITEK_APP IDENTIFIED BY MTITEKPWD DEFAULT TABLESPACE MTITEK_DATA_TS QUOTA UNLIMITED ON MTITEK_DATA_TS;

GRANT CONNECT, RESOURCE TO MTITEK_APP;

MTITEK_APP is the schema/user.
MTITEK_DATA_TS is the tablespace that physically stores its data.

Built-in Tablespace Types

Oracle Files for Data Integrity