Posts

Pdb

 insert_pdb() {   echo "Running PDB onboarding..." | tee -a "$LOGFILE"   TGT_TYPE="Pluggable Database"   HOST_NAME=$(hostname -f)   for ENV_FILE in /home/oracle/*.env; do     source "${ENV_FILE}"     if [[ -z "$ORACLE_SID" || -z "$ORACLE_HOME" ]]; then       echo "Environment variables not set in $ENV_FILE. Skipping..." | tee -a "$LOGFILE"       continue     fi     # Verify if the CDB is running     DB_STATUS=$(ps -ef | grep "[p]mon_${ORACLE_SID}" | wc -l)     if [[ "$DB_STATUS" -eq 0 ]]; then       echo "CDB $ORACLE_SID is not running. Skipping..." | tee -a "$LOGFILE"       continue     fi     echo "Processing CDB: $ORACLE_SID" | tee -a "$LOGFILE"     # Fetch PDBs in NORMAL status     PDBS=$(sqlplus -s / as sysdba <<EOF SET HEAD OFF FEEDBACK OFF SELECT pdb_name FROM cdb_pdbs WHERE pdb_name != 'PDB\...

Sql1

#!/bin/bash LOGFILE="/home/oracle/pdb_output.log" : > $LOGFILE # Clear the log file get_pdb_details() {   echo "CDB_UNIQUE_NAME|PDB_NAME|CPU|SGA_MAX_SIZE_GB|SGA_TARGET_GB|PGA_GB|DB_SIZE_GB" > $LOGFILE   # Iterate over each CDB   for ENV_FILE in /home/oracle/*.env; do     source "${ENV_FILE}"     # Validate environment variables     if [[ -z "$ORACLE_SID" || -z "$ORACLE_HOME" ]]; then       continue     fi     # Check if CDB is running     INSTANCE_STATUS=$(timeout 5 sqlplus -s / as sysdba <<EOF SET HEAD OFF FEEDBACK OFF SELECT instance_name FROM v\$instance WHERE status = 'OPEN'; EXIT; EOF )     if [[ -z "$INSTANCE_STATUS" ]]; then       continue     fi     # Fetch CDB unique name     CDB_UNIQUE_NAME=$(sqlplus -s / as sysdba <<EOF SET HEAD OFF FEEDBACK OFF SELECT value FROM v\$parameter WHERE name = 'db_unique_name'; EXIT; EO...

Sql

get_pdb_details() {   echo "Fetching PDB Details..." | tee -a $LOGFILE   # Iterate over each CDB   for ENV_FILE in /home/oracle/*.env; do     echo "Sourcing environment file: $ENV_FILE" | tee -a $LOGFILE     source "${ENV_FILE}"     # Validate environment variables     if [[ -z "$ORACLE_SID" || -z "$ORACLE_HOME" ]]; then       echo "Environment variables not set in $ENV_FILE. Skipping..." | tee -a $LOGFILE       continue     fi     # Check if CDB is running     INSTANCE_STATUS=$(timeout 5 sqlplus -s / as sysdba <<EOF SET HEAD OFF FEEDBACK OFF SELECT instance_name FROM v\$instance WHERE status = 'OPEN'; EXIT; EOF )     if [[ -z "$INSTANCE_STATUS" ]]; then       echo "CDB $ORACLE_SID is not running. Skipping..." | tee -a $LOGFILE       continue     fi     echo -e "\nProcessing CDB: $ORACLE_SID" | tee -a $LOGFIL...

Join

SELECT      'emcli add_target -name="' || inst1.cluster_dbname || '" -type="rac_database" -host="' ||     inst1.host_name || '" -monitor_mode="1" -properties="ServiceName:' || inst1.SERVICE_NAME ||      '; ClusterName:' || inst1.CLUSTER_NAME || '; instances=' || inst1.tgt_name ||      ':oracle_database;' || inst2.tgt_name || ':oracle_database"' AS emcli_command,     inst1.tgt_name,      inst2.tgt_name,      inst1.cluster_dbname FROM      (SELECT * FROM TEST.OEM_onboard_database_instance) inst1,     (SELECT * FROM TEST.OEM_onboard_database_instance) inst2 WHERE      inst1.cluster_dbname = inst2.cluster_dbname     AND inst1.tgt_name <> inst2.tgt_name     AND inst1.cluster_dbname IN (SELECT DISTINCT cluster_dbname FROM TEST.OEM_onboard_database_instance);

Asm

#!/bin/bash # Set environment variables ORACLE_SID=YOUR_SID ORACLE_HOME=/path/to/oracle_home export ORACLE_SID ORACLE_HOME LOG_DIR=/path/to/logs SQL_DIR=/path/to/sql mkdir -p "$LOG_DIR" mkdir -p "$SQL_DIR" DB_USER="/ as sysdba" # Function to generate SQL data for each target type generate_sql() {   local TARGET_TYPE=$1   local SQL_FILE="$SQL_DIR/${TARGET_TYPE}_data.sql"   local OUTPUT_FILE="/tmp/${TARGET_TYPE}_data.txt"   case "$TARGET_TYPE" in     cluster)       echo "SET HEADING OFF; SET FEEDBACK OFF; SET PAGESIZE 0;" > "$SQL_FILE"       echo "SELECT TARGET_NAME || '|' || HOST_NAME || '|' || CREDENTIALS || '|' || CLUSTER_NAME || '|' || VIP_ADDRESS FROM CLUSTER_TARGETS;" >> "$SQL_FILE"       ;;     # Additional target types can be added here     *)       echo "[ERROR] Unknown target type: $TARGET_TYPE"       return 1       ;;   esac ...

DBA Day-2 ve

 Operating system  CPU mpstat top  load average  pidstat dstat -vr strace---> debug if system CPU usage % is high but if you dont know then use strace -tp `grep testdb1 2>&1 | head 100 debug if User CPU usage % is high but if you dont know then use 6. jobs (hit enter) 6.1 perf record -F 99 -a -g --sleep 10 (Profiling ) 6.2 perf report -n --stdio 6.3 ./perf-tools/execsnoop Memory vmstat I/O iostat -xmd 1 iotop Network sar -n DEV 1 mtr netstat -antpl | grep 1521 nmcli device status ethtool iperf3 -c 10.1.90.51 https://www.youtube.com/watch?v=eWUeJBAiX80 fs.aio-max-nr--> Async I/O max fs.file-max --> Max file open kernal.shmmin --> how many program segment can access(permission) the shared memory kernal.shmall --> maximum amount of shared memory can accessed by all the process other than OS(set to sum of all SGAs on the server divided by page size – ‘getconf PAGESIZE’) kernal.shmmax --> maximum amount of shared memory can accessed by ind...

DBA - Day1

Perfect! I’ll give you hands-on-style answers with commands, output samples, and explanation, just like a real-world DBA would use. Let’s begin with the enhanced version of your earlier question: --- Question 1: How do you troubleshoot high CPU usage in Oracle 19c? Step-by-Step Approach (Hands-on) --- Step 1: OS-Level Check using top or vmstat Command: top -n 1 Sample Output: %Cpu(s): 90.5 us, 1.5 sy, 0.0 ni, 8.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st us (user): high value here (e.g., 90%) indicates application/SQL consuming CPU. If id (idle) is very low and us is high = DB or app is the cause. Alternative Command (better for deeper view): vmstat 2 5 Sample Output: procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----  r b swpd free buff cache si so bi bo in cs us sy id wa st  3 0 0 20000 15000 500000 0 0 0 1 200 300 85 5 10 0 0 r = run queue. If r > no. of CPUs, system is under pressure. us/sy:...