Tuesday, August 13, 2019

Mysql release version EOL support details..

To check release version EOL support:

http://www.oracle.com/us/support/library/lifetime-support-technology-069183.pdf


To check release versions: similar

https://dev.mysql.com/doc/relnotes/mysql/8.0/en/

https://dev.mysql.com/doc/relnotes/mysql/5.7/en/


Hope this helps....

Mysql upgrade from 5.7.XX to 5.7.27

Below you can find the steps to upgrade Mysql 5.7.xx to 5.7.27.

Here we are using In-Place Upgrade. which means we are upgrading the mysql version on the existing server only which is completely different from logical upgrade.

1)

First download right version of Mysql software. do this.

Go to Patches and downloades -> click product or family -> enter Mysql in product and check release you want(5.7.27) -> platform that you need (here it is linux) -> select description  and enter 5.7.27 -> search.

download the zip version(here it is linux)

p30076436_570_Linux-x86-64.zip

2)  Unzip p30076436_570_Linux-x86-64.zip

3) check what rpm's are installed on your server for mysql by doing this
rpm -qa  mysql* or use rpm -V mysql*

4) when you are about to upgrade. Take VM snapshot or take a backup of mysql data.

5) login into mysql and check below variables setting.

show variables like 'innodb_fast_shutdown';

6) run below command to set below variable.
mysql -u root -p --execute="SET GLOBAL innodb_fast_shutdown=0"

7)
mysqladmin -u root -p  shutdown   or systemctl stop mysqld  (as root)
ps -ef| grep mysqld

8) use below command to upgrade all the rpm's(with dependencies). check the list you have to upgrade and edit the below command.  run as "root "

rpm -Uhv mysql-commercial-{server,libs,libs-compat,client,common,embedded,embedded-compat}-5.7.27-1.1.el7.x86_64.rpm

9) once rpms are installed with no errors. start mysql 
systemctl start mysqld    --- as root (you can use sudo commands if you have to)

monitor mysqld.log... if you see this below messages.. ignore for now and proceed to next step.
(  output from mysqld.log
 [Warning] InnoDB: Table mysql/innodb_table_stats has length mismatch in the column name table_name.  Please run mysql_upgrade
[Warning] InnoDB: Table mysql/innodb_index_stats has length mismatch in the column name table_name.  Please run mysql_upgrade
)

10) run mysql upgrade command and monitor all tables. they should resturn "OK" and "Upgrade process completed successfully"  in the end.

mysql_upgrade -u root -p

12) do this step only if you seeing the above similar warnings only after mysql_upgrade.
 drop table mysql.innodb_index_stats;
 drop table mysql.innodb_table_stats;

and run the mysql_upgrade -u root -p

12) Post checks after upgrade.
select version();
show databases;
select count(*) from table_name;

13). bounce mysql.


Hope this helps....


Wednesday, July 31, 2019

Auto - CPU Parallel calculation

Below is the script to get the available CPU's from the allotted servers based on Number of Instances on that server:


Script:-

total_cpu=`lscpu | grep ^'CPU(s)' | awk '{print $2}'`
cpu_used=$(top -b -n2 -p 1 | fgrep "Cpu(s)" | tail -1 | awk -F'id,' -v prefix="$prefix" '{ split($1, vs, ","); v=vs[length(vs)]; sub("%", "", v); printf "%s%.1f%%\n", prefix, 100 - v }' | sed 's/%//g')

used_cpus=`echo "$total_cpu*$cpu_used*0.01"|bc`
avail_cpus=`echo "$total_cpu-$used_cpus" | awk '{print int($1)}'`

num_inst=`pgrep -al pmon |egrep -v '(^#|\+|\-)' |awk '{print $2}' |wc -l`

if [[ "$avail_cpus" -le 1 ]]; then
 echo "consider Default"
 CHNLS=1
 echo $CHNLS
  else
     if [[ "$num_inst" -lt 2 ]] ; then
       echo "consider 90 percent"
       avail_cpu2con=`echo "$avail_cpus*0.9"|bc`
       CHNLS=`echo $avail_cpu2con | awk '{print int($1)}'`
       echo $CHNLS

      else
          if [[ "$num_inst" -ge 2 ]] && [[ "$num_inst" -le 4 ]] ; then
             echo "consider 75 percent"
             avail_cpu2con=`echo "$avail_cpus*0.75"|bc`
             CHNLS=`echo $avail_cpu2con | awk '{print int($1)}'`
             echo $CHNLS
           else
              echo " consider 60 percent"
              avail_cpu2con=`echo "$avail_cpus*0.60"|bc`
              CHNLS=`echo $avail_cpu2con | awk '{print int($1)}'`
              echo $CHNLS
         fi
    fi
