Oracle Setup

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 8

<font color="#00008b"><u>set hostname</u></font>

hostnamectl set-hostname home


vi /etc/hosts
192.168.201.199 home home.db
Stop Firewall

systemctl stop firewalld


systemctl disable firewalld
systemctl status firewalld

editing the file /etc/selinux/config and


changing the line SELINUX=enforcing to SELINUX=disabled.
Then you need to reboot your system for the changes to take effect.
To check the status of SELinux, you can run sestatus.

to stop selinux till next reboot


sudo setenforce 0

//
reboot

getenforce
//permissive

** set network

nmtui
edit connection of enp0s3

nmcli con down enp0s3 && nmcli con up enp0s3

curl -o compat-openssl10-1.0.2o-3.el8.x86_64.rpm
https://yum.oracle.com/repo/OracleLinux/OL9/latest/x86_64/getPackage/compat-
openssl10-1.0.2o-3.el8.x86_64.rpm

yum -y localinstall compat-openssl10-1.0.2o-3.el8.x86_64.rpm

su - oracle
vi .bash_profile

mkdir -p /d01/app/oracle/product/19.3.0/dbhome
mkdir -p /d02/oradata
chown -R oracle:oinstall /d02 /d02
chmod -R 775 /d01 /d02
export TMP=/tmp
export TMPDIR=$TMP

export ORACLE_HOSTNAME=home.db
export ORACLE_UNQNAME=cdb1
export ORACLE_BASE=/d01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/19.3.0/dbhome
export ORA_INVENTORY=/d01/app/oraInventory
export ORACLE_SID=cdb1
export PDB_NAME=pdb1
export DATA_DIR=/d02/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

Set the environment variable CV_ASSUME_DISTID to a supported OS version, such as


OL7, before running the installer.
For example, you can use the command export CV_ASSUME_DISTID=OL8 in your terminal.
Edit the file $ORACLE_HOME/cv/admin/cvu_config and add a new line
CV_ASSUME_DISTID=OL7, then save the file and run the installer again.

1)CREATE

2)SERVER CLASS
3)ENTERPRISE EDITIOB

SGA_TARGET => ALTER SYSTEM => DEFAULT 0


NLS_DATE_FORMAT => ALTER SESSION =>

CREATE PFILE = '/home/oracle/mypfile.ora' FROM SPFILE;


CREATE SPFILE FROM PFILE = '/home/oracle/mypfile.ora';

** Enabling Automatic Memory Management:

SHOW PARAMETER TARGET

NAME TYPE VALUE


------------------------------------ ----------- ------------------------------
archive_lag_target integer 0
db_big_table_cache_percent_target string 0
db_flashback_retention_target integer 1440
fast_start_io_target integer 0
fast_start_mttr_target integer 0
memory_max_target big integer 0
memory_target big integer 0
parallel_servers_target integer 100
pga_aggregate_target big integer 792M
sga_target big integer 2384M
target_pdbs integer 4

select value /1024 /1024 M from v$pgastat where name='maximum PGA allocated';

memory_target = sga_target + max(pga_aggregate_target, maximum PGA allocated)


= 2384M + 792M

ALTER SYSTEM SET MEMORY_MAX_TARGET= 3200M SCOPE = SPFILE;

SELECT ((SELECT SUM(value) FROM V$SGA) -(SELECT CURRENT_SIZE FROM


V$SGA_DYNAMIC_FREE_MEMORY)) / 1024 / 1024 "SGA_TARGET MB" FROM DUAL;

A CDB contains the following files:


� One control file
� One online redo log
� One or more sets of temp files
� One set of undo data files
� A set of system data files for every container
� Zero or more sets of user-created data files
*** Back and Recovery

Use a fast recovery area, which automates storage management for most backuprelated
files,
and specify it as an archived redo log file destination. Run the database in
ARCHIVELOG mode
so you can perform online backups and have data recovery options such as complete
and point-in-time media recovery.
Oracle recommends placing the fast recovery area on a separate storage device from
the working set of database files.
SCN =>System Change Number
It is great if we have tape backup then we can move some files to tape . But
restore from fra is faster.
To perform backup and recovery tasks with Oracle Recovery Manager (RMAN), you
must connect to the target database as a user with the SYSDBA or SYSBACKUP
administrative privilege.
The SYSBACKUP user.
When you install the database, the SYSBACKUP user, with the SYSBACKUP privilege,
is created automatically.
� Database users to whom you grant the SYSBACKUP privilege.
� Database host users who are members of the OSBACKUPDBA operating system
group�for operating system authentication.
The OSBACKUPDBA group is assigned to a specific operating system group
during database installation. For example, on UNIX and Linux systems, the
backupdba group is typically designated as the OSBACKUPDBA group. Host users
in this group can connect to the target database using operating system
authentication; they do not need to be defined as a database user.
A target database is the Oracle database that must be backed
up or restored using RMAN. Connections to the target database require the SYSDBA or
SYSBACKUP administrative privilege.

