Wednesday, February 1, 2023

Audit Unsuccessful Logins

Audit Unsuccessful Logins


select username,os_username, userhost, client_id, trunc(timestamp),count(*) failed_logins from dba_audit_trail

where returncode=1017 and --1017 is invalid username/password timestamp > sysdate -7 group by username,os_username,userhost, client_id,trunc(timestamp);

To get more details on the record found for "ALTER USER" command issued:


SET ECHO OFF
SET MARKUP HTML ON SPOOL ON
SPOOL /tmp/AUDIT_INFO.html
select * from dba_audit_trail where action_name='ALTER USER' and timestamp> sysdate-10;
select * from unified_audit_trail where EVENT_TIMESTAMP > sysdate-10;


SPOOL OFF
SET MARKUP HTML OFF
SET ECHO ON
Alter user commad from dba_audit_trail:

SQL> select username,TIMESTAMP,ACTION_NAME,RETURNCODE,SQL_TEXT from dba_audit_trail where ACTION_NAME like '%ALTER USER%';

How to check the password_verify_function:

set lines 170
col owner format a30
col name format a45
col text format a50
select * from dba_source where owner = 'SYS' and name in(select limit from dba_profiles where resource_name = 'PASSWORD_VERIFY_FUNCTION' and limit <> 'NULL') order by name, line;


How to check the dba profile from sqlplus:

set lines 170
col profile format a20
col limit format a30
select PROFILE, RESOURCE_NAME, RESOURCE_TYPE, LIMIT from dba_profiles where PROFILE='<Profile_name>';


How to check the user status and details:
SQL> select USERNAME, ACCOUNT_STATUS, LOCK_DATE, EXPIRY_DATE, PROFILE from dba_users where username ='User_name';


How to check the last_login details:

SQL> SELECT USERNAME, LAST_LOGIN FROM DBA_USERS WHERE USERNAME='User_name';

Saturday, December 31, 2022

RAC Installation Step By Step

RAC Installation Step By Step


All steps will be carried out on one of the node (node1) and later we will clone to other nodes or machines:

Install the system Linux prerequisites:

The package oracle-database-preinstall-19c contains all the prerequisites on Oracle Linux using the Oracle Unbreakable Enterprise Kernel (UEK).

yum install -y oracle-database-preinstall-19c
yum install -y oracleasm-support

sysctl -p
crosscheck >>> cat /etc/sysctl.conf

Group Creation: –

groupadd -g 5001 oinstall
groupadd -g 5002 dba
groupadd -g 5003 oper
groupadd -g 5004 asmadmin
groupadd -g 5005 asmdba
groupadd -g 5006 asmoper

User Creation: –

useradd -u 5007 -g oinstall -G dba,oper,asmdba oracle
useradd -u 5008 -g oinstall -G asmadmin,asmdba,asmoper,dba grid
usermod -g oinstall -G dba,oper,asmdba oracle
usermod -g oinstall -G asmadmin,asmdba,asmoper,dba grid

passwd oracle
passwd grid

Add below entries in /etc/security/limits.conf file which will detine limits

oracle soft nofile 1024
oracle hard nofile 65536
oracle soft nproc 16384
oracle hard nproc 16384
oracle soft stack 10240
oracle hard stack 32768
oracle hard memlock 134217728
oracle soft memlock 134217728

grid soft nofile 1024
grid hard nofile 65536
grid soft nproc 16384
grid hard nproc 16384
grid soft stack 10240
grid hard stack 32768
grid hard memlock 134217728
grid soft memlock 134217728

Create the directories in which the Oracle / Grid software will be installed.

mkdir -p /u01/app/grid
mkdir -p /u01/app/19c/gridhome_1
mkdir -p /u02/app/oracle
mkdir -p /u02/app/oracle/product/19c/dbhome_1
mkdir -p /u01/app/oraInventory
mkdir -p /u01/LATEST_PATCH/
chown -R grid:oinstall /u01
chown -R oracle:oinstall /u02
chown -R grid:oinstall /u01/app/oraInventory
chmod -R 775 /u01
chmod -R 775 /u02

Set bash_profile for grid and oracle user

login to grid user and set .bash_profile :

export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/19c/gridhome_1
export ORACLE_SID=+ASM1
export ORACLE_TERM=xterm
export BASE_PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$BASE_PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

login to oracle user and set .bash_profile :

