Clearing down archive logs / audit / trace files (RMAN and o/s level)

A very quick script to clear down rman archive logs over 4 days - crontab entry to run 10pm every day


*NB* The 'sysdate' command below - when using cut&paste from Windows to Unix may fail as the single quote changes when pasting into Linux - please check.

[root@ora01 oracle]# cat rman_arch_del.sh

export ORACLE_HOME=/u01/app/oracle/product/12.2.0
export ORACLE_SID=db01
export PATH=$ORACLE_HOME/bin:$PATH


delbackup () {
rman log=/home/oracle/arch_del.log << EOF
connect target /
DELETE noprompt ARCHIVELOG ALL COMPLETED BEFORE ‘sysdate-4’;
CROSSCHECK ARCHIVELOG ALL;
DELETE EXPIRED ARCHIVELOG ALL;
exit
EOF
}
# Main
delbackup



We can delete the archivelogs by force using the following command "sledge hammer" approach

RMAN > delete noprompt force archivelog all;


[root@ora01 oracle]# crontab -l

00 22 * * * su - oracle -c "/home/oracle/rman_arch_del.sh" > /tmp/rmanarch.log


+++++++++++++++++++

At unix level run :

NLS_DATE_FORMAT='DD-MON-YYYY HH24:MI:SS'; export NLS_DATE_FORMAT

prior to running rman to output date/time in required format.


######  Clearing down old  RMAN / rman logs
From wthin rman :

crosscheck backup;
crosscheck archivelog all;
delete expired backup;
list copy of archivelog all;
delete obsolete recovery window of 14 days;
delete expired archivelog all;
report obsolete;
delete obsolete;
list backup;


++++++++++++++++++++++

A slightly more expanded version :

#!/bin/bash
# del_arch_no_backup.sh  Use this script to "cleanly" remove archivelogs when not
# backing up the database.
# Usage: del_arch_no_backup.sh sid num_of_days_to_keep

declare rman_ctl="/tmp/rman_ctl.ctl"
if [[ "$#" = 2 ]]; then
   declare sid=$1
   declare -i num_days=$2
else
   echo "usage: del_arch_no_backup.sh sid num_of_days_to_keep"
   exit 1
fi

if [[ ${ORACLE_HOME} = '' ]]; then
        echo "ORACLE_HOME is not set"
        exit 1
fi

# Check if DB is running
if ! `ps -ef|grep pmon|grep -q ${sid}`; then
   echo "Not a running database: ${sid}"
   echo "usage: del_arch_no_backup.sh sid num_of_days_to_keep"
fi

# Must keep at least one of day of archivelogs
if [[ ${num_days} < 1 ]]; then
   echo "Not a valid number of days"
   echo "usage: del_arch_no_backup.sh sid num_of_days_to_keep"
   exit 1
fi

echo "connect target" >${rman_ctl}
echo "delete archivelog all completed before 'sysdate-${num_days}';" >>${rman_ctl}
echo "crosscheck archivelog all;" >>${rman_ctl}
$ORACLE_HOME/bin/rman @${rman_ctl} >/dev/null

rm ${rman_ctl}
exit 0


Script to clean up oracle audit files :

[oracle@scripts]$ cat clean_oracle_audit_files.sh

#!/bin/bash
#
# This shell script will dynamically find and remove Oracle audit files after a given number of days.
# This shell script will work on any uncommented entries in the oratab file, including RAC instances,
# ASM and MGMTDB instances.
#
# usage: clean_oracle_audit_files.sh full_path_to_oratab number_of_days_to_keep
#

if [[ "$#" = 2 ]]; then
   declare ora_tab=$1
   declare -i num_days=$2
else
   echo "usage: clean_oracle_audit_files.sh full_path_to_oratab num_of_days_to_keep"
   exit 1
fi

if [[ !(-f ${ora_tab}) ]]; then
   echo "Not a valid ora_tab path/filename"
   echo "usage: clean_oracle_audit_files.sh full_path_to_oratab num_of_days_to_keep"
   exit 1
fi

if [[ ${num_days} < 1 ]]; then
   echo "Not a valid number of days"
   echo "usage: clean_oracle_audit_files.sh full_path_to_oratab num_of_days_to_keep"
   exit 1
fi

get_instance_name()
{
#Get all instances including RAC
local sid=$1
ps -eo args|grep pmon|grep $sid|sort -u
}