When you do not explicitly specify SYSDBA or SYSBACKUP, you are connected to
the target database with the SYSDBA privilege.
=======

rman target /
ALTER SYSTEM SET DB_RECOVERY_FILE_DEST_SIZE = 10G;
ALTER SYSTEM SET DB_RECOVERY_FILE_DEST = '/d01/oracle/fra';

SELECT LOG_MODE FROM V$DATABASE;


SQL> SELECT LOG_MODE FROM V$DATABASE;

LOG_MODE
------------
NOARCHIVELOG

You must ensure that there is sufficient disk space at all times for archived
log file destinations. If the database encounters a disk full error as it attempts
to archive a log file, a fatal error occurs and the database stops responding.
You can check the alert log for a disk full message.

SHUTDOWN DATABASE;
STARTUP MOUNT;
BACKUP DATABASE;

RMAN> BACKUP DATABASE;


ALTER SYSTEM SET LOG_ARCHIVE_DEST_1='LOCATION=/d02/oracle/logfiles';
(Optional) Enter the following command to set the second archived log file
destination:
ALTER SYSTEM SET LOG_ARCHIVE_DEST_2 = 'LOCATION=/d03/oracle/logfiles';
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;
SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
BACKUP DATABSE;
**We have taken another backup because You cannot use backups from before the
switch to ARCHIVELOG mode to
restore and recover the database to a point in time after the switch. Thus, if
you do not immediately make a backup after switching, then you are running
your database without a valid backup.
***Point in time backup
SELECT FLASHBACK_ON FROM V$DATABASE;
SQL> SELECT FLASHBACK_ON FROM V$DATABASE;

FLASHBACK_ON
------------------
NO

ALTER SYSTEM SET DB_FLASHBACK_RETENTION_TARGET=4320;


ALTER DATABASE FLASHBACK ON;

***Configure Backup

CONFIGURE DEFAULT DEVICE TYPE TO DISK;

Specify that the backups must be stored on disk in the form of backup sets. Also
set the parallelism to 1.
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO BACKUPSET PARALLELISM 1;

Backups on disk can be stored in the form of backup sets or image copies. Image
copies are exact copies of database files. They are not stored in an RMAN-specific
format and can be used as-is to perform recovery. Backup sets use an RMANspecific
format. With backup sets, RMAN uses unused block compression to save
space by backing up only the blocks that contain data. RMAN can also encrypt
backups and create incremental backups.

To configure automatic backups for the control file and server parameter file:

CONFIGURE CONTROLFILE AUTOBACKUP ON;

Configure backup optimization to save space in the fast recovery area.


Optimization excludes unchanged files, such as read-only files and offline data
files, that were previously backed up.
CONFIGURE BACKUP OPTIMIZATION ON;

The following command specifies that the backups and archived logs must be
retained for 31 days.
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 31 DAYS;

Specify that archived logs can be automatically deleted only when they have been
backed up to tape or are obsolete based on the retention policy by using the
following command.
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE;

To determine if block change tracking is enabled, check the STATUS and FILENAME
columns in the V$BLOCK_CHANGE_TRACKING view, using the following statement from the
SQL or RMAN prompt:
SELECT status, filename FROM V$BLOCK_CHANGE_TRACKING;

Determine the current location of the database data files by submitting the
following query:
RMAN> SELECT NAME FROM V$DATAFILE;

Set the DB_CREATE_FILE_DEST initialization parameter to specify the location where


new database files, including the block change tracking file, must be stored.

ALTER SYSTEM SET DB_CREATE_FILE_DEST = '/d01/app/oracle/oradata';

Enable block change tracking for the database using the following command:
ALTER DATABASE ENABLE BLOCK CHANGE TRACKING;

Optionally, specify the tablespaces that must be excluded from backups.


The following command excludes the tablespace example from backups.