fi



Hope this helps..... suggest if any improvements are needed.

Sunday, June 2, 2019

resize alert log for each database using script.

This script automatcally back's up exisitng alert log to a location you need(BKP_ALT_DIR)  and resize the alert log to 0.



code of the script:


COMMAND=$0
PGM=${COMMAND##*/}
DATE=$(date "+%Y%m%d")
hostname=`hostname -s`
PWD=`pwd`
repdir=$PWD
LOG=$repdir/logs

################ Change Retention Here ###########

BKP_ALT_DIR=/backup/2_week/$hostname/ALERT_BKP

############ Done ########################


# Log directory checks:

if [ ! -d ${LOG} ]
 then
    mkdir -p $LOG
  else
    rm $LOG/*log
fi

if [ ! -d ${BKP_ALT_DIR} ]
 then
    mkdir -p $BKP_ALT_DIR
fi


# copying alert log files to desired folder:

  for db in `cat /etc/oratab| egrep -v '(^#|\+|\-)'|cut -f1 -d: -s|egrep -v 'OMS'|egrep -v 'AGENT'`
       do
         db_check=`pgrep -al pmon|grep $db |cut -f3,4 -d_`
          if [ -n "$db_check" ]
              then
              echo $db
              db_sid=$db_check
              l_db=`echo $db | tr [A-Z] [a-z]`
               alert_dir=/opt/oracle/diag/rdbms/$l_db/$db_check/trace
                  cd $alert_dir
                  echo $alert_dir
                  echo "$BKP_ALT_DIR"
                  cp alert_$db_check.log $BKP_ALT_DIR/alert_"$db_check"_$DATE.log
                echo "alert_$db_check.log copy is done for $db" >>$LOG/DB_up_list.log
            ready=0
              while [ $ready -eq 0 ]
                   do
                 if [ `lsof | grep /opt/oracle/diag/rdbms/$l_db/$db_check/trace/alert_$db_check.log |grep -v tail |wc -l` != 0 ];
                           then
                         echo "`lsof | grep /opt/oracle/diag/rdbms/$l_db/$db_check/trace/alert_$db_check.log |grep -v tail |wc -l`"
                            ready=0
                              sleep 5
                    else
                            ready=1
                  fi
              done
                  echo "resetting alert_$db_check.log for $db" >>$LOG/DB_up_list.log
                  > alert_$db_check.log
                  echo "alert_$db_check.log reset for $db is done" >>$LOG/DB_up_list.log
           else
               echo "$db" >>$LOG/exclude_list.log
          fi
   done

echo "completed:" >>$LOG/DB_up_list.log


Hope this helps......

Thursday, May 30, 2019

How To Know the Current Patches released

Steps to find what current patches released as of Date:

Oracle Database:

  1. Login to oracle support
  2. Type 1454618.1 and hit search
  3. Select  the option you need (ex: Oracle database PSU,SPU(CPU),Bundle Patches (versions 12.1 & lower).
  4. then select 12.1.0.2 (if 12c)
  5. then select the related patch you need from the list.

Oracle Enterprise Manager:

1) Checking for future releases:

NOTE:793512.1 - Release Schedule of Enterprise Manager Releases and Patchsets (10g, 11g, 12c, 13c)

2) To find Current installed OMS list of patches:

How to Determine the Patch Set Update (PSU) Applied to the Enterprise Manager 13c Cloud Control OMS and the Bundle Patch applied to Plug-ins and Agent (Doc ID 2319892.1)

For the EM 13c Cloud Control OMS, issue this command to find the effective PSU level of the EM 13c OMS:
<OMS Oracle Home>/OPatch/opatch lsinventory | grep -i 'EMBP Patch Set Update'

To see the current version according to the Plugin Bundle Patches for the EM 13c OMS plug-ins, use the following:
<OMS Oracle Home>/OPatch/opatch lsinventory | grep -i 'Plugin Bundle Patch'

For the EM 13c Cloud Control Agent, issue this command to the the current Bundle Patch level applied:
<OMS Oracle Home>/OPatch/opatch lsinventory | grep -i 'EM-AGENT Bundle Patch'


Other helpful Doc id's:
Doc ID 822485.1


Hope this helps.

Tuesday, October 16, 2018

Creating calender rotation in plsql for x number of people...

Below is an example to create a rotation for 4 people in 3 step process. Make changes as needed.

1) 

create table test (START_DATE DATE,WEEK_DAY varchar2(20),W_D_N varchar2(10) default null,WEEK_NUMBER number,NAME varchar2(20) default null);
create table test1 ( ID number, NAME varchar2(10) default null);
insert into test1 values (1,'jack');
insert into test1 values (2,'mike');
insert into test1 values (3,'jim');
insert into test1 values (4,'bob');

commit;


2) ---load calender now with appropriate dates and validate randomly:

insert into test (START_DATE,WEEK_DAY,W_D_N,WEEK_NUMBER,NAME)
       SELECT (to_date('2018-08-16','YYYY-MM-DD') +( level -1)) start_date,to_char( (to_date('2018-08-16','YYYY-MM-DD') +level -1) +1, 'DAY')Week_day,
     ( CASE 
    WHEN  to_char( (to_date('2018-08-16','YYYY-MM-DD') +level -1) +1, 'DAY')  like 'MON%'   THEN   7      
     WHEN to_char( (to_date('2018-08-16','YYYY-MM-DD') +level -1) +1, 'DAY')  like 'TUES%'  THEN   1
     WHEN to_char( (to_date('2018-08-16','YYYY-MM-DD') +level -1) +1, 'DAY')  like 'WED%'   THEN   2
     WHEN  to_char( (to_date('2018-08-16','YYYY-MM-DD') +level -1) +1, 'DAY') like 'THUR%'  THEN   3
     WHEN to_char( (to_date('2018-08-16','YYYY-MM-DD') +level -1) +1, 'DAY')  like 'FRID%'  THEN   4 
     WHEN  to_char( (to_date('2018-08-16','YYYY-MM-DD') +level -1) +1, 'DAY') like 'SAT%'   THEN   5
     WHEN to_char( (to_date('2018-08-16','YYYY-MM-DD') +level -1) +1, 'DAY')  like 'SUN%'   THEN   6
     ELSE
          null
  END ) W_D_N,
        to_char( (to_date('2018-08-16','YYYY-MM-DD') +level -1), 'WW') week_number,null
  FROM DUAL CONNECT BY (to_date('2018-08-16','YYYY-MM-DD') +( level -1)) <= to_date('2018-12-31','YYYY-MM-DD');

--------------------------------------------------


3) ---- have a rotation set from the above... change the value "x < 4" based on the rotation..




set serveroutput on
declare 
TYPE at_most_twelve_t IS VARRAY (100) OF VARCHAR2 (100);
l_months   at_most_twelve_t;
type rotat_name is VARRAY (100) OF VARCHAR2 (100);
rotat_cur rotat_name;
--temp varchar2(10);
x NUMBER := 0;
y NUMBER := 0;
z NUMBER := 0;
p NUMBER := 0;
Begin

SELECT distinct week_number  BULK COLLECT INTO l_months FROM test where name is null order by week_number asc;
  select name BULK COLLECT into rotat_cur from test1 order by id asc; 
  for i in 1 .. l_months.count
  LOOP
      -- DBMS_OUTPUT.PUT_LINE('Outer Loop counter is ' || l_months(i));
       ---- set the x value for if loop based on number of people in rotation.
          if  x < 4 then
          x := x + 1;
          else 
           x := 1;
          end if;
             
         -- DBMS_OUTPUT.PUT_LINE('Outer Loop counter is ' || x);
          for k in 1 .. rotat_cur.count 
             loop
                  if    k = x then  
             for j in (select w_d_n from test where week_number=l_months(i))
                 loop 
                 update test set Name=rotat_cur(k) where week_number=l_months(i);
                 commit;
                 end loop;
                  else
                    continue;
                    end if;
            end loop;
  END LOOP;
END;

commit;


===========================================

Hope this helps....

Wednesday, September 26, 2018

ASM disk to OS device to SCSI Id's (Linux)

Use below scripts to get the needed mapping between the ASM raw disks to OS devices to SCSI ID's.
use below script if your Unix admin is using dev rules for mapping....

run below one as oracle user ... if needed this to run as grid owner then change the logic below..

1) 1st script:-
disk_info.sql

{

col NAME for a30
col PATH for a30
spool asm_info.log
select NAME,PATH,OS_MB from V$ASM_DISK order by NAME asc;
spool off

}


2) 2nd script which is *.sh

ASM_disk_SCSI_shell.sh

{

COMMAND=$0
PGM=${COMMAND##*/}
host_name=`hostname | cut -d"." -f1`