export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_BASE=/u02/app/oracle
export ORACLE_HOME=/u02/app/oracle/product/19c/dbhome_1
export ORACLE_SID=racdb1
export ORACLE_TERM=xterm
export BASE_PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$BASE_PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib


Add the following entry in /etc/hosts file and crosscheck node reachability

Primary Site:

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

# Private

192.168.10.1 node1-priv.localdomain node1-priv
192.168.10.2 node2-priv.localdomain node2-priv

# Public

192.168.56.71 node1.localdomain node1
192.168.56.72 node2.localdomain node2

# Virtual

192.168.56.81 node1-vip.localdomain node1-vip
192.168.56.82 node2-vip.localdomain node2-vip

# SCAN

192.168.56.91 node-scan.localdomain node-scan
192.168.56.92 node-scan.localdomain node-scan
192.168.56.93 node-scan.localdomain node-scan

Firewall Stop and Disable

We can open firewall after installation

systemctl stop firewalld.service
systemctl disable firewalld.service

Chrony NTP Configuration

systemctl enable chronyd.service
systemctl restart chronyd.service


Verify the network reachability using ping command:

From Node1:
ping node2
ping node2-priv

From Node2:
ping node1
ping node1-priv

Create shared ASM Disk FOR OCR, DATAFILE and ARCHIVE on Both Sites.

Add new shared disk to virtual box machines it should be sharable

Login to system and run ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb
fdisk /dev/sdb

The sequence of answers is "n", "p", "1", "Return", "Return" and "w".

Set ASM disks >>>> oracleasm configure -i
Create ASM disks >>>> oracleasm createdisk ASM1 /dev/sdb1
Scan ASM disks >>>> oracleasm scandisks
List ASM disks >>>> oracleasm listdisks

######### On Primary Site ##########

Copy software to node1 on primary site and unzip software at grid home location and rdbms home locations by login to respective users.

Setup passwordless ssh configuration

cd /u01/app/19c/gridhome_1/deinstall
./sshUserSetup.sh -user grid -hosts "node1 node2" -noPromptPassphrase -confirm -advanced

Similarly do it for oracle user

cd /u02/app/oracle/product/19c/dbhome_1/deinstall

./sshUserSetup.sh -user oracle -hosts "node1 node2" -noPromptPassphrase -confirm –advanced
./sshUserSetup.sh -user root -hosts "node1 node2" -noPromptPassphrase -confirm –advanced

Set profile and go to ORACLE_HOME location from grid user and run following command and follow the steps.

cd $ORACLE_HOME
./gridSetup.sh -applyRU /u01/LATEST_PATCH/32545008

Once Grid Installation done, Install RDBMS Software through oracle user and create RAC database on production (PROD).

./runInstaller -applyRU /u01/LATEST_PATCH/32545008
Use DBCA to create database PROD.

Physical Standby Creation Steps For Single Instance

Physical Standby Creation Steps For Single Instance



Tuesday, December 27, 2022

How to check the OS user status

How to check the OS user status


linux chage -l username ---------------> Linux
passwd -s username --------------> Solaris

chage -l oracle

Last password change : Sep 18, 2022
Password expires : Dec 17, 2022
Password inactive : Mar 17, 2023
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 90
Number of days of warning before password expires : 7

chage -l grid

Last password change : Jul 21, 2022
Password expires : Oct 19, 2022
Password inactive : Jan 17, 2023
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 90
Number of days of warning before password expires : 7



How to find large files

How to find large files


$ cd $ORACLE_HOME

$ find . -ls | sort -nrk7 | head -10
$ find . -ls | sort -nrk7 | head -10
$ du -S . | sort -nr | head -10





Find recently modified tables in Oracle database

Find recently modified tables in Oracle database



select a.OWNER, a.SEGMENT_NAME "TABLE_NAME", B.OBJECT_TYPE,b.CREATED, b.LAST_DDL_TIME "MODIFIED" , a.BYTES/1024/1024 "SIZE_MB"
from dba_segments a, dba_objects b
where a.OWNER=B.OWNER
AND A.SEGMENT_NAME=B.OBJECT_NAME
AND A.SEGMENT_TYPE=B.OBJECT_TYPE
and a.owner not in (select name from system.logstdby$skip_support where action = 0);



select tab.owner as table_schema,
       tab.table_name,
       obj.last_ddl_time as last_modify
