To Work With Oracle Database 19c On A Linux Virtual Machine
To Work With Oracle Database 19c On A Linux Virtual Machine
familiarize yourself with the basics of starting, stopping, and managing the database. Here’s a step-
by-step guide with the necessary commands and an overview of key functionalities.
Command:
sudo su - oracle
sqlplus / as sysdba
STARTUP;
Explanation:
sudo su - oracle: Switches the user to oracle, which is required for database administration
tasks.
Result: You will see messages indicating that the database is opening, and it will eventually display
Database opened.
Logic: This command initializes the database instance, mounts the database, and opens it for access.
Command:
sudo su - oracle
sqlplus / as sysdba
SHUTDOWN IMMEDIATE;
Explanation:
SHUTDOWN IMMEDIATE;: Shuts down the database without affecting active sessions
abruptly.
Result: You will see messages indicating that the database is closing, and it will eventually display
Database closed.
Logic: This command allows Oracle to terminate user sessions gracefully and write any pending
changes to disk.
lsnrctl start
Explanation: Starts the Oracle Listener, which handles incoming client connection requests.
Result: You will see a message stating Listening on: followed by the address and port.
Logic: The listener enables external connections to the database, allowing client applications to
access the database services.
Command:
lsnrctl stop
Result: You will see a message stating LSNRCTL: stopping... followed by Service "..." has 0 instance(s).
Logic: Stopping the listener prevents new client connections until it is restarted.
Command:
lsnrctl status
Result: You will see details about the listener configuration, including services that are registered.
Logic: This command helps ensure the listener is running and that it recognizes the database
services.
Connect as SYSDBA
Command:
sqlplus / as sysdba
Result: You will enter the SQL*Plus prompt, ready to execute SQL commands.
Logic: SYSDBA has full administrative privileges, allowing access to all database objects and
operations.
sqlplus username/password@ORCL
Result: You will enter the SQL*Plus prompt for that user.
Logic: Normal users have restricted access, based on the privileges granted to them.
Command:
Logic: This command helps users understand the tables available in their schema.
Command:
first_name VARCHAR2(50),
last_name VARCHAR2(50),
salary NUMBER
);
Logic: This command defines the structure of the table to store employee data.
Command:
Command:
Logic: This command allows users to view the contents of the table.
Update Data
Command:
Delete Data
Command:
5. Managing Tablespaces
Command:
Logic: This command helps understand the logical storage structure of the database.
Create a New Tablespace
Command:
Explanation: Creates a new tablespace named my_tablespace with a specified data file and size.
Logic: This command defines a new logical storage unit for data.
Command:
ALTER TABLESPACE my_tablespace ADD DATAFILE
'/u01/app/oracle/oradata/orcl/mytablespace02.dbf' SIZE 100M;
Logic: This command allows expanding storage capacity for the tablespace.
Start RMAN
Command:
rman target /
Command:
BACKUP DATABASE;
Logic: This command is essential for data protection and recovery strategies.
Restore the Database
Command:
RESTORE DATABASE;
Result: RMAN will display progress messages indicating the restoration process.
Logic: This command is critical for recovering from failures or data loss.
Command:
SELECT username, sid, serial#, status FROM v$session WHERE username IS NOT NULL;
Result: Displays a list of sessions with details such as username and status.
Logic: This command helps monitor user activity and troubleshoot performance issues.
Command:
SELECT sql_text FROM v$sql WHERE parsing_user_id = (SELECT user_id FROM dba_users WHERE
username = 'SCOTT');
Result: Displays the SQL text for queries run by the user SCOTT.
Logic: This command helps analyze which queries are running and their performance impact.
Command:
sqlplus / as sysdba
Logic: This command provides quick insight into whether the database is running.
9. Automatic Database Startup/Shutdown on System Boot
Command:
sudo vi /etc/oratab
Change:
ORCL:/u01/app/oracle/product/19.0.0/dbhome_1:N
To:
ORCL:/u01/app/oracle/product/19.0.0/dbhome_1:Y
Explanation: Edit the oratab file to allow Oracle to start automatically on system boot.
Command:
Command:
Conclusion
This guide provides a detailed overview of essential Oracle database commands, their explanations,
results, and underlying logic. You can use this as a quick reference for managing an Oracle Database
19c environment. If you have any further queries or need assistance with specific commands, feel
free to ask!
SELECT table_name FROM user_tables; Show existing tables List of table names
INSERT INTO employees (...) VALUES (...); Insert data into a table 1 row inserted
SELECT * FROM employees; View data from a table Displays all rows
UPDATE employees SET salary = ...; Update data in a table 1 row updated
DELETE FROM employees WHERE ...; Delete data from a table 1 row deleted
5. Managing Tablespaces
Tablespace
CREATE TABLESPACE my_tablespace ...; Create a new tablespace
created
RESTORE DATABASE; Restore the database from backup Progress messages displayed
SELECT username, sid, serial#, status FROM v$session WHERE View active user List of active
username IS NOT NULL; sessions sessions
SELECT sql_text FROM v$sql WHERE parsing_user_id = (SELECT View running SQL Displays SQL
user_id FROM dba_users WHERE username = 'SCOTT'); queries text
SELECT status FROM v$instance; Check database instance status Displays instance status
CREATE USER new_user IDENTIFIED BY password; Create a new database user User created
GRANT CONNECT, RESOURCE TO new_user; Grant privileges to the new user Grant succeeded
Note:
Always ensure you have the necessary privileges to execute these commands.
This cheat sheet is a quick reference guide; for more in-depth information, consult Oracle
documentation or your DBA.