Oracle DBA 19C Administration
Oracle DBA 19C Administration
Error.txt
you can use the below command that will that will indent the hostname to the file for faster action.
ip hostname FQDN
oracle-db01
step 2, install required packages
the there is some prerequisites packages that need to be installed you can copy whole script and past it in the terminal
yum install -y bc
yum install -y binutils
yum install -y compat-libcap1
yum install -y compat-libstdc++-33
yum install -y dtrace-modules
yum install -y dtrace-modules-headers
yum install -y dtrace-modules-provider-headers
yum install -y dtrace-utils
yum install -y elfutils-libelf
yum install -y elfutils-libelf-devel
yum install -y fontconfig-devel
yum install -y glibc
yum install -y glibc-devel
yum install -y ksh
yum install -y libaio
yum install -y libaio-devel
yum install -y libdtrace-ctf-devel
yum install -y libXrender
yum install -y libXrender-devel
yum install -y libX11
yum install -y libXau
yum install -y libXi
yum install -y libXtst
yum install -y libgcc
yum install -y librdmacm-devel
yum install -y libstdc++
yum install -y libstdc++-devel
yum install -y libxcb
yum install -y make
yum install -y net-tools
yum install -y nfs-utils
yum install -y python
yum install -y python-configshell
yum install -y python-rtslib
yum install -y python-six
yum install -y targetcli
yum install -y smartmontools
yum install -y sysstat
you can also use the bellow command that will install the required package but will not consider only the default data path and
user , which limit our ability to modify the installation.
yum install -y oracle-database-preinstall-19c
it will installed the default path and default setting so that why we are using the manual way to install packages.
I have run the command again to make sure that group are done
This should allow Oracle to be installed and make changes on the OS level.
As User Oracle
nano /etc/selinux/config
set SELINUX=permissive
selinuix
setenforce Permissive
step 6 disable the firewall
mkdir -p /u01/app/oracle/product/12.2.1
chown -R oracle:oinstall /u01/app/oracle/product/12.2.1
chmod -R 775 /u01/app/oracle/product/12.2.1
nano /home/oracle/.bash_profile
# Oracle Settings
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=db
export ORACLE_UNQNAME=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/19c/db_1
export ORA_INVENTORY=/u01/app/oraInventory
export ORACLE_SID=orcl
export PDB_NAME=pdorcl
export DATA_DIR=/u01/oradata
export PATH=/usr/sbin:/usr/local/bin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
step 9 upload oracle db. installation
upload the database file and move the file to using the oracle user****
then copy the file to the below directory we have created before
note : above prosses must be done using oracle user and not the root
/u01/app/oracle/product/19c/db_1/
then unzip the file make sure all this steps must be run using the oracle user
run the installer
./runInstaller
note : When dealing with Oracle installation on a server running a non-GUI (Graphical User Interface) operating system, a
different approach is needed. In this scenario, the absence of a GUI means you can't directly interact with the installer through
graphical means.
To overcome this limitation, you'll have to initiate an SSH (Secure Shell) connection from a separate device that does have a
GUI and is equipped with Java JDK (Java Development Kit). This secondary device will serve as your remote control center for
the installation process.
next window also you have to confirm inventory directory to be same in the server , also confirm the group 'oinstall' must be
available on sever
next window will ask about global database , just make
next window will ask where to store data , just confirm and click next
next window root script execution , there some script that need privileged user to execute the window will ask to provide root
username and password or a user that have sedure privilege , uncheck mark automatly run he configuration and click next means
there possible chance the installation will failed , check mark it and provide either root or suder username and password
connecting to oracle dba
to connect to oracle database make sure your running using oracle & use the below command
sqlplus sys/sys as sysdba
show user
startup
once done the "database open "must show means the database is online
installing oracle sql developer
for sql developer to work you must install java jdk
first extract the sqldeveloper zip file .
Connecting to database
connect to database remotely :
if you have application server , in this case we will provide connection parameter to application server to connect to database . this
similar to what we did with sql developer application
listener
is responsible for communication between the client and database engine , listener handle the authenticating by communicating
with database engine and allow the privilege base on permission the user has
lsnrctl stop
lsnrctl start
from the configuration you can make multitap lisnter or reconfigure the lisnter
the port has not changed we will change it and restart the listener and shut down and start the database
shutdown immediate
startup
add more listener port netmgr
if you have multiple interface you can configure multiple listener to acuminate the interface , this is done by using netmgr .
the window will open expand the window till you reach listener and click + green sing
give friendly name
then click add address and then give random port and then click ok
lsnrctl start ahmed
shared pool
it response of taking the query and execute the query on data folder and return the result
large pool
similar to shared pool but specified for large query's with loops inside of it .
buffer cache
this is responsible for keep store of result of common executed query to avoid going to the data folder to speed up the process of
query executing , also reduce CPU usage .
the query that goes to shared pool to be executed , if the query is getting executed many time , then shared pool will send the
query to buffer cache to keep the result of the query to save time and load .
java pool
responsible for java command & query's
stream pool
reasonable for query contain any media such as photos or videos.
3. managing database instance paramter
how to view the parameters
preciouses to be follow before editing the parameter
taking bckup of psfile
how to edit the parameter
basic parameter
advanced parameter
example 1change java pool parameter.
rollback the configuration
the parameter for configuring the instance such as for spa & pga are found on the below files .
''spfileorcl.ora' & ''initorcle.ora'
this both have all parameter that defined how database run .
there are many parameter in the file you can edit
its not recommended to edit the parameters by opening the ''spfileorcl.ora' & ''initorcle.ora' as the database may not work after
restart
show parameters;
also you can view the parameter from sql developer for better view of the parameter just connect to oracle and issue the same
command .
you will find the path for ''spfileorcl.ora' & ''initorcle.ora' & also you will find parameters for large pool and spa pga
some parameters has dependency such sga pga , you cannot change their parameters with informing the parameter'' memory
target ''
create pfile='path for where you want save the spfile/filename.ora' from spfile;
create pfile ='share/pfile.ora' from spfile;
how to edit the parameter
you will use the command alter follow by parameter name and parameter value .
basic parameter
this are easy to edit parameter such as 'control_file' , 'db_block_size' ,'undo_tablespace' and many more .
advanced parameter
this parameter has some specific steps such as 'shared_pool_size' 'db_cach_size' this parameters are specific for core component
of the database engine .
the parameters here will not take effect unless you restart the instance .
shutdown immediate ;
startup ;
select name , value from v$parameter where name =('java_pool_size');
shutdown immediate
then startup the database using the spfile you took copy of it
startup pfile='/share/pfile.ora';
4. database mode
startup modes
shutdown mode
startup modes
the database mode while starting
1- shutdown :when you startup the server the database will be in shutdown state
2.nomount : when you execute the startup command the instance start will begin and then database will move to nomunt, in the
nomount this will happen
Immediate Shutdown
Normal Shutdown: Think of this as the polite way to shut down Oracle. In normal shutdown mode, the database doesn't accept
new connections, but it waits for existing transactions to complete before closing. It's like letting everyone finish their conversations
before turning off the lights.
-Transactional Shutdown: This mode is even more patient. It allows all transactions to complete, and then it shuts down the
database gracefully. It's like waiting for the last guest to leave the party before cleaning up.
Immediate Shutdown Abort: This one is a bit like yanking the power cord out of your computer. It forcefully terminates the
Oracle database without any regard for ongoing transactions. It's not the recommended way to do it, but sometimes it's
necessary in extreme situations.
5.managed database storage structure
database engine will not talk directory with storage of server when it need to store data in the disk
tablespace
Tablespace
segment
tablespace type
Stores Transactional Data
Undo Tablespace
Temporary Tablespace
Permanent Tablespace
undo tablespace
The redo log employs this tablespace to store transaction data that has not yet been committed. This ensures that in the event of a
rollback, the necessary information is readily available, offering a safeguard against data inconsistencies or incomplete
transactions.
temporary tablespace
The temporary tablespace is harnessed by the buffer pool to house the results of queries that are frequently executed. It acts as a
short-term storage repository for this data, which is eventually purged after its temporary use, ensuring efficient memory
management
premiant tablespace
A 'Permanent Tablespace' is where all the important stuff in a database lives – like tables and their data. It's the safe and stable
home for your valuable information, and it sticks around even when you turn off the computer or close the application. Just
remember, when you want your data to stay put, it goes into the Permanent Tablespace
syntax:
we can use the below query to get the path for tablespace we jut created .
When you've already utilized 80MB out of the 100MB available in a tablespace, issuing a RESIZE command to increase it by
10MB will adjust the tablespace size to 90MB, effectively accommodating the additional storage needed. It doesn't expand the
tablespace to its original 100MB size; instead, it adapts to your storage requirements.
Conversely, if you apply the RESIZE command to a 100MB tablespace that hasn't stored any data, setting it to 10MB will shrink
the tablespace size to match the specified 10MB. In this case, the command alters the tablespace size to exactly what you've
designated, as there is no existing data to consider
syntax:
offline tablespace
this one that will not allow any action t be done on data on tablespace
drop tablespace
there two way to drop
this query doesn't not delete data file it only delete tablespace object
normally in oracle we will create user and then create database under the user this which the called user database.
manging user
there are two type of user security
below are type of privilege you can grant to the user
1. system privilege
is all the privilege that are granted to user to manage the database engine.
2. object privilege
user privilege on another user , if we have user that has table called emp , then I can give other user select privilege on the user
emp table .
In Oracle's SQL syntax, 'GRANT' and 'REVOKE' are SQL statements used to control access and permissions for various
database objects. These objects can include tables, views, procedures, and more. The 'GRANT' statement gives specific
privileges to a user or role, while the 'REVOKE' statement takes those privileges away. Here's a more detailed breakdown:
'privilege': This represents the specific permission you want to grant, such as 'SELECT,' 'INSERT,' 'UPDATE,' 'DELETE,'
or 'CREATE.' You can specify multiple privileges separated by commas.
'object': This refers to the database object (e.g., a table, view, or procedure) on which you want to grant the privileges.
'user': The user or role to whom you're granting the privileges. You can grant to multiple users or roles simultaneously.
'WITH ADMIN OPTION' (optional): When used, this option allows the recipient to further grant the same privileges to
other users or roles. It essentially delegates the privilege management.
2. REVOKE Statement Syntax:
'privilege': Similar to 'GRANT,' this specifies the privilege(s) you want to revoke.
'object': The database object from which you're revoking the privileges.
'user': The user or role from whom you're revoking the privileges.
'CASCADE CONSTRAINTS' (optional): If you're revoking privileges on a table, this option also removes any dependent
constraints owned by the user. Be cautious when using it, as it can have far-reaching consequences.
Here's a practical example. Let's say you want to grant the 'SELECT' and 'INSERT' privileges on the 'employees' table to the user
'Alice' and allow her to further grant these privileges to others:
This command grants 'Alice' both SELECT and INSERT permissions on the 'employees' table and empowers her to pass on these
privileges to additional users if needed.
On the flip side, if you want to remove these privileges from 'Alice,' you'd use the 'REVOKE' statement:
This statement takes away the SELECT and INSERT privileges from 'Alice' on the 'employees' table.
Remember, precise management of privileges is crucial for database security and access control. Always use these commands
with care and according to your database security policies.
example
create user with admin option
i will create user called mg , the another user called sg
i will grant mg create session privilage and adding with admin option so he can grant other user the same privilege .
1. create user
create user mg identified by mg;
2. grant the user create session with admin option
grant create session to mg with admin option
3. create another user that will we use to test with admin option
create user sg identified by sg;
4. login to oracle db using mg user
revoke permission
now we will revoke the permission using
revoke parameter
syntax :
system privilege
In the realm of Oracle Database, these privileges are akin to the ultimate authority, conferring users with the capability to execute
profound administrative operations and wield control over fundamental aspects of the database system. Here's a more in-depth
exploration:
CREATE SESSION: This privilege is fundamental , this allow you to connect to database so it must be exist
this similar to MSSQL public privilege that allow you to connect to the database .
1. SYSDBA: This is the most powerful system privilege, granting full administrative control over the database, including the
ability to start and stop the database, perform backup and recovery operations, and modify database parameters.
2. SYSOPER: A step below SYSDBA, SYSOPER allows for basic database operations such as starting and shutting down the
database. It has fewer administrative capabilities compared to SYSDBA.
3. CREATE SESSION: This privilege is fundamental, allowing users to establish a connection and log in to the database.
Without it, users can't even access the database.
4. CREATE TABLE: Grants the ability to create new tables within a schema. It's often used by application developers to define
data structures.
5. ALTER SYSTEM: Provides the authority to modify certain global database settings and configuration parameters.
6. DROP USER: Permits the removal of user accounts. This privilege is typically held by administrators responsible for user
management.
7. SELECT ANY TABLE: Allows a user to query any table in the database, regardless of ownership. It's useful in scenarios
where users need broad read access.
8. INSERT, UPDATE, DELETE ANY TABLE: These privileges enable users to perform data manipulation operations on any
table in the database, irrespective of ownership.
9. EXECUTE ANY PROCEDURE: Grants the right to execute any stored procedure or function in the database, regardless of
the schema in which it resides.
10. CREATE SESSION, ALTER SESSION: These privileges pertain to session management and configuration, including the
ability to alter one's own session settings.
These system privileges cover a spectrum of actions, from fundamental access (CREATE SESSION) to more advanced
administrative and data manipulation capabilities. They are typically assigned based on a user's role and responsibilities within the
database environment.
object privilege
here you can give privilege on object of the database to do specific action
such as you can give select privilege to user to do select statment on certain table or all tables on object
or update or insert for user to certain table of the database .
example
grant user select statement on table
we will grant select privilege on table called employee to user called mg user
mg
in the role you can assignee mutable privilege and assignee it to users.
Create Role
create role
Create a Role: First, create a role named "Select_Role" using SQL:
Grant SELECT Privilege: Assign the SELECT privilege on the desired table(s) to the "Select_Role". Let's assume you want to
grant SELECT on the employees table in the hr schema:
grant hr_select to mg ;
predefined roles
profile
each user created has preference
cpu-per-session
when user create session it consume cpu
you can edit the amount of cpu the user can consume
cpu-per-call
when you session is open when you make query you will make call to database , here is how many call can user can make.
connection time
how mush time can session can be open if ideal.
fail_login_attempt
how many failed attempt allowed till user is get locked by default is set to 5
8. backup and restore
type of backup
1.export regular
2, data pumb
how to export and import using datapump
1.create directory and marked it in oracle engin
export schema
what does the export contain
import dump file
export dump with password
import and export normal way
export the normal way
import the normal way
type of backup
1.Export regular
it produce dump file 'dmp' extensions
allow to export database and save it in any place with out the need to specfy the dump directory
2, Data pumb
data pump must specify the directory
it also produce dump file 'dmp' extensions
in this case you have to create folder and then go to database engine and specify the directory
create directory dump as '/path '
once you specify the directory this will be only directory to export and import
and also the user must have privilege
the user hr must have dba privilege
grant dba to hr
now login to user for this instance i will login using hr user that have sample schema
and the execute the below command .
CREATE DIRECTORY : This part of the command initiates the creation of a directory object.
dumps : This is the name of the directory object you are creating. You can choose any name that makes sense for your use
case.
AS '/home/oracle/dump2/' : This specifies the actual physical directory path on the server's file system that you want to
associate with the directory object. In this example, the directory object named "dumps" is associated with the path
'/home/oracle/dump2/' on the server.
syntax :
CREATE DIRECTORY directory_name AS 'directory_path';
Export schema
to export the schema is expdp and can only be done through the terminal .
and you will have to fill the directory which we have submitted in database engine .
which dumps
and then fill the filename follow by the file extensions .dmp
syntax
username[/password] : The Oracle username and optional password for the database connection.
@connect_identifier : The connection identifier for the Oracle database.
DIRECTORY=directory_objec t: Specifies the Oracle directory object representing the directory where the export file will be
placed.
DUMPFILE=dumpfile_name : Indicates the name of the dump file to be generated.
Remember to replace username, password, connect_identifier, directory_object, and dumpfile_name with your specific
database and export file details.
the
What does the export contain
the export will contain the table , roles , views , database links ,index.
now we want to export, to achieve that we will need to import the dump under another user
for this purpose i will create user and grant it the necessary privilege .
then I will import hr user dump to that user .
example :
username/password: The Oracle username and password used to connect to the target database.
@connect_identifier: The connection identifier for the Oracle database.
-DIRECTORY=directory_object: Specifies the Oracle directory object representing the directory from which the export file will be
read during import.
DUMPFILE=dumpfile_name: Indicates the full path to the dump file to be used for the import operation.
-REMAP_SCHEMA=source_schema:target_schema: Allows you to map the source schema in the dump file to the target
schema in the database during the import process
so for our case we exported from hr user and planning to import ahmed user
Export dump with password
if you have very critical database with sensitive data that you don't want to be seen by unauthorised people
syntax:
-expdp: This is the command used to invoke Oracle Data Pump, a utility for exporting and importing data in Oracle databases.
-hr/hr@prod: This section specifies the username and password used to connect to the Oracle database. It's in the format
username/password@database. In this case, it's connecting as user hr with the password hr to the prod database.
-schemas=hr: This option specifies the schema (hr) from which data will be exported. A schema is a logical container for database
objects within the Oracle database.
-directory=dumps: Here, you specify the Oracle directory named dumps. This directory should have been previously created in
the database and is used as the location where the Data Pump utility will store the export files.
-dumpfile=[file].dmp: This part defines the name of the dump file that will be generated during the export. You should replace [file]
with your desired file name. The .dmp extension is standard for Oracle Data Pump export files.
-logfile=[name].log: Similar to the dumpfile, this option specifies the name of the log file that will be generated during the export.
Replace [name] with your preferred log file name. The .log extension is commonly used for log files.
-encryption=all: This indicates that data in the export file will be encrypted. The encryption=all option ensures that all exported
data is encrypted for security purposes.
-encryption_password=[password]: Here, you need to specify the encryption password. Make sure to replace [password] with
the actual encryption password you intend to use. This password will be required to decrypt the exported data when needed.
syntax:
example:
Examble: