DBA Class Notes
DBA Class Notes
Linux Commands
1. pwd
2. mkdir
3. open
4. cd
5. ls -ltr
6. mv
7. clear
8. rm
9. ls
10. ls -l
11. >
12. sort
13. exit
14. vi
15. wq
16. cat
17. chmod -w <filename>
18. chmod +x <filename>
19. sh <filename>
20. ./<filename>&
21. hostname
22. top
23. kill
GIRI
3. Cd (change directory)
Using CD <filename>
change the current
working directory
Created 2 files
(giri1 , giri2)
4. Open <filename>
Changed directory to
Using OPEN <filename> giri1 , initially it was
a giri directory
You can able to open the
directory which you
want.
5. CP
GIRI
To edit any text file we have to remember these things;
Vi Edit mode
Cat Read text file
Esc + dd Delete the text
Ecs + shift + ; To come out from edit mode
Wq Saving purpose, write and quite the file
STEPS TO CREATE A TEXT FILE:
8. LS
9. rm
It remove/delete entire
from system.
rm abc.txt
GIRI
10. MV (Move command. It used to move a file/directory into another destination file.) try…
11. Chmod -w <filename>
12. TOP
13.KILL
KILL USING PID
GIRI
1.ORACLE DATABASE INSTALLATION GUIDE
. 1 2
3 3
GIRI
NOW
1. Open V38894-01_2of2. Follow this path: database → stage → components → copy all those files.
2. Now Open V38894-01_1of2. Follow this path: database → stage → components → past all copied files here.
Procedure to setup:
1. Click on NEXT
2. A pop up come Click on YES
3. Click on NEXT
4. Check box: create and configure a database
5. Select : Desktop class
6. Try to create with a new user.
7. Provide administrative password and confirm
8. Some loads and click on INSTALL.
1
Search for ORACLE
SQL DEVELOPER
GIRI
You need to download : java sdk 8
Technical terms:
• Net Listener
• SID
• Service name
• Container database
• Pluggable database
• Sql Plus
• Sql Developer
1. Net listener : A listener is configured with one or more listening protocol addresses, information about
supported services, and parameters that control its run-time behavior. The listener configuration is stored in a
configuration file named listener.ora.
Because all of the configuration parameters have default values, it is possible to start and use a listener with no
configuration. This default listener has a name of LISTENER, supports no services on startup, and listens on the
following TCP/IP protocol address:
(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
An SID is specific to a database, it is unique in an environment and 'points' to one, and only one,
database in that environment. A service name can be associated with one or more SIDs; think about a
RAC environment where each instance is uniquely named yet all can be accessed through the
SERVICE_NAME:
SID SERVICE_NAME
bob1 bob
bob2 bob
bob3 bob
GIRI
Through the 'magic' of the tnsnames.ora file all four of those SIDs can be associated with the
SERVICE_NAME bob, and if load balancing is configured, the listener will 'balance' the workload across
all four SIDs. This doesn't stop you from connecting to bob1 all of the time if you want to, you just
need to NOT use the SERVICE_NAME and use the SID.
Think of the SERVICE_NAME as a town and each SID as a house in that town; you can choose to drive
to town and see who's home (using the SERVICE_NAME) or you can make a direct trip to one of those
houses (using the SID).
SERVICE_NAME is a much more flexible choice. Dynamic registration uses the SERVICE_NAME and
allows one or more SIDs to be serviced by that SERVICE_NAME (no pun intended).
If you run ''lsnrctl services' you'll see how the SERVICE_NAME and SID relate:
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Refer : https://www.databasestar.com/oracle-pdb/
4. SQL PLUS
SQLPlus is an interactive and batch query tool that is installed with every Oracle Database Server or Client
installation. It has a command-line user interface, a Windows Graphical User Interface (GUI) and the I sql
Plus web-based user interface.
SQL*Plus has its own commands and environment, and it provides access to the Oracle Database. It
enables you to enter and execute SQL, PL/SQL, SQL*Plus and operating system commands to perform the
following:
• Format, perform calculations on, store, and print from query results
• Examine table and object definitions
• Develop and run batch scripts
• Perform database administration
Refer : https://docs.oracle.com/cd/B14117_01/server.101/b12170/ch1.htm
GIRI
5. SQL DEVELOPER
Oracle SQL Developer is a free, integrated development environment that simplifies the development and
management of Oracle Database. Java powered application for Windows, OS X, and Linux with + 5 Million
users.
• Full featured PL/SQL IDE
• Database administration
• Complete Data Modelling Solution
• 3rd party DBMS migrations to Oracle
• Migrate Oracle On-Premises to Oracle Cloud
GIRI
tnsnames.ora file looks like this…
3.CREATE A TABLE
GIRI
4. COMMANDS TO KNOW
1. Shutdown;
2. Startup;
3. Startup mount;
4. Shutdown immediate;
5. Shutdown abort;
6. Show con_name;
7. Show pdbs;
8. tnsping <service name>
9. lsnrctl
10. lsnrctl start
11. lsnrctl status
12. show user;
13. alter database open;
14. alter database mount;
15. alter pluggable database <pdb_name> open;
16. alter session set container = <pdb_name>
Shutdown [Normal]: Normal database shutdown proceeds with the following conditions:
• No new connections are allowed after the statement is issued.
• Before the database is shut down, the database waits for all currently connected users to
disconnect from the database.
Shutdown Immediate:
• No new connections are allowed, nor are new transactions allowed to be started, after the
statement is issued.
• Any uncommitted transactions are rolled back. (If long uncommitted transactions exist, this
method of shutdown might not complete quickly, despite its name.)
• Oracle Database does not wait for users currently connected to the database to disconnect. The
database implicitly rolls back active transactions and disconnects all connected users.
The next startup of the database will not require any instance recovery procedures.
GIRI
Shutdown transactional:
Shutdown abort:
You can shut down a database instantaneously by aborting the database instance. If possible, perform
this type of shutdown only in the following situations:
The database or one of its applications is functioning irregularly and none of the other types of shutdown
works.
• You need to shut down the database instantaneously (for example, if you know a power shutdown is
going to occur in one minute).
• You experience problems when starting a database instance.
When you must do a database shutdown by aborting transactions and user connections, use one of the
following commands:
An aborted database shutdown proceeds with the following conditions:
• No new connections are allowed, nor are new transactions allowed to be started, after the statement
is issued.
• Current client SQL statements being processed by Oracle Database are immediately terminated.
• Uncommitted transactions are not rolled back.
• Oracle Database does not wait for users currently connected to the database to disconnect. The
database implicitly disconnects all connected users.
The next startup of the database will require automatic instance recovery procedures.
Startup:
GIRI
tnsping <service_name>:
GIRI
5.INTERNAL DB STRUCTURE
Datafiles: Data files are the operating system files that store the data within the database. The data is
written to these files in an Oracle proprietary format that cannot be read by other programs.
Refer: datafiles..
Control files: The control file must be available for writing by the Oracle database server whenever the
database is open. Without the control file, the database cannot be mounted and recovery is difficult.
The control file of an Oracle database is created at the same time as the database. By default, at least one
copy of the control file is created during database creation. On some operating systems the default is to
create multiple copies. You should create two or more copies of the control file during database creation.
You might also need to create control files later, if you lose control files or want to change particular
settings in the control files.
Refer: controlfiles..
Redo log files: The most crucial structure for recovery operations is the redo log, which consists of two or
more preallocated files that store all changes made to the database as they occur. Every instance of an Oracle
Database has an associated redo log to protect the database in case of an instance failure.
Refer: redologfiles..
Article Body
ARCHIVELOG mode is a mode that you can put the database in for creating a backup of all transactions that
have occurred in the database so that you can recover to any point in time.
NOARCHIVELOG mode is basically the absence of ARCHIVELOG mode and has the disadvantage of not being
able to recover to any point in time. NOARCHIVELOG mode does have the advantage of not having to write
transactions to an archive log and thus increases the performance of the database slightly.
ARCHIVELOG MODE
Advantages
1. You can perform hot backups (backups when the database is online).
2. The archive logs and the last full backup (offline or online) or an older backup can completely recover the
database without losing any data because all changes made in the database are stored in the log file.
GIRI
Disadvantages
1. It requires additional disk space to store archived log files. However, the agent offers the option to purge the
logs after they have been backed up, giving you the opportunity to free disk space if you need it.
NO-ARCHIVELOG MODE
Advantages
1. It requires no additional disk space to store archived log files.
Disadvantages
1. If you must recover a database, you can only restore the last full offline backup. As a result, any changes made
to the database after the last full offline backup are lost.
2. Database downtime is significant because you cannot back up the database online. This limitation becomes a
very serious consideration for large databases.
Note: Because NOARCHIVELOG mode does not guarantee Oracle database recovery if there is a disaster, the
Agent for Oracle does not support this mode. If you need to maintain Oracle Server in NOARCHIVELOG mode,
then you must backup full Oracle database files without the agent using CA ARCserve Backup while the database
is offline to ensure disaster recovery.
6. DATAFILES RECOVERY
Scenario:
GIRI
7.CONTROLFILE RECOVERY
1. shutdown immediate;
2. Copy CONTROLO2 file from FAST_RECOVERY_AREA
3. Past this file in oradata folder
4. Rename as CONTROL01
5. Open SQL plus
6. Login
7. Alter database mount;
8. Alter database open;
8.USER CREATION
1. Login
2. Try to create user : you will get error- ora:65096
3. Run: alter session set “_oracle_script” = true ;
4. create user GIRI identified by GIRI123 ;
5. grant dba to GIRI;
6. CONNECT GIRI
7. SHOW USER;
8. For dropping a database user: DROP USER GIRI;
GIRI
9. RMAN
RECOVERY MANAGER
RMAN
CONNECT TARGET /
LIST BACKUP;
BACKUP DATA
RMAN Database Recovery done only when your database ARCHIVELOG MODE is ON
Steps:
Shutdown immediate;
Startup mount;
GIRI
Now shift to cmd for backup files:
RMAN
CONNECT TARGET /
BACKUP DATABASE;
STARTUP MOUNT;
BACKUP DATABASE;
BACKUP DATA
CONNECT TARGET /
STARTUP MOUNT;
RESTORE DATABASE;
login
Startup;
GIRI
There is chance of getting an error : database note open
Try this.
alter database open;
RECOVER DATAFILE 1;
Shutdown;
NOTE
GIRI
10. MEMORY MANAGEMENT
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
System altered.
System altered.
GIRI
11.TELNET
Telnet, developed in 1969, is a protocol that provides a command line interface for communication with a
remote device or server, sometimes employed for remote management but also for initial device setup like
network hardware. Telnet stands for Teletype Network, but it can also be used as a verb; 'to telnet' is to
establish a connection using the Telnet protocol.
Telnet provides users with a bidirectional interactive text-oriented communication system utilizing a virtual
terminal connection over 8 byte. User data is interspersed in-band with telnet control information over
the transmission control protocol (TCP). Often, Telnet was used on a terminal to execute functions remotely.
The user connects to the server by using the Telnet protocol, which means entering Telnet into a command
prompt by following this syntax: telnet hostname port. The user then executes commands on the server by
using specific Telnet commands into the Telnet prompt. To end a session and log off, the user ends a Telnet
command with Telnet.
Telnet can be used to test or troubleshoot remote web or mail servers, as well as for remote access to MUDs
(multi-user dungeon games) and trusted internal networks.
GIRI
GIRI
12.pfile vs spfile
Spfile refers to Server Parameter file(spfile$ORACLE_SID.ora). Server parameter files are binary files that
exist only on the server and are called from client locations to start up the database. Since spfile is a
binary file we cannot edit the file directly rather we need to use ALTER SYSTEM SET parameter
to modify/update the parameters.
You must have the SYSDBA or the SYSOPER system privilege to create spfile. You can execute this
statement before or after instance startup. However, if you have already started an instance using
spfile_name, you cannot specify the same spfile_name in this statement.
Pfile refers to Parameter file(init$ORACLE_SID.ora). Pfile is a text file created from spfile, used to get a
list of the current parameter setting being used by the database. We can easily edit the pfile using editor
like vi and applied to the database by creating spfile from the pfile.
You must have the SYSDBA or the SYSOPER system privilege to create pfile. We can execute this
statement either before or after instance startup.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
GIRI
SQL> SHUTDOWN IMMEDIATE;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> STARTUP;
ORA-00823: Specified value of sga_target greater than sga_max_size
init.ora.23202371229
File created.
GIRI
13. CREATE TABLESPACE
SQL> startup;
ORACLE instance started.
Tablespace altered.
User altered.
GIRI
SQL> CONNECT trnusr
Enter password: trnusr
Connected.
SQL> CREATE TABLE EMPLOYEE (ID INT, NAME VARCHAR(20));
Table created.
SQL> COMMIT;
Commit complete.
SQL> ROLLBACK;
Rollback complete.
GIRI
14.SHOW PARAMETER
File created.
SQL> startup;
ORACLE instance started.
GIRI
15.CONTROLFILE BACKUP USING RMAN
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Cmd:
Microsoft Windows [Version 10.0.22000.1696]
(c) Microsoft Corporation. All rights reserved.
C:\Users\girin>rman
Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved.
Statement processed
released channel: ORA_DISK_1
GIRI
File Name:
D:\APP\GIRINAGESH5\FAST_RECOVERY_AREA\NAGESH\AUTOBACKUP\2023_03_20\O1_M
F_S_1131992890_L1JP325B_.BKP
RMAN>
Sql side
SQL> startup;
ORACLE instance started.
SQL>
GIRI
Cmd side
C:\Users\girin>rman
Sql side:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
GIRI
Total System Global Area 2147483648 bytes
Fixed Size 2926472 bytes
Variable Size 1224738936 bytes
Database Buffers 905969664 bytes
Redo Buffers 13848576 bytes
SQL> alter database mount;
Database altered.
SQL> alter database clear unarchived logfile group 1;
Database altered.
SQL> alter database clear unarchived logfile group 2;
Database altered.
SQL> alter database clear unarchived logfile group 3;
Database altered.
SQL> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup
GIRI
16.EXPORT AND IMPORT SCHEMAS
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
WARNING: Oracle Data Pump operations are not typically needed when connected to the root or seed of a container
database.
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
GIRI
WARNING: Oracle Data Pump operations are not typically needed when connected to the root or seed of a container
database.
C:\Users\girin>
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> connect
Enter user-name: c##rajesh
Enter password:
Connected.
SQL> select * from emp;
ID NAME
---------- ----------
10 nagesh
13 giri
GIRI
SQL> drop user c##rajesh cascade; AFTER EXPORT USER SCHEMA.
WE DROPED USER
User dropped.
SQL> connect
Enter user-name: c##rajesh
Enter password:
ERROR:
ORA-01017: invalid username/password; logon denied
SQL> connect
Enter user-name: c##rajesh
Enter password:
After importing the dumpfile,
Connected.
Now I am able to get back the user
SQL> select * from emp;
ID NAME
---------- ----------
10 nagesh
13 giri
SQL>
TASK: GET ACCESS OF EMP TABLE FROM C##RAJESH USER TO C##SURESH USER
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
ORA-39002: invalid operation
ORA-39166: Object SYS.EMP was not found. UNDERSTAND EMP TABLE NOT
RELATED TO SYS USER/SCHEMA
GIRI
C:\Users\girin>impdp directory=dp dumpfile=rajesh.dmp tables='emp' remap_schema='c##rajesh:c##rajesh'
Import: Release 12.1.0.1.0 - Production on Mon Mar 20 23:08:54 2023
Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
WARNING: Oracle Data Pump operations are not typically needed when connected to the root or seed of a container
database.
Username: c##rajesh
Password:
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
WARNING: Oracle Data Pump operations are not typically needed when connected to the root or seed of a container
database.
Master table "C##RAJESH"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "C##RAJESH"."SYS_IMPORT_TABLE_01": c##rajesh/******** directory=dp dumpfile=rajesh.dmp
tables='emp' remap_schema='c##rajesh:c##suresh'
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "C##SURESH"."EMP" 5.492 KB 2 rows
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
Job "C##RAJESH"."SYS_IMPORT_TABLE_01" successfully completed at Mon Mar 20 23:10:03 2023 elapsed 0 00:00:02
C:\Users\girin
GIRI
SQLPLUS SIDE
User created.
Grant succeeded.
Grant succeeded.
SQL> connect
Enter user-name: c##suresh
Enter password:
Connected.
SQL> connect
Enter user-name: sys as sysdba
Enter password:
Connected.
SQL> connect
Enter user-name: c##suresh
Enter password:
Connected.
SQL> select * from emp;
EMP TABLE IS CREATED BY C##RAJESH
ID NAME NOW YOU CAN ACCESS THAT SAME TABLE
---------- ---------- IN C##SURESH USER
10 nagesh
13 giri
SQL>
TASKS :
1) EXPORT TABLESPACE DATA INTO DUMPFILE…
2) IMPORT TABLES INTO ANOTHER TABLESPACE….
3) REMAP TABLE…..
GIRI
17.IMPORT A DUMPFILE REMOTE SYSTEM
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Connected to HARI
5 times inserted
5 times inserted
GIRI
NAME FNAME
---------- ----------
adam smith
adam smith
adam smith
adam smith
adam smith
adam smith
6 rows selected.
NAME FNAME
---------- ----------
smith adam
smith adam
smith adam
smith adam
smith adam
smith adam
6 rows selected.
SQL>
CMD SIDE
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit
Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
WARNING: Oracle Data Pump operations are not typically needed when connected to the
root or seed of a container database.
GIRI
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 128 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
. . exported "HARI"."BANGALORE" 5.531 KB 5 rows
. . exported "HARI"."HYD" 5.523 KB 5 rows
Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is:
D:\DATA\HARISCHEMA.DMP
Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Wed Mar 22 15:34:47
2023 elapsed 0 00:00:12
C:\Users\girin>
IMPORT
GIRI
18.SQL*LOADER
C:\Users\girin>sqlldr
Valid Keywords:
C:\Users\girin>
Task 1:
sample sqlloader control file
GIRI
Download a sample textfile have lots of lorem data size ~2mb
https://www.learningcontainer.com/download/sample-text-file/
2) create a table in sqlplus which you mensioned in the sqlldr control file
3)
GIRI
Create temporary tablespace
Target machine :
➢ SSH [email protected]
GIRI
C:\Windows\System32>ssh [email protected]
ssh: connect to host 172.20.10.4 port 22: Connection refused
ON Linux machine I have installed OpenSSH client and OpenSSH server components
➢ Sudo apt install openssh-client
➢ Sudo apt install openssh-server
➢ Systemctl status httpd
C:\Windows\System32>ssh [email protected]
The authenticity of host '172.20.10.4 (172.20.10.4)' can't be established.
ED25519 key fingerprint is SHA256:pwoqBCQFlvoMNA4EM0aogJzgeMrrwyKYyWorqTxli9U.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '172.20.10.4' (ED25519) to the list of known hosts.
[email protected]'s password:
Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 6.5.0-45-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
giri@ubuntu:~$ su -
Password:
root@ubuntu:~#
GIRI