Sub topic 7
Creating a development user instead of working as SYS or ADMIN
This chapter assumes that you know basic SELECT, INSERT, and CREATE TABLE statements. You should also understand the difference between a database client and a database server. For the container option, you need a terminal and basic Docker or Podman commands. For Autonomous Database, you need access to the Oracle Cloud console. FreeSQL does not normally give you administrative access.
Why use a development user?
SYS and ADMIN are administrative accounts. An administrative account can change database settings, create users, inspect other schemas, and remove objects that other people need. Those privileges are useful for setup, but they make practice mistakes more serious.
A development user is a separate database account for your tables, views, procedures, and test data. It should have only the privileges needed for your exercises. This separation gives you:
- A safer place to create and remove objects.
- A schema that represents a real application owner.
- Fewer accidental changes to the database.
- A clearer test of which privileges your application actually needs.
A user and a schema are closely related in Oracle. When you create a user, Oracle creates a schema with the same name. Objects created by APP_USER belong to the APP_USER schema unless another schema is specified.
The account model in each environment
The setup differs slightly between the three free options.
| Environment | Setup account | Development-user approach |
|---|---|---|
| 26ai Free container | `SYS` in `FREEPDB1` | Create a local user in the pluggable database |
| Autonomous Database | `ADMIN` | Create a local user from Database Actions or a SQL client |
| FreeSQL | Site-provided schema | Use the assigned schema; user creation is usually unavailable |
The container command in the previous chapter connects to the FREEPDB1 pluggable database. Create the practice user there, not only in the root container. A user created in the wrong container might not be available where you run your tables.
Create a user in the container database
Connect as SYS to FREEPDB1:
sqlplus sys/ChangeMe_123@localhost:1521/FREEPDB1 as sysdbaCreate the user and grant a development role:
CREATE USER app_user
IDENTIFIED BY "ChangeMe_123"
QUOTA UNLIMITED ON users;
GRANT DB_DEVELOPER_ROLE TO app_user;CREATE USER creates the account. The IDENTIFIED BY clause sets its password. The quota allows the schema to use space in the USERS tablespace. A quota is required before the user can create many kinds of persistent objects.
DB_DEVELOPER_ROLE is an Oracle role, which is a named collection of privileges. It is convenient for a local learning database because it provides common development privileges. For a production application, grant a smaller, purpose-built set instead.
For a more restrictive practice account, grant only the privileges needed by your exercises:
CREATE USER app_user
IDENTIFIED BY "ChangeMe_123"
QUOTA 100M ON users;
GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE,
CREATE VIEW, CREATE PROCEDURE
TO app_user;CREATE SESSION allows the user to log in. The other privileges allow common schema work. The 100M quota limits the amount of space this user can consume in the USERS tablespace.
Create a user in Autonomous Database
In Autonomous Database, connect to Database Actions as ADMIN, open SQL, and run a user-creation statement. The exact available roles can vary by service configuration, so start with the smallest set you need:
CREATE USER app_user
IDENTIFIED BY "ChangeMe_123";
GRANT CREATE SESSION TO app_user;
GRANT CREATE TABLE, CREATE VIEW, CREATE SEQUENCE,
CREATE PROCEDURE TO app_user;Autonomous Database manages much of the storage configuration for you. Do not assume that a local container’s tablespace and quota commands apply unchanged to Autonomous Database. If Database Actions reports a quota or tablespace error, use the Autonomous Database user-management interface or its current documentation for the supported storage settings.
When you connect as app_user, use the connection method supplied by Database Actions. Autonomous Database connections use encrypted TLS and commonly require a wallet or a cloud connection configuration. Do not copy a container connection string such as localhost:1521/FREEPDB1 into an Autonomous Database client.
Confirm the account and container
Log in as the new user and check the session:
SELECT sys_context('USERENV', 'CON_NAME') AS container_name,
sys_context('USERENV', 'SESSION_USER') AS session_user
FROM dual;The result should show APP_USER as the session user. In the container environment, the container name should be FREEPDB1.
Then test object creation:
CREATE TABLE practice_note (
id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
body VARCHAR2(200) NOT NULL
);
INSERT INTO practice_note (body)
VALUES ('Created by the development user');
COMMIT;
SELECT id, body
FROM practice_note;The table belongs to APP_USER. You can confirm its owner with:
SELECT owner, table_name
FROM user_tables
WHERE table_name = 'PRACTICE_NOTE';USER_TABLES is a data dictionary view. It describes tables owned by the current user. This is safer and simpler than querying every table in the database.
Exercise
Why should the CREATE USER command run in FREEPDB1 when the practice connection also uses FREEPDB1?
Show answer
A pluggable database has its own users and objects. Creating the user in another container can leave APP_USER unavailable in the database where the exercises run.