get_audit_home()
{
$ORACLE_HOME/bin/sqlplus -s / as sysdba <<EOF
set pages 0
set head off
set feed off
select value from v\$parameter where name = 'audit_file_dest';
EOF
}

while read -r line
do
   test_char=${line:0:1}
   if [[ "$test_char" != "#" && "$test_char" != "" && "$test_char" != " " ]]; then
      IFS=':' read sid ora_home rest <<< "$line"
      inst_name=$(get_instance_name $sid)
      inst_name=${inst_name:9}
      if [[ "$inst_name" != "" ]]; then #Skip non-running databases
         declare -x ORACLE_HOME=${ora_home}
         declare -x ORACLE_SID=${inst_name}
         audit_dest=$(get_audit_home);
         find ${audit_dest}/ -daystart -mtime +${num_days} -exec rm {} \;
      fi
   fi
done < "${ora_tab}"


Script to clean up trace files :


[oracle@scripts]$ cat clean_oracle_trace_files.sh
#!/bin/bash
#
# This shell script will dynamically find and remove Oracle trace files after a given number of days.
# This shell script will work on any uncommented entries in the oratab file, including RAC instances,
# ASM and MGMTDB instances.
# Updated to include xml files in alert directory.
#
# usage: clean_oracle_trace_files.sh full_path_to_oratab number_of_days_to_keep
#

if [[ "$#" = 2 ]]; then
   declare ora_tab=$1
   declare -i num_days=$2
else
   echo "usage: clean_oracle_trace_files.sh full_path_to_oratab num_of_days_to_keep"
   exit 1
fi

if [[ !(-f ${ora_tab}) ]]; then
   echo "Not a valid ora_tab path/filename"
   echo "usage: clean_oracle_trace_files.sh full_path_to_oratab num_of_days_to_keep"
   exit 1
fi

if [[ ${num_days} < 1 ]]; then
   echo "Not a valid number of days"
   echo "usage: clean_oracle_trace_files.sh full_path_to_oratab num_of_days_to_keep"
   exit 1
fi

get_instance_name()
{
#Get all instances including RAC
local sid=$1
ps -eo args|grep pmon|grep $sid|sort -u
}

get_trace_home()
{
$ORACLE_HOME/bin/sqlplus -s / as sysdba <<EOF
set pages 0
set head off
set feed off
select value from v\$diag_info where name = 'Diag Trace';
EOF
}

get_alert_home()
{
$ORACLE_HOME/bin/sqlplus -s / as sysdba <<EOF
set pages 0
set head off
set feed off
select value from v\$diag_info where name = 'Diag Alert';
EOF
}

while read -r line
do
   test_char=${line:0:1}
   if [[ "$test_char" != "#" && "$test_char" != "" && "$test_char" != " " ]]; then
      IFS=':' read sid ora_home rest <<< "$line"
      inst_name=$(get_instance_name $sid)
      inst_name=${inst_name:9}
      if [[ "$inst_name" != "" ]]; then #Skip non-running databases
         declare -x ORACLE_HOME=${ora_home}
         declare -x ORACLE_SID=${inst_name}
         trace_dest=$(get_trace_home);
         alert_dest=$(get_alert_home);
         find ${trace_dest}/ -daystart -mtime +${num_days} -exec rm {} \;
         find ${alert_dest}/ -daystart -mtime +${num_days} -exec rm {} \;
      fi
   fi
done < "${ora_tab}"
[oracle@usze2qmbtora01 scripts]$





## Log in to rman and show configuration items

RMAN> show all
2> ;

RMAN configuration parameters for database with db_unique_name ORADB01 are:

CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE RMAN OUTPUT TO KEEP FOR 7 DAYS; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/12.2.0.1/dbhome_1/dbs/snapcf_emrep.f'; # default

## Currently archivelog deletion policy is set to none - so we can delete the archivelogs

RMAN> delete archivelog all;

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=269 device type=DISK
List of Archived Log Copies for database with db_unique_name EMREP
=====================================================================

Key Thrd Seq S Low Time
------- ---- ------- - ---------
1 1 5 A 10-JUN-19
Name: /u01/oradata/recovery/EMREP/archivelog/2019_06_10/o1_mf_1_5_ghw4xs8r_.arc

2 1 6 A 10-JUN-19
Name: /u01/oradata/recovery/EMREP/archivelog/2019_06_10/o1_mf_1_6_ghw4xyx4_.arc