CONFIGURE EXCLUDE FOR TABLESPACE example;

If the database runs in ARCHIVELOG mode, then an autobackup is also taken whenever
the database structure metadata in the control file changes.

CONFIGURE CONTROLFILE AUTOBACKUP ON;

BACKUP DATABASE PLUS ARCHIVELOG;

# /usr/sbin/groupadd -g 54324 backupdba

tail /etc/group
slocate:x:21:
tcpdump:x:72:
sajib:x:1000:
oinstall:x:54321:oracle
dba:x:54322:oracle
oper:x:54323:oracle
backupdba:x:54324:oracle
dgdba:x:54325:oracle
kmdba:x:54326:oracle
racdba:x:54330:oracle

usermod -aG backupdba oracle


usermod -aG 54324 oracle
chgrp -R backupdba /d01/app/oracle/rman/
chmod -R 2775 /d01/app/oracle/rman/

*** startup
alter session set container=pdb1;
alter pluggable database pdb1 open;
alter user hr identified by hr account unlock;

select * from dba_scheduler_job_run_details;


select * from dba_scheduler_running_jobs;

. oraenv
sqlplus / as sysdba
lsnrctl start
sqlplus system/oracle@home:1521/pdb1
create user jim identified by jim;
create user tom identified by tom;
create user ann identified by ann;

create role HR_MGR;


create role SALES_CLERK;
create role ANALYST;

grant create session to jim, tom, ann;


grant select, update, delete, insert on hr.employees to HR_MGR;
grant HR_MGR to JIM;
grant select on sh.sales to SALES_CLERK;
grant SALES_CLERK to TOM;
grant select any table to ANALYST;
grant ANALYST to ann;

***Flashback:

Configure fast recovery area and set a fast retention target.

BEFORE APPPLYING "ALERT DATABASE OPEN RESETLOGS;" must need to be confirmed about
the flashback point.

archive log list;


select log_mode from v$database;
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
archive log list;
alter database force logging;
alter database flashback on;
select flashback_on from v$database;
show parameter DB_FLASHBACK_RETENTION_TARGET;
alter system set db_flashback_retention_target=4320,scope=both;
alter tablespace tbs_data flashback on;
drop table test_tab1;
select object_name,original_name,operation,droptime from user_recyclebin;
flash table test_tab1 to before drop;

Go back to container database;


select current_scn from v$database;

connect to pluggable database

sqlpus sys/oracle@home:1521/pdb1;
drop table test_tab1 purge;

Go back to container db
sqlplus sys / as sysdba;
shutdown immediate;
startup mount;
flashback database to scn xyz;
alter database open resetlogs;

***SQL
LISTAGG FUNCTION

select listagg(first_name,'-') within group (order by first_name) "Employees" from


employees where job_id='st_clark';

Query Execution order:

From
Where
Group By
Having
Select
Order By

Group By Clasue:

All the single column in select must be in group by clause but all the fields in
group by clause not necessarily
We can not use where clause in group data because where clasue comes before group
by in execution order.
having clause comes before order by .
Nest group function not works if any single row column is in select clause and also
it not works if no group by clause in command.

***TABLESPACES:
Three types:
Permanent=>Persistent schema objects
Undo=> Undo data automatic undo management mode
Temporary=> Temporary for a session

'autoextend on' clause to automatically grow tablespace


'online' or 'offline' clause to make the tablespace available on creation or not
'blocksize' to apply non standard block size
include LOGGING clause to control loggin of dml operations in redo log. it is
available for Permanent tbs

command:

create tablespace pdb_user01 datafile 'u01/app/oracle/19.3/.../ssdsd.dbf' size 1M


autoextend on next 10M maxsize 10g;
create table t1(id INT generated always as identity, column1 VARCHAR2(32))
tablespace orcl_pdb_users;

BEGIN
FOR count IN 1..100000 loop
INSERT INTO T1(COLUMN1)
VALUES(sys_guid());
END loop;
END;
/

select tablespace_name,bytes /1024 /1024 MB FROM dba_free_space where


tablespace_name='ORCL_PDB_USERS';

ALTER TABLESPACE DATAFILE 'XYZ' RESIZE 10M;


DBA_TABLESPACES
DBA_DATAFILES
DBA_TEMP_FILES
V$TABLESPACE

**You must login as SYS or SYSTEM to perform sehutdown and startup operation. If
SYS then LOGON as SYSDBA.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy