Monday, November 4, 2024

pre-post check script

 #######################################################
#!/bin/ksh
# set the DB env and run
# Script to check PRE & Post checks Manually
#
# CB - <Date>   - version 1 - Initial Draft
#set -x

echo -e "\n*************************************"
echo  "DATE = `date`"
echo  "HOSTNAME = " `hostname`
echo -e "*************************************\n"

if [ "$1" = "" ]; then
  echo -e "\n please Provide pre or post "
  echo -e "Syntax: $0 <pre>|<post> \n"
  exit 1
elif [[ "${chk_type}" == "pre" || "${chk_type}" == "post" ]]; then
  echo -e "\n Entered ${chk_type}   ..........  \n"
else
  echo -e "\n Please enter either " PRE " or " POST " Only. \n"
  exit 1
fi

chk_type=`echo $1 | tr "[:upper:]" "[:lower:]"`
export logfile=/home/oracle/CB/${chk_type}_shell_logfile.log
export home=<ORACLE_HOME>
export oem_agent_home=<Agent_home>
export psu_location=<Patch_path>/<patch#>

#exit 1
precheck(){
echo -e "\n   -----[ Gather OS Info ]------\n"
date
uname -a
cat /etc/oratab
ps -ef |grep pmon
ps -ef |grep tns
crsctl stat res -t
df -h
echo -e "\n   -----[ OEM Agent Info ]------\n"
${oem_agent_home}/bin/emctl status agent
${oem_agent_home}/bin/emctl status blackout <name>
}


home_check () {
echo -e "\n     -----[ Gather PATCH Info ]------\n"
$home/OPatch/opatch version
$home/OPatch/opatch lsinventory
 if [[ "$chk_type" == "pre" ]]; then
  echo -e "\n Checking patch Conflicts ........."
  cd ${psu_location}
  ${home}/OPatch/opatch prereq CheckConflictAgainstOHWithDetail -ph ./
 fi
}

db_check () {
echo -e "\n   -----[ Gather DB Info ]------\n"
crsctl stat res -t | grep ".db$" |tr "." " " | awk -F" " '{print $2}'| while read LINE2
do
 # case $LINE2 in
 #   *)
echo -e "\n Running for : $LINE2  "
srvctl status database -d $LINE2 -v
srvctl status service -d $LINE2 -v
echo "-------------------------"
#esac
done
}

home_check | tee -a ${logfile}
precheck | tee ${logfile}
db_check  | tee -a ${logfile}

sql_info (){
cat /etc/oratab | grep 112|tr ":" " "  | awk -F" " '{print $1}' |egrep -v ''\#'|ASM' | while read LINE3
do
export ORACLE_SID=${LINE3}
export ORACLE_HOME=${home}
export LD_LIBRARY_PATH=$ORACLE_HOME/bin:$PATH
#echo "$LINE3"
echo -e "\n    --------[ Running for database : $LINE3 ]---------"
$ORACLE_HOME/bin/sqlplus -s / as sysdba << eof
set pages 999 lines 280 feedback off
col COMMENTS for a33
col pdb_name format a15
col dp_action format a15
col dp_status format a20
col dp_action_time format a20
col dp_description format a30
select comments, action, to_char(action_time,'DD/MM/RR HH24:MI:SS') action_date, version  from sys.registry\$history  order by action_date;
 select name,action_time dp_action_time,id dp_patch_id,action dp_action,comments dp_description from v\$database,sys.registry\$history  where action_time=(select max(action_time)   from sys.registry\$history);
eof
done
}

sql_info

cat  ${logfile} | mailx -s "`hostname` : precheck info " Your_email

 

Monday, July 22, 2024

Postgres DB Fundamentals

 

vacuum --> Defrag in Oracle

 

In postgres Tables gets Bloated due to DML's

A tuple is an internal representation of a row


 

Vacuum

Vacuum FULL

Free up dead rows for reuse,

Selects and DMLs Allowed

No Exclusive Locks,

OS Space NOT released

Rewrite the table with no dead rows (Tuple),

No DML’s Including select Allowed,

Puts EXCLUSIVE Lock,

OS Space will be released

Tune AutoVacuum:

set Vacuum_cost_page IO limit parameters
No. of Workers (I/O Intensive)
 

Autovacuum_vacuum_threshold :

min number of updates/deletes tuples needed to trigger a VACUUM in any table. The default is 50 tuples.

 

Autovacuum_vacuum_scale_factor:

Fraction of the table size (in terms of no. of rows) to decide whether vacuum should be triggered. Default is 0.2

 