from all_tables tab
join all_objects obj on tab.owner = obj.owner
     and tab.table_name = obj.object_name
where tab.owner not in ('ANONYMOUS','CTXSYS','DBSNMP','EXFSYS', 'LBACSYS',
     'MDSYS', 'MGMT_VIEW','OLAPSYS','OWBSYS','ORDPLUGINS', 'ORDSYS','OUTLN',
     'SI_INFORMTN_SCHEMA','SYS','SYSMAN','SYSTEM','TSMSYS','WK_TEST',
     'WKSYS','WKPROXY','WMSYS','XDB','APEX_040000','APEX_PUBLIC_USER','DIP',
     'FLOWS_30000','FLOWS_FILES','MDDATA', 'ORACLE_OCM', 'XS$NULL',
     'SPATIAL_CSW_ADMIN_USR', 'SPATIAL_WFS_ADMIN_USR', 'PUBLIC')
      and obj.last_ddl_time > (current_date - INTERVAL '60' DAY)
order by last_modify desc;



COLUMN TABLE_NAME FORMAT A32
COLUMN OBJECT_NAME FORMAT A32
COLUMN OWNER FORMAT A10

SELECT
   owner, 
   table_name, 
   TRUNC(sum(bytes)/1024/1024) Meg,
   ROUND( ratio_to_report( sum(bytes) ) over () * 100) Percent
FROM
(SELECT segment_name table_name, owner, bytes
 FROM dba_segments
 WHERE segment_type IN ('TABLE', 'TABLE PARTITION', 'TABLE SUBPARTITION')
 UNION ALL
 SELECT i.table_name, i.owner, s.bytes
 FROM dba_indexes i, dba_segments s
 WHERE s.segment_name = i.index_name
 AND   s.owner = i.owner
 AND   s.segment_type IN ('INDEX', 'INDEX PARTITION', 'INDEX SUBPARTITION')
 UNION ALL
 SELECT l.table_name, l.owner, s.bytes
 FROM dba_lobs l, dba_segments s
 WHERE s.segment_name = l.segment_name
 AND   s.owner = l.owner
 AND   s.segment_type IN ('LOBSEGMENT', 'LOB PARTITION')
 UNION ALL
 SELECT l.table_name, l.owner, s.bytes
 FROM dba_lobs l, dba_segments s
 WHERE s.segment_name = l.index_name
 AND   s.owner = l.owner
 AND   s.segment_type = 'LOBINDEX')
WHERE owner in UPPER('&owner')
GROUP BY table_name, owner
HAVING SUM(bytes)/1024/1024 > 10  /* Ignore really small tables */
ORDER BY SUM(bytes) desc
;

-- Tables + Size MB
select owner, table_name, round((num_rows*avg_row_len)/(1024*1024)) MB 
from all_tables 
where owner not like 'SYS%'  -- Exclude system tables.
and num_rows > 0  -- Ignore empty Tables.
order by MB desc -- Biggest first.
;


--Tables + Rows
select owner, table_name, num_rows
 from all_tables 
where owner not like 'SYS%'  -- Exclude system tables.
and num_rows > 0  -- Ignore empty Tables.
order by num_rows desc -- Biggest first.
;

SELECT * FROM (
  SELECT
    owner, object_name, object_type, table_name, ROUND(bytes)/1024/1024 AS meg,
    tablespace_name, extents, initial_extent,
    ROUND(Sum(bytes/1024/1024) OVER (PARTITION BY table_name)) AS total_table_meg
  FROM (
    -- Tables
    SELECT owner, segment_name AS object_name, 'TABLE' AS object_type,
          segment_name AS table_name, bytes,
          tablespace_name, extents, initial_extent
    FROM   dba_segments
    WHERE  segment_type IN ('TABLE', 'TABLE PARTITION', 'TABLE SUBPARTITION')
    UNION ALL
    -- Indexes
    SELECT i.owner, i.index_name AS object_name, 'INDEX' AS object_type,
          i.table_name, s.bytes,
          s.tablespace_name, s.extents, s.initial_extent
    FROM   dba_indexes i, dba_segments s
    WHERE  s.segment_name = i.index_name
    AND    s.owner = i.owner
    AND    s.segment_type IN ('INDEX', 'INDEX PARTITION', 'INDEX SUBPARTITION')
    -- LOB Segments
    UNION ALL
    SELECT l.owner, l.column_name AS object_name, 'LOB_COLUMN' AS object_type,
          l.table_name, s.bytes,
          s.tablespace_name, s.extents, s.initial_extent
    FROM   dba_lobs l, dba_segments s
    WHERE  s.segment_name = l.segment_name
    AND    s.owner = l.owner
    AND    s.segment_type = 'LOBSEGMENT'
    -- LOB Indexes
    UNION ALL
    SELECT l.owner, l.column_name AS object_name, 'LOB_INDEX' AS object_type,
          l.table_name, s.bytes,
          s.tablespace_name, s.extents, s.initial_extent
    FROM   dba_lobs l, dba_segments s
    WHERE  s.segment_name = l.index_name
    AND    s.owner = l.owner
    AND    s.segment_type = 'LOBINDEX'
  )
  WHERE owner = UPPER('&owner')
)
WHERE total_table_meg > 10
ORDER BY total_table_meg DESC, meg DESC
/