# Remove nohup.out files if any from previous execution.

if [ -f nohup.out ]; then
   rm nohup.out
fi

#

## Choose directory/Path or hit enter to choose default path(currect directory).

echo "Enter the unix directory path to create the reports.Press Enter to create in current directory:"
read dir
if [ "$dir" = "" ]
then
repdir=$PWD
else
repdir=$dir
cp $PWD/*.sql $repdir
fi

##

### Remove the old log files.

cd $repdir
rm $repdir/*.log
rm $repdir/*.html

###

#### Chech to find which database/instance is up and running based on crontab entries.

   for db in `cat /etc/oratab| egrep -v '(^#|\+|\-)'|cut -f1 -d: -s|egrep -v 'OMS'|egrep -v 'AGENT'`
       do
         echo "$db";
         db_check=`pgrep -al pmon|grep $db |cut -f3,4 -d_`
            if [ -n "$db_check" ]
              then
              db_sid=$db_check
              # echo "$db_sid"
                echo "$db"
                dbhome=`cat /etc/oratab|egrep $db|egrep -v '(^#|\+)'|cut -f2 -d: -s`
                echo "$dbhome"
                uname -a
                break
                else
                echo "db_check is empty";

            fi
      done
####

### /// Setting environment variables.
PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:$HOME/bin:/usr/bin/xterm:/sbin:/opt/freeware/bin:/bin:.
export ORACLE_SID=$db_check
export ORACLE_HOME=$dbhome
PATH=$ORACLE_HOME/bin:$PATH
LIBPATH=$ORACLE_HOME/lib:$LIBPATH

### ///

#### Login into database to get the Disk info.

sqlplus / as sysdba << EOF
set heading off
set feedback off
set echo off
set pagesize 0
@$repdir/disk_info.sql
exit
EOF

sort -b -V -k 2 $repdir/asm_info.log >>$repdir/asm_info_cut.log_1
mv $repdir/asm_info_cut.log_1 $repdir/asm_info.log
cat asm_info.log| awk '{print $2}' >> $repdir/asm_info_cut.log

cat asm_info_cut.log | sort -V >asm_info_cut_1.log
mv asm_info_cut_1.log asm_info_cut.log

cat asm_info_cut.log|while read disk

do
echo "`cat /etc/udev/rules.d/60-raw.rules | grep -v '^#' | grep -w $disk | awk '{print $2}' | grep -Po '".*?"' | grep -oP '"\K[^"]+' `" >> $repdir/asm_disk_lun_info.log

echo "` raw -qa | grep -w $disk | awk '{print $1,$5,$7}' | sed 's/,//;s/://g' | awk '{ print $1"\t"$2":"$3}' `" >>asm_disk_lun_info_m.log

done

cat $repdir/asm_disk_lun_info.log |while read rawd

do
echo "$rawd  `lsscsi | grep $rawd''  | tr '[' '\t' | tr ']' '\t' | awk '{print $1}'` " >> $repdir/asm_raw-physical.log
done

paste $repdir/asm_info.log $repdir/asm_disk_lun_info.log $repdir/asm_raw-physical.log| awk  '
BEGIN {
format = "%-20s %-18s %-19s %-18s  %-19s %s\n"
printf format,  "ASM_groups", "ASM_RAW_DISK",  "OS_DISK_SIZE", "UNIX_MAP_Disk", "LINUX_id",  "LINUX_SCSI_id"
printf format,  "----------", "-------------", "------------", "-------------", "--------", "-------------"}
{for(i=1;i<=NF;i++)
printf("%-20s%c", $i, (i==NF) ? ORS : "")}' >> $repdir/asm_info_final.log;

exit;


}

Hope this helps...

PostgreSql: Useful Commands-

 1)   ************************* Users ***************************  -- List of users with roles assigned: SELECT usename AS role_name,   CASE...