Transaction wraparound

·        TXID's can go up till ~4 billion (32 bit ID)

·        Postgres will stop accepting commands when there are fewer than one million transactions left before the maximum XID value is reached.

 

   Why Happens this ?

·        Auto-vacuum is set to turned off

·        Heavy DML Operation

·        Many session or connection’s holding lock’s for very long time

 

   What happens in this Situation

·        PostgreSQL will stop accepting DML statements and switches to READONLY mode.

 

   FIX:

·        Stop and Bring up DB into single user mode

·        Run Vacumm FULL on entire DB (vacuumdb --all)

·        Once done stop ad restart postgres normally


Monday, April 22, 2024

OEM Modifying-em-metric-threshold sizeOfOSAuditFiles

 

In order to modify “sizeOfOSAuditFiles” metric for all the targets in OEM when you have several of them use below script to do all in one shot

Check the current values/setting for your targets 

select  * from sysman.MGMT$METRIC_COLLECTION A
where A.METRIC_NAME='sizeOfOSAuditFiles'
and WARNING_THRESHOLD <'2000';
--and target_name='<target_name>
 
Generate emcli command using below
 
select
'emcli modify_threshold -target_name="'||A.target_name||'" -target_type="oracle_database" -metric="sizeOfOSAuditFiles" -column="FILE_SIZE" -warning_threshold="2000" -critical_threshold="5000" -force'
from sysman.MGMT$METRIC_COLLECTION A
where A.METRIC_NAME='sizeOfOSAuditFiles'
and WARNING_THRESHOLD <='2000';
 
Place the above emcli commands in shell script and run from OMS repo server

$ emcli login -username=sysman 

vi modify_audit.sh
 
[oracle@omshost CB]$ ll
total 20
-rw-r-----. 1 oracle dba 18471 Apr 22 08:42 modify_audit.sh
 
[oracle@ omshost CB]$ chmod 755 modify_audit.sh
total 20
-rwxr-xr-x. 1 oracle dba 18471 Apr 22 08:42 modify_audit.sh
 
[oracle@ omshost CB]$ sh modify_audit.sh
 

 



 and if you want to disable this metric itself then follow below oracle Doc, thanks 

 

Saturday, March 23, 2024

Postgres Backup/Restore

 

pg_dump    à Creates a backup of ONE database at a time

pg_dumpall  à Can back up ALL of your databases simultaneously,

 

pg_dump -U username -W -F t database_name > c:\backup_file.tar

 
-F : specifies the output file format that can be one of the following:
    ·        c: custom-format archive file format
    ·        d: directory-format archive
    ·        t: tar
    ·        p: plain-text SQL script file (Default)
-h Specify database server host
 
-p   Specify database server port
-U  Specify the user which is used to connect to the PostgreSQL database server
-W Used to prompt for a password before connecting to the PostgreSQL server
-d   Specify the database to dump
 
 
 

SCHEMA backup
 

pg_dump --username=user --password --schema-only [schema_name] > database_schema.sql

pg_dump --schema-only DATABASE > schema.sql

 
 
EX:
pg_dump --clean --create --file /tmp/DB-$(date +%Y%m%d).pgdump --format=custom --no-unlogged-table-data  <dbname>
 
 
psql --dbname=DBNAME --command="select pg_start_backup('CurBuild');"
 

Restore

To import a single database testdb from the tar dumpfile

pg_restore -c -U username -W -F t -d testdb dump.tar

 

To import ALL databases from tar dumpfile

pg_restore -c -U username -W -F t dump.tar


To import 1 database from .sql backup

postgres=# create database

psql   -d <New_DBNAME>    < dump.sql 

Validate :

-bash-4.2$ psql

psql (15.4)

Type "help" for help.

postgres=#  \l

postgres=# \c   <new_dbname>

postgres=#  SELECT pg_size_pretty( pg_database_size(‘NEW_DBNAME’));

 




Wednesday, December 6, 2023

Add Oracle Physical Standby to Existing Data guard BROKER Configuration

 

 
PRIMARY  : oradb_prim
STANDBY  :  oradb_std
ORACLE Version : 19c
 
Assuming tnsping using TNSNAME is working from both sides.

On Standby :

sho parameter broker

 alter system set dg_broker_config_file1='+DATAC1/ORADB_STD/DATAGUARDCONFIG/oradb_primdg1.dat' scope=both sid='*'; 

 alter system set dg_broker_config_file2='+DATAC1/ORADB_STD/DATAGUARDCONFIG/oradb_primdg2.dat' scope=both sid='*';

 alter system set dg_broker_start=TRUE scope=both sid='*'; 