SELECT
   owner, table_name, TRUNC(sum(bytes)/1024/1024/1024) GB
FROM
(SELECT segment_name table_name, owner, bytes
FROM dba_segments
WHERE segment_type in  ('TABLE','TABLE PARTITION')
UNION ALL
SELECT i.table_name, i.owner, s.bytes
FROM dba_indexes i, dba_segments s
WHERE s.segment_name = i.index_name
AND   s.owner = i.owner
AND   s.segment_type in ('INDEX','INDEX PARTITION')
UNION ALL
SELECT l.table_name, l.owner, s.bytes
FROM dba_lobs l, dba_segments s
WHERE s.segment_name = l.segment_name
AND   s.owner = l.owner
AND   s.segment_type IN ('LOBSEGMENT','LOB PARTITION')
UNION ALL
SELECT l.table_name, l.owner, s.bytes
FROM dba_lobs l, dba_segments s
WHERE s.segment_name = l.index_name
AND   s.owner = l.owner
AND   s.segment_type = 'LOBINDEX')
---WHERE owner in UPPER('&owner')
GROUP BY table_name, owner
HAVING SUM(bytes)/1024/1024 > 10  /* Ignore really small tables */
ORDER BY SUM(bytes) desc;




SELECT * FROM (
  SELECT
    owner, object_name, object_type, table_name, ROUND(bytes)/1024/1024 AS meg,
    tablespace_name, extents, initial_extent,
    ROUND(Sum(bytes/1024/1024) OVER (PARTITION BY table_name)) AS total_table_meg
  FROM (
    -- Tables
    SELECT owner, segment_name AS object_name, 'TABLE' AS object_type,
          segment_name AS table_name, bytes,
          tablespace_name, extents, initial_extent
    FROM   dba_segments
    WHERE  segment_type IN ('TABLE', 'TABLE PARTITION', 'TABLE SUBPARTITION')
    UNION ALL
    -- Indexes
    SELECT i.owner, i.index_name AS object_name, 'INDEX' AS object_type,
          i.table_name, s.bytes,
          s.tablespace_name, s.extents, s.initial_extent
    FROM   dba_indexes i, dba_segments s
    WHERE  s.segment_name = i.index_name
    AND    s.owner = i.owner
    AND    s.segment_type IN ('INDEX', 'INDEX PARTITION', 'INDEX SUBPARTITION')
    -- LOB Segments
    UNION ALL
    SELECT l.owner, l.column_name AS object_name, 'LOB_COLUMN' AS object_type,
          l.table_name, s.bytes,
          s.tablespace_name, s.extents, s.initial_extent
    FROM   dba_lobs l, dba_segments s
    WHERE  s.segment_name = l.segment_name
    AND    s.owner = l.owner
    AND    s.segment_type = 'LOBSEGMENT'
    -- LOB Indexes
    UNION ALL
    SELECT l.owner, l.column_name AS object_name, 'LOB_INDEX' AS object_type,
          l.table_name, s.bytes,
          s.tablespace_name, s.extents, s.initial_extent
    FROM   dba_lobs l, dba_segments s
    WHERE  s.segment_name = l.index_name
    AND    s.owner = l.owner
    AND    s.segment_type = 'LOBINDEX'
  )
  WHERE owner = UPPER('&owner')
)
WHERE total_table_meg > 10
ORDER BY total_table_meg DESC, meg DESC
/