Do you really want to delete the above objects (enter YES or NO)? NO

## Change the parameter so the logs have to be backed up at least once.

RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO DISK;

new RMAN configuration parameters:
CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO DISK;
new RMAN configuration parameters are successfully stored

RMAN> delete archivelog all;

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=269 device type=DISK

RMAN-08138: warning: archived log not deleted - must create more backups

archived log file name=/u01/oradata/recovery/archivelog/2019_06_10/o1_mf_1_5_ghw4xs8r_.arc thread=1 sequence=5

RMAN-08138: warning: archived log not deleted - must create more backups

archived log file name=/u01/oradata/recovery/archivelog/2019_06_10/o1_mf_1_6_ghw4xyx4_.arc thread=1 sequence=6
## Logs won't delete so we change it the policy back to default.

RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO NONE;

old RMAN configuration parameters:
CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO DISK;
new RMAN configuration parameters:
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE;
new RMAN configuration parameters are successfully stored

RMAN> delete archivelog all;

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=269 device type=DISK
List of Archived Log Copies for database with db_unique_name ORADB01
=====================================================================

Key Thrd Seq S Low Time
------- ---- ------- - ---------
1 1 5 A 10-JUN-19
Name: /u01/oradata/recovery/EMREP/archivelog/2019_06_10/o1_mf_1_5_ghw4xs8r_.arc

2 1 6 A 10-JUN-19
Name: /u01/oradata/recovery/EMREP/archivelog/2019_06_10/o1_mf_1_6_ghw4xyx4_.arc

Do you really want to delete the above objects (enter YES or NO)?

Enter YES and et voilla.

Now put the policy back to it's original value.

The easier option is to use :

RMAN > delete noprompt force archivelog all;





Failed Oracle Agent Install

Had a case of an Oracle agent not installing correctly on a Linux server.

We had to manually remove all details from the OEM server as below :


[oracle@oem01 bin]$ ./emcli login -username=sysman
Enter password :

Login successful

[oracle@oem01 bin]$ ./emcli delete_target -name=odw01.nyfps.net:3872 -type=oracle_emd -delete_monitored_targets -async

Target "odw01.nyfps.net:3872:oracle_emd" deleted successfully


After checking on OEM there was no reference to the odw01 server - removed the agent from the actual odw server itself.

[oracle@odw01 install]$ perl ./AgentDeinstall.pl -agentHome /u01/app/middleware/agent_13.2.0.0.0


 Agent Oracle Home: /u01/app/middleware/agent_13.2.0.0.0

agentHome = /u01/app/middleware/agent_13.2.0.0.0
Agent installed in config modevalue of skip flag is false
NOTE: The agent base directory: /u01/app/middleware will be removed after successful deinstallation of agent home.
The command is /u01/app/middleware/agent_13.2.0.0.0/oracle_common/jdk/jre/bin/java -classpath /u01/app/middleware/agent_13.2.0.0.0/oui/modules/OraInstaller.jar:/u01/app/middleware/agent_13.2.0.0.0/oui/modules/emCfg.jar:/u01/app/middleware/agent_13.2.0.0.0/jlib/agentInstaller.jar oracle.sysman.agent.installer.AgentDeinstallation /u01/app/middleware/agent_13.2.0.0.0 /u01/app/middleware /u01/app/middleware/agent_inst
Apr 10, 2019 5:06:01 AM oracle.sysman.agent.installer.AgentInstaller$StreamGobbler run
INFO: Oracle Enterprise Manager Cloud Control 13c Release 2
Apr 10, 2019 5:06:01 AM oracle.sysman.agent.installer.AgentInstaller$StreamGobbler run
INFO: Copyright (c) 1996, 2016 Oracle Corporation.  All rights reserved.
Apr 10, 2019 5:06:03 AM oracle.sysman.agent.installer.AgentInstaller$StreamGobbler run
INFO: Agent is Not Running
Apr 10, 2019 5:06:03 AM oracle.sysman.agent.installer.AgentInstaller$StreamGobbler run
INFO: Plugin homes:
Apr 10, 2019 5:06:03 AM oracle.sysman.agent.installer.AgentInstaller$StreamGobbler run
INFO: Plugin homes:
Apr 10, 2019 5:06:03 AM oracle.sysman.agent.installer.AgentDeinstallation main
INFO: Creating directory /u01/app/middleware/agent_13.2.0.0.0/install/tmp completed successfully.
Apr 10, 2019 5:06:03 AM oracle.sysman.agent.installer.AgentDeinstallation main
INFO: File /etc/oragchomelist exists.
Apr 10, 2019 5:06:03 AM oracle.sysman.agent.installer.AgentDeinstallation main
INFO: File /etc/oragchomelist is writable.
Apr 10, 2019 5:06:03 AM oracle.sysman.agent.installer.AgentDeinstallation main
INFO: Index :-1 for line : /u01/app/oracle/agent/agent_13.2.0.0.0
Apr 10, 2019 5:06:03 AM oracle.sysman.agent.installer.AgentDeinstallation main
INFO: Index :-1 for line :
Apr 10, 2019 5:06:03 AM oracle.sysman.agent.installer.AgentDeinstallation main
INFO: Index :0 for line : /u01/app/middleware/agent_13.2.0.0.0:/u01/app/middleware/agent_inst
Apr 10, 2019 5:06:03 AM oracle.sysman.agent.installer.AgentDeinstallation main
INFO: Overwriting the contents since oracle home:/u01/app/middleware/agent_13.2.0.0.0 entry already exists.
The output is Agent Deinstall:agent deintall has been started
Executing status :0
Agent service stopped successfully.
 and the exit code is 0