sho parameter broker

 

From primary

$ dgmgrl /

show configuration;            

    --- Add Standby database into Broker Config                                  
add database oradb_std  as connect identifier is oradb_std maintained as physical;
 

enable configuration;

show configuration;

        --- Add Redo Routes for Primary

show database oradb  redoroutes;

edit database oradb_prim set property RedoRoutes='(local:oradb_std ASYNC)';   -- Change as per requirements

  -- As soon as Redo property is added oracle dest_ parameter will set in database Automatically

show database oradb_prim redoroutes;

 

edit database 'oradb_std' set state='apply-off';

edit database 'oradb_std' set state='apply-on';

Enable configuration

            --- Optionally adjust some properties as you like

DGMGRL> edit database oradb_std set property TransportLagThreshold='900';

Property "transportlagthreshold" updated

 

DGMGRL> edit database oradb_std set property ApplyLagThreshold='900';

Property "applylagthreshold" updated



Enable Physical standby BROKER Configuration for oracle Primary


Primary : PRIMDB  
Standby  : primdb_std 
 
On primary :
 
12:14:55 SYSTEM@PRIMDB >sho parameter broker
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
connection_brokers                   string      ((TYPE=DEDICATED)(BROKERS=1)),
                                                  ((TYPE=EMON)(BROKERS=1))
dg_broker_config_file1               string      /opt/oracle/product/19.3.0/dbs
                                                 /dr1primdb.dat
dg_broker_config_file2               string      /opt/oracle/product/19.3.0/dbs
                                                 /dr2primdb.dat
dg_broker_start                      boolean     FALSE
use_dedicated_broker                 boolean     FALSE
 
12:15:05 SYSTEM@PRIMDB > show parameter log_archive_config
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_config                   string
 
oraclehost:PRIMDB:/home/oracle $ dgmgrl /
DGMGRL for Linux: Release 19.0.0.0.0 - Production on Thu Jul 27 11:45:14 2023
Version 19.17.0.0.0
 
Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
 
Welcome to DGMGRL, type "help" for information.
Connected to "PRIMDB"
Connected as SYSDG.
DGMGRL> show configuration
ORA-16525: The Oracle Data Guard broker is not yet available.
 
Configuration details cannot be determined by DGMGRL
 
 
 
SYNTAX:
DGMGRL> CREATE CONFIGURATION '<configuration name>' AS PRIMARY DATABASE IS '<primary db_unique_name>' CONNECT IDENTIFIER IS <primary connect string>;
 
 
DGMGRL>  create configuration Primdb_dg as primary database is 'PRIMDB' connect identifier is PRIMDB ;
Error:
ORA-16525: The Oracle Data Guard broker is not yet available.
 
 
Fix : set “dg_broker_start” to TRUE
 
11:50:11 SYSTEM@PRIMDB >   alter system set dg_broker_start=true sid='*';
 
System altered.
 
Also you can set desired broker config file path using below

alter system set dg_broker_config_file1='+<path>/DATAGUARDCONFIG/primdb_dg1.dat' scope=both sid='*'; 

alter system set dg_broker_config_file2='+<path>/DATAGUARDCONFIG/primdb_dg2.dat' scope=both sid='*'; 


11:51:53 SYSTEM@PRIMDB >sho parameter broker
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
connection_brokers                   string      ((TYPE=DEDICATED)(BROKERS=1)),
                                                  ((TYPE=EMON)(BROKERS=1))
dg_broker_config_file1               string      /opt/oracle/product/19.3.0/dbs/dr1PRIMDB.dat
dg_broker_config_file2               string      /opt/oracle/product/19.3.0/dbs/dr2PRIMDB.dat                                            
dg_broker_start                      boolean     TRUE
use_dedicated_broker                 boolean     FALSE
 
  
 
DGMGRL> create configuration primdb_dg as primary database is 'PRIMDB' connect identifier is primdb ;
Configuration "primdb_dg" created with primary database "PRIMDB"
 
DGMGRL>  show configuration
 
Configuration - Primdb_dg
 
  Protection Mode: MaxPerformance
  Members:
  PRIMDB - Primary database
 
Fast-Start Failover:  Disabled
 
Configuration Status:
DISABLED
 
Files will be created automatically on server
 
oraclehost:PRIMDB:/home/oracle $ ll /opt/oracle/product/19.3.0/dbs/dr1PRIMDB.dat
-rw-r----- 1 oracle oinstall 8192 Jul 27 11:58 /opt/oracle/product/19.3.0/dbs/dr1PRIMDB.dat
 
