Lab Report DBA
Lab Report DBA
**Q1.1**: How can you view the name and number of tablespaces in the current database?
**Answer**:
```sql
-- Login with sys as sysdba and execute the following query
SELECT * FROM V$TABLESPACE;
```
**Answer**:
```sql
-- Create a new tablespace with an initial size of 5MB and autoextend enabled
CREATE TABLESPACE demo2
DATAFILE 'C:\RMAN\DEMO\DEMO.dbf' SIZE 5M AUTOEXTEND ON;
```
**Q1.3**: How can you add a new datafile to an existing tablespace `demo`?
**Answer**:
```sql
-- Add a new datafile of 15MB to the existing tablespace demo
ALTER TABLESPACE demo
ADD DATAFILE 'c:\rman\demo\datafile.dbf' SIZE 15M AUTOEXTEND ON;
```
**Answer**:
```sql
-- Resize the datafile to 10MB
ALTER DATABASE DATAFILE 'c:\rman\demo\datafile.dbf' RESIZE 10M;
```
**Answer**:
```sql
-- Drop the tablespace demo
DROP TABLESPACE demo;
```
**Q2.1**: How do you create a new user `BIT1` with the password `password1`?
**Answer**:
```sql
-- Create a new user BIT1 with the specified password
CREATE USER BIT1 IDENTIFIED BY password1;
```
**Q2.2**: How can you grant `connect` and `resource` privileges to the user `demo`?
**Answer**:
```sql
-- Grant the connect and resource privileges to the user demo
GRANT connect, resource TO demo;
```
**Q2.3**: How do you grant `SELECT` access to the `employees` table in the `HR` schema for the
user `demo`?
**Answer**:
```sql
-- Grant select access on HR.EMPLOYEES to the user demo
GRANT SELECT ON hr.employees TO demo;
```
**Q2.4**: How do you revoke the `SELECT` privilege on the `employees` table from the user
`demo`?
**Answer**:
```sql
-- Revoke select access on HR.EMPLOYEES from the user demo
REVOKE SELECT ON hr.employees FROM demo;
```
**Q2.5**: How do you delete the user `demo` and all its associated objects?
**Answer**:
```sql
-- Drop the user demo along with all its objects
DROP USER demo CASCADE;
```
**Q3.1**: Describe the steps to create an Oracle logical backup using `expdp`.
**Answer**:
```sql
-- Create a directory for the backup
CREATE DIRECTORY demo AS 'c:\test';
**Answer**:
```sql
-- Use Data Pump import utility to restore the backup
impdp hr/hr DIRECTORY=demo DUMPFILE=demo.dmp LOGFILE=impdemo.log
SQLFILE=impdp.log;
```
**Q4.1**: What steps are required to put the database in ARCHIVELOG mode and perform a
backup using RMAN?
**Answer**:
```sql
-- Check the current log mode
SELECT log_mode FROM v$database;
-- From a new command window, run RMAN and perform the backup
rman target /
RMAN> BACKUP AS BACKUPSET DATABASE;
```
**Answer**:
```sql
-- Show the current SGA target parameter
SHOW PARAMETER sga_target;
**Q5.2**: Describe the steps to start and stop the Oracle database instance.
**Answer**:
```sql
-- Start the Oracle instance
sqlplus
-- Login as sysdba
CONNECT sys as sysdba
**Answer**:
```sql
-- Take the tablespace demo offline
ALTER TABLESPACE demo OFFLINE;
```
**Answer**:
```sql
-- Bring the tablespace demo back online
ALTER TABLESPACE demo ONLINE;
```
**Answer**:
```sql
-- Coalesce free space in the tablespace demo
ALTER TABLESPACE demo COALESCE;
```
**Q7.1**: How do you create an index on the `LastName` column of the `employees` table?
**Answer**:
```sql
-- Create an index on the LastName column
CREATE INDEX idx_lastname ON employees (LastName);
```
**Answer**:
```sql
-- Rebuild the index idx_lastname
ALTER INDEX idx_lastname REBUILD;
```
**Answer**:
```sql
-- Drop the index idx_lastname
DROP INDEX idx_lastname;
```
**Q8.1**: How do you view the current active sessions in the database?
**Answer**:
```sql
-- View current active sessions
SELECT * FROM v$session WHERE status = 'ACTIVE';
```
**Answer**:
```sql
-- Check current database locks
SELECT * FROM v$lock;
```
**Answer**:
```sql
-- Identify resource-intensive queries
SELECT sql_text, disk_reads, executions
FROM v$sql
ORDER BY disk_reads DESC;
```