Agent deconfiguration completed successfully. 0


 DetachHome Command executed:/u01/app/middleware/agent_13.2.0.0.0/oui/bin/detachHome.sh -silent ORACLE_HOME=/u01/app/middleware/agent_13.2.0.0.0
WARNING: Ignoring ORACLE_HOME=<value> on the command line (cannot override the Oracle Home to be detached)
Launcher log file is /tmp/OraInstall2019-04-10_05-06-04AM/launcher2019-04-10_05-06-04AM.log.
Starting Oracle Universal Installer

Checking swap space: must be greater than 500 MB.   Actual 4095 MB    Passed
Checking if this platform requires a 64-bit JVM.   Actual 64    Passed (64-bit not required)


'detachHome' was successful.
Logs successfully copied to /u01/oraInventory/logs.

 Removing other files ...
cannot remove path when cwd is /u01/app/middleware/agent_13.2.0.0.0/sysman/install for /u01/app/middleware/agent_13.2.0.0.0:  at ./AgentDeinstall.pl line 466.
cannot remove path when cwd is /u01/app/middleware/agent_13.2.0.0.0/sysman/install for /u01/app/middleware:  at ./AgentDeinstall.pl line 469.

NOTE: The targets monitored by this Management Agent will not be deleted in the Enterprise Manager Repository by this deinstall script. Make sure to delete the targets manually from the Cloud Control Console for a successful deinstallation.

Manually delete the agent s/w

[oracle@uodw01 middleware]$ pwd
/u01/app/middleware
[oracle@odw01 middleware]$ rm -rf agent_13.2.0.0.0


Now ok to install OEM agent as clean install. :)



Postgres v10

Some quick notes on Postgres v10


[root@localhost bin]# yum install postgresql10-server postgresql10
Loaded plugins: langpacks, ulninfo
Package postgresql10-server-10.7-2PGDG.rhel7.x86_64 already installed and latest version
Package postgresql10-10.7-2PGDG.rhel7.x86_64 already installed and latest version
Nothing to do

[root@localhost bin]# systemctl start postgresql-10.service

[root@localhost bin]# systemctl enable postgresql-10.service
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-10.service to /usr/lib/systemd/system/postgresql-10.service.

Note :

/usr/pgsql-10/bin/postgres

/var/lib/pgsql/10/data


[root@localhost bin]# su - postgres -c "psql"

psql (10.7)
Type "help" for help.

postgres=# CREATE TABLE demo(
postgres(# id serial PRIMARY KEY,
postgres(# email VARCHAR (100) UNIQUE NOT NULL,
postgres(# name VARCHAR (50) UNIQUE NOT NULL
postgres(# );
CREATE TABLE
postgres=# \d
List of relations
Schema | Name | Type | Owner
--------+-------------+----------+----------
public | demo | table | postgres
public | demo_id_seq | sequence | postgres
(2 rows)

postgres=# INSERT INTO demo (id, email, name) VALUES (1, 'ian@dba','ian');
INSERT 0 1

postgres=# select * from demo;
id | email | name
----+---------+------
1 | ian@dba | ian
(1 row)