oraclehost:PRIMDB:/home/oracle $ ll /opt/oracle/product/19.3.0/dbs/dr2PRIMDB.dat
-rw-r----- 1 oracle oinstall  8192 Jul 27 11:58 /opt/oracle/product/19.3.0/dbs/dr2PRIMDB.dat
 
 
DGMGRL> enable configuration;
Enabled.
 
DGMGRL> show configuration
 
Configuration - Primdb_dg
 
  Protection Mode: MaxPerformance
  Members:
  PRIMDB - Primary database
    Warning: ORA-16905: The member was not enabled yet.
 
Fast-Start Failover:  Disabled
 
Configuration Status:
WARNING   (status updated 246 seconds ago)

 Doc:
12c Create Dataguard Broker Configuration - DGMGRL (Doc ID 1583588.1)
 
Add Standby to primary can be found here :  Add standby to Broker 

Monday, October 9, 2023

Check oracle OEM agent from AWS RDS database

PING OMS

 

From RDS database

 

SQL> SELECT rdsadmin.rdsadmin_oem_agent_tasks.ping_oms_oem_agent() as TASK_ID from DUAL;
 
TASK_ID
--------------------------------------------------------------------------------
16968905670056-4470
 
 

View the status output

 
SQL> SELECT text FROM table(rdsadmin.rds_file_util.read_text_file('BDUMP','dbtask-16968905670056-4470.log'));
 
TEXT
--------------------------------------------------------------------------------
2023-10-09 22:29:32.557 UTC [INFO ] Oracle Enterprise Manager Cloud Control 13c
Release 4
 
Copyright (c) 1996, 2020 Oracle Corporation.  All rights reserved.
---------------------------------------------------------------
EMD pingOMS completed successfully
 
2023-10-09 22:29:32.558 UTC [INFO ] The task finished successfully.
 
6 rows selected.

 

 

Check Agent Status

 

SQL> SELECT rdsadmin.rdsadmin_oem_agent_tasks.get_status_oem_agent() as TASK_ID from DUAL;

 
TASK_ID
--------------------------------------------------------------------------------
1696890801000-4470
 

 

SQL> SELECT text FROM table(rdsadmin.rds_file_util.read_text_file('BDUMP','dbtask-1696890801000-4470.log'));

 
TEXT
--------------------------------------------------------------------------------
2023-10-09 22:33:23.486 UTC [INFO ] Oracle Enterprise Manager Cloud Control 13c
Release 4
 
Copyright (c) 1996, 2020 Oracle Corporation.  All rights reserved.
---------------------------------------------------------------
Agent Version          : 13.4.0.0.0
OMS Version            : 13.5.0.0.0
Protocol Version       : 12.1.0.1.0
Agent Home             : /home/rdsdb/agent/app/agent_inst
Agent Log Directory    : /home/rdsdb/agent/app/agent_inst/sysman/log
Agent Binaries         : /home/rdsdb/agent/app/agent_13.4.0.0.0
Core JAR Location      : /home/rdsdb/agent/app/agent_13.4.0.0.0/jlib
Agent Process ID       : 1076
Parent Process ID      : 1032
Agent URL              : https://mydb.ckpij9egh4g.us-west-2.rds.amazonaws.com
:3872/emd/main/
 
Local Agent URL in NAT : https://mydb.ckpij9egh4g.us-west-2.rds.amazonaws.com
:3872/emd/main/
 
Repository URL         : https://omsserver.domain.com:4904/empbs/upload
Started at             : 2023-09-19 11:20:48
Started by user        : rdsdb
Operating System       : Linux version 4.1.12-124.77.2.el7uek.x86_64 (amd64)
Number of Targets      : 2
Last Reload            : (none)
Last successful upload                       : 2023-10-09 22:32:08
Last attempted upload                        : 2023-10-09 22:32:08
Total Megabytes of XML files uploaded so far : 26.03
Number of XML files pending upload           : 0
Size of XML files pending upload(MB)         : 0
Available disk space on upload filesystem    : 53.44%
Collection Status                            : Collections enabled
Heartbeat Status                             : Ok
Last attempted heartbeat to OMS              : 2023-10-09 22:32:55
Last successful heartbeat to OMS             : 2023-10-09 22:32:55
Next scheduled heartbeat to OMS              : 2023-10-09 22:33:56
 
---------------------------------------------------------------
Agent is Running and Ready
 
2023-10-09 22:33:23.487 UTC [INFO ] The task finished successfully.
 
36 rows selected.
 
 

 

Refer more :

https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Oracle.Options.OEMAgent.html#Oracle.Options.OEMAgent.limitations

 

x

Saturday, July 15, 2023

Recover Standby DB when standby_file_management is MANUAL when new files added in primary 19c

 
 
When datafiles are added on primary I see 2 datafiles are in WRONG Location in standby database after the new standby build
 
On Standby :
09:52:55 SYSTEM@devdb_std >select file_name from dba_data_files order by 1;
 
FILE_NAME
--------------------------------------------------------------------------------
/acfs_data/devdb_std/datafile/DEVDB_STD/datafile/o1_mf_it2_lbtw9k_.dbf
/acfs_data/devdb_std/datafile/DEVDB_STD/datafile/o1_mf_it2_lbtymt_.dbf
/acfs_data/devdb_std/datafile/data_D-DEVDB_TS-A_FNO-8
/acfs_data/devdb_std/datafile/data_D-DEVDB_TS-AA_FNO-9
/acfs_data/devdb_std/datafile/data_D-DEVDB_TS-AD_FNO-10
…… Trimmed ….
 
09:54:26 SYSTEM@devdb_std >sho parameter convert
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string      +DATAC1, /acfs_data/devdb_std/datafile
log_file_name_convert                string      +RECOC1, /acfs_reco/devdb_std/onlinelog
pdb_file_name_convert                string
 
09:53:19 SYSTEM@devdb_std >sho parameter standby
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
enabled_PDBs_on_standby              string      *
standby_db_preserve_states           string      NONE
standby_file_management              string      AUTO
standby_pdb_source_file_dblink       string
standby_pdb_source_file_directory    string
 
Reason :
 
The reason being by default when “standby_file_management” is AUTO OMF creates files in “db_file_name_convert” parameter in below location
 
<db_file_name_convert PATH>/<CAPS DBNAME>/datafile/
 
FIX:
 
Check the file number and status
 
10:31:33 SYSTEM@devdb_std > select file#, error, name from v$datafile_header where ERROR='FILE MISSING';
 
     FILE# ERROR
---------- -----------------------------------------------------------------
NAME
------------------------------------------------------------------------------------------------------------------------------------------
       781 FILE MISSING
 
 
 
10:34:39 SYSTEM@devdb_std >select name from v$datafile where file#=781 ;
 
NAME
-------------------------------------------------------------------------------------------------------------------
/u02/app/oracle/product/19.0.0.0/dbhome_1/dbs/UNNAMED00781
 
10:34:53 SYSTEM@devdb_std >alter database create datafile '/u02/app/oracle/product/19.0.0.0/dbhome_1/dbs/UNNAMED00781' as NEW;
alter database create datafile '/u02/app/oracle/product/19.0.0.0/dbhome_1/dbs/UNNAMED00781' as NEW
*
ERROR at line 1:
ORA-01275: Operation CREATE DATAFILE is not allowed if standby file management is automatic.
 
Cannot run when standby_file_management is AUTO so disable and rerun
 
10:36:13 SYSTEM@devdb_std >alter system set standby_file_management=MANUAL scope=both;
 
System altered.
 
10:36:25 SYSTEM@devdb_std >alter database create datafile '/u02/app/oracle/product/19.0.0.0/dbhome_1/dbs/UNNAMED00781' as NEW;
 
Database altered.
 
10:36:31 SYSTEM@devdb_std >alter system set standby_file_management=AUTO scope=both;
 
System altered.
 
 
Check the paths again
 
SQL >   select file_name from dba_data_files order by 1;
 
SQL >   select name from v$datafile where file#=779;
 
set the path correctly based on your location so that we cannot ran into this issue again
 
10:17:19 SYSTEM@devdb_std >alter system set db_create_file_dest='/acfs_data';
 
System altered.
 
10:23:41 SYSTEM@devdb_std >sho parameter file_dest
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
audit_file_dest                      string      /u02/app/oracle/product/19.0.0.0/dbhome_1/rdbms/audit
db_create_file_dest                  string      /acfs_data
db_recovery_file_dest                string      /acfs_reco/devdb_std/archivelog
db_recovery_file_dest_size           big integer 3500G
remote_recovery_file_dest            string
 
 
Now add couple of datafiles in primary and verify.
 
10:52:44 SYSTEM@devdb_std >select name from v$datafile where file#=779;
 
NAME
------------------------------------------------------------------------------------------------------------------------------------------
/acfs_data/DEVDB_STD/datafile/o1_mf_imm2_lc2vtbcd_.dbf
 
 
More like this

Auto Scroll Stop Scroll