Pages

Wednesday, August 24, 2022

Shrink space Oracle

=======================
Shrink Table
=======================
ALTER TABLE MY_USER.MY_TABLE ENABLE ROW MOVEMENT;
ALTER TABLE MY_USER.MY_TABLE SHRINK SPACE;
ALTER TABLE MY_USER.MY_TABLE DEALLOCATE UNUSED;

=======================
Shrink Index
=======================
SELECT INDEX_NAME FROM DBA_INDEXES 
WHERE OWNER = 'MY_USER' AND table_name = 'MY_TABLE';
ALTER INDEX MY_USER.MY_INDEX REBUILD ONLINE;

=======================
Rebuild Partitioned Indexes
=======================
SELECT 'ALTER INDEX '||DBA_IND_PARTITIONS.index_owner||'.'||DBA_IND_PARTITIONS.index_name||' REBUILD PARTITION '||DBA_IND_PARTITIONS.partition_name||';'
  FROM DBA_IND_PARTITIONS       
WHERE DBA_IND_PARTITIONS.index_name = 'MY_INDEX';
  AND DBA_IND_PARTITIONS.index_owner = 'MY_OWNER';
  
ALTER INDEX DEU_O2Q7Q_SPARX.SFI_CUSTOMER_PROFILE_PK REBUILD PARTITION SYS_P49;

=======================
Shrink SubPartition
=======================
ALTER TABLE MY_USER.MY_TABLE ENABLE ROW MOVEMENT;
ALTER TABLE MY_USER.MY_TABLE MODIFY SUBPARTITION SYS_SUBP315772  SHRINK SPACE;
ALTER TABLE MY_USER.MY_TABLE MODIFY SUBPARTITION SYS_SUBP315772  DEALLOCATE UNUSED; 


Generate the sql above
SELECT 'ALTER TABLE '||USER_TAB_PARTITIONS.table_name||' MODIFY SUBPARTITION '||USER_TAB_SUBPARTITIONS.subpartition_name||' SHRINK SPACE;'||CHR(13)
       'ALTER TABLE '||USER_TAB_PARTITIONS.table_name||' MODIFY SUBPARTITION '||USER_TAB_SUBPARTITIONS.subpartition_name||'  DEALLOCATE UNUSED;' as sql_cmd
   FROM (
SELECT USER_TAB_PARTITIONS.table_name, 
       USER_TAB_SUBPARTITIONS.subpartition_name, 
   USER_TAB_SUBPARTITIONS.last_analyzed,       ROUND(USER_TAB_SUBPARTITIONS.blocks*DBA_TABLESPACES.block_size/1024/1024) as sub_part_used_mb,
       USER_TAB_SUBPARTITIONS.num_rows sub_part_num_rows
  FROM USER_TAB_PARTITIONS,
       USER_TAB_SUBPARTITIONS,
   DBA_TABLESPACES
 WHERE USER_TAB_SUBPARTITIONS.table_name = USER_TAB_PARTITIONS.table_name
   AND USER_TAB_SUBPARTITIONS.partition_name = USER_TAB_PARTITIONS.partition_name
   AND USER_TAB_SUBPARTITIONS.last_analyzed < TRUNC(SYSDATE)-2
   AND USER_TAB_PARTITIONS.partition_name <> 'BASE_PART'
   AND DBA_TABLESPACES.tablespace_name = 'IGT_TABLE_BIG'
   AND ROUND(USER_TAB_SUBPARTITIONS.blocks*DBA_TABLESPACES.block_size/1024/1024) > 10
   AND USER_TAB_PARTITIONS.table_name = 'SGA_W_PSMS_SUBSCRIBER'
   );



=======================
Generate for non-partitioned Objects
=======================
set linesize 120
set pagesize 0
set heading off
set feedback off
spool enable_row_movement.sql
SELECT 'ALTER TABLE '||owner||'.'||table_name||'  ENABLE ROW MOVEMENT;' FROM DBA_TABLES WHERE tablespace_name = 'IGT_TABLE';
spool off
spool shrink_space.sql
SELECT 'ALTER TABLE '||owner||'.'||table_name||'  SHRINK SPACE;' FROM DBA_TABLES WHERE tablespace_name = 'IGT_TABLE';
spool off
spool deallocate_unused.sql
SELECT 'ALTER TABLE '||owner||'.'||table_name||'  DEALLOCATE UNUSED;' FROM DBA_TABLES WHERE tablespace_name = 'IGT_TABLE';
spool off
ALTER TABLE MY_USER.MY_TABLE ENABLE ROW MOVEMENT;
ALTER TABLE MY_USER.MY_TABLE SHRINK SPACE;
ALTER TABLE MY_USER.MY_TABLE DEALLOCATE UNUSED;
spool rebuild_index_online.sql
SELECT 'ALTER INDEX '||owner||'.'||index_name||' REBUILD ONLINE;' FROM DBA_INDEXES WHERE tablespace_name = 'IGT_TABLE';
spool off

@enable_row_movement.sql
@shrink_space.sql
@deallocate_unused.sql
@rebuild_index_online.sql

For Partitioned Objects:
ALTER TABLE MY_OWNER.MY_TABLE MODIFY PARTITION P_01_06 SHRINK SPACE;

ALTER TABLE MY_OWNER.MY_TABLE MOVE PARTITION P_01_06 TABLESPACE NEW_TBS_01;

ALTER TABLE MY_OWNER.MY_TABLE MOVE SUBPARTITION P_01_06 TABLESPACE NEW_TBS_01;


To Generate the SQL:
SELECT 'ALTER TABLE '||table_name||' MODIFY PARTITION '||partition_name||' SHRINK SPACE;' 
FROM USER_TAB_PARTITIONS WHERE table_name = 'MY_TABLE';

Tuesday, August 16, 2022

Shrink Temporary Tablespace and Move temp file to another location

==============
General
==============

=====================
Shrink Temporary Tablespace
=====================
SELECT file_name,
       tablespace_name, 
       ROUND(SUM(bytes)/1024/1024) TOTAL_MB 
  FROM DBA_TEMP_FILES 
 GROUP BY file_name,tablespace_name;

FILE_NAME                                     TABLESPACE_NAME    TOTAL_MB
--------------------------------------------- ------------------ --------
D:\ORACLE_DB\DB1\DB_IGT\ORA_TEMPORARY_01.DBF  TEMPORARY              4400

ALTER TABLESPACE TEMPORARY SHRINK SPACE KEEP 200M;
Tablespace altered;

SELECT file_name,
       tablespace_name, 
       ROUND(SUM(bytes)/1024/1024) TOTAL_MB 
  FROM DBA_TEMP_FILES 
GROUP BY file_name,tablespace_name;

FILE_NAME                                     TABLESPACE_NAME    TOTAL_MB
--------------------------------------------- ------------------ --------
D:\ORACLE_DB\DB1\DB_IGT\ORA_TEMPORARY_01.DBF  TEMPORARY               201


=====================
Move temp file to another location
=====================

Now: temporary table space has one file:
/oracle_db/db1/db_igt/ora_temporary_01.dbf
Need to move it to /oracle_db/db2/db_igt/datafile location




==============
Steps
==============
sqlplus / as sysdba

SET LINESIZE 120
COL NAME FOR A60
COL FILE_NAME FOR A60

SELECT name, status FROM V$TEMPFILE;

NAME                                       STATUS
------------------------------------------ --------
/oracle_db/db1/db_igt/ora_temporary_01.dbf ONLINE


SELECT file_id, tablespace_name, file_name, status, ROUND(bytes/1024/1024) as used_md, ROUND(maxbytes/1024/1204) as total_mb
FROM DBA_TEMP_FILES;

FILE_ID TABLESPACE_NAME FILE_NAME                                  STATUS   USED_MD    TOTAL_MB
------- --------------- ------------------------------------------ -------- ---------- ----------
1       TEMPORARY       /oracle_db/db1/db_igt/ora_temporary_01.dbf ONLINE   6000       5103

!mkdir /oracle_db/db2/db_igt
!mkdir /oracle_db/db2/db_igt/datafile

ALTER TABLESPACE TEMPORARY ADD TEMPFILE '/oracle_db/db2/db_igt/datafile/ora_temporary_01.dbf' SIZE 100M AUTOEXTEND ON MAXSIZE 8000M;

Tablespace altered.


SELECT name, status FROM V$TEMPFILE;

NAME                                                  STATUS
----------------------------------------------------- --------
/oracle_db/db1/db_igt/ora_temporary_01.dbf            ONLINE
/oracle_db/db2/db_igt/datafile/ora_temporary_01.dbf   ONLINE


ALTER DATABASE TEMPFILE '/oracle_db/db1/db_igt/ora_temporary_01.dbf' OFFLINE;
Database altered.

SELECT name, status FROM V$TEMPFILE;
NAME                                                  STATUS
----------------------------------------------------- ----------
/oracle_db/db1/db_igt/ora_temporary_01.dbf            OFFLINE
/oracle_db/db2/db_igt/datafile/ora_temporary_01.dbf   ONLINE

ALTER DATABASE TEMPFILE '/oracle_db/db1/db_igt/ora_temporary_01.dbf' DROP INCLUDING DATAFILES;

ERROR at line 1:
ORA-25152: TEMPFILE cannot be dropped at this time


There are active sessions that are using the temp files:

SELECT B.tablespace, B.segfile#, A.sid, A.serial#,
 A.username, A.osuser, A.status
 FROM V$SESSION A,
      V$SORT_USAGE B
 WHERE A.saddr = B.session_addr;

Kill the active sessions:
ALTER SYSTEM DISCONNECT SESSION '590,39359' IMMEDIATE;
ALTER SYSTEM DISCONNECT SESSION '970,6840' IMMEDIATE;
ALTER SYSTEM DISCONNECT SESSION '22,42942' IMMEDIATE;

ALTER DATABASE TEMPFILE '/oracle_db/db1/db_igt/ora_temporary_01.dbf' DROP INCLUDING DATAFILES;
Database altered.

SELECT name, status FROM V$TEMPFILE;

NAME                                                  STATUS
----------------------------------------------------- ---------
/oracle_db/db2/db_igt/datafile/ora_temporary_01.dbf   ONLINE

Sunday, August 7, 2022

How to: Resolve DRBD split-brain recovery manually

How to: Resolve DRBD split-brain recovery manually

After split brain has been detected, one node will always have the resource in a StandAlone connection state. The other might either also be in the StandAlone state (if both nodes detected the split brain simultaneously), or in WFConnection (if the peer tore down the connection before the other node had a chance to detect split brain).

At this point, unless you configured DRBD to automatically recover from split brain, you must manually intervene by selecting one node whose modifications will be discarded (this node is referred to as the split brain victim). 
This intervention is made with the following commands:

Below is the implementation of above technote
On secondary site



Regulal Flow 
on secondary site
drbdadm secondary Ora_Exp
drbdadm disconnect Ora_Exp
drbdadm -- --discard-my-data connect Ora_Exp

on primary site
drbdadm connect Ora_Exp
drbdadm status



If above does not work
on secondary site
root@server-1b:~>% drbdadm secondary Ora_Exp
root@server-1b:~>% drbdadm disconnect Ora_Exp
root@server-1b:~>% drbdadm -- --discard-my-data connect Ora_Exp
root@server-1a:~>% drbdadm status
optional:
root@server-1b:~>% drbdadm invalidate Ora_Exp


On primary site
root@server-1a:~>% drbdadm connect Ora_Exp
root@server-1a:~>% drbdadm status



See progress and log:
/sys/kernel/debug/drbd/resources/<resource_name>/connections/<server_name>/0/proc_drdb/

See progress
root@server-1a:~>% drbdadm status
Ora_Exp role:Primary
  disk:UpToDate
  server-1b role:Secondary
    peer-disk:UpToDate

Ora_Online role:Primary
  disk:UpToDate
  server-1b role:Secondary
    peer-disk:UpToDate

db1 role:Primary
  disk:UpToDate
  server-1b role:Secondary congested:yes ap-in-flight:96 rs-in-flight:14336
    replication:SyncSource peer-disk:Inconsistent done:81.03

db2 role:Primary
  disk:UpToDate
  server-1b role:Secondary congested:yes ap-in-flight:32 rs-in-flight:14336
    replication:SyncSource peer-disk:Inconsistent done:86.60


In this example, Ora_Exp and Ora_Online were already synced.
db1 and db2 are in process of sync.
The numbers 81.03 and 86.60 are percent of the synced disk.

once the percent is 100% - the 2 sites are in sync
on site A
Ora_Exp role:Primary
  disk:UpToDate
  server-1b role:Secondary
    peer-disk:UpToDate

on site B
Ora_Exp role:Secondary
  disk:UpToDate
  server-1a role:Primary
    peer-disk:UpToDate



Example:
commands on secondary site
commands on primary site

drbdadm secondary Ora_Exp
drbdadm disconnect Ora_Exp
drbdadm -- --discard-my-data connect Ora_Exp
drbdadm connect Ora_Exp
drbdadm status
 
drbdadm secondary Ora_Online
drbdadm disconnect Ora_Online
drbdadm -- --discard-my-data connect Ora_Online
drbdadm connect Ora_Online
drbdadm status

drbdadm secondary db1
drbdadm disconnect db1
drbdadm -- --discard-my-data connect db1
drbdadm connect db1
drbdadm status

drbdadm secondary db2
drbdadm disconnect db2
drbdadm -- --discard-my-data connect db2
drbdadm connect db2
drbdadm status
 
drbdadm status
drbdadm status


drbdadm secondary ogg
drbdadm disconnect ogg
drbdadm -- --discard-my-data connect ogg
drbdadm connect ogg
drbdadm status


How to: Make a node Primary
On to be Primary site:
root@server-1a:~>% drbdadm status
ogg role:Secondary
  disk:UpToDate
  server-1b connection:Connecting
root@server-1a:~>% drbdadm primary ogg
root@server-1a:~>% drbdadm disconnect ogg
root@server-1a:~>% drbdadm connect ogg
root@server-1a:~>% drbdadm status
ogg role:Primary
  disk:UpToDate
  server-1b connection:Connecting


drbdadm primary
Promote the resource´s device into primary role.
You need to do this before any access 
to the device, such as creating or mounting a file system.

drbdadm secondary
Brings the device back into secondary role.

Reference
https://manpages.ubuntu.com/manpages/xenial/en/man8/drbdadm.8.html


=================
Correct status
=================
root@SRV901G:~>% drbdadm  status
Ora_Exp role:Primary
  disk:UpToDate
  SRV902G role:Secondary
    peer-disk:UpToDate

Ora_Online role:Primary
  disk:UpToDate
  SRV902G role:Secondary
    peer-disk:UpToDate

db1 role:Primary
  disk:UpToDate
  SRV902G role:Secondary
    peer-disk:UpToDate

db2 role:Primary
  disk:UpToDate
  SRV902G role:Secondary
    peer-disk:UpToDate

root@SRV902G:~>% drbdadm  status
Ora_Exp role:Secondary
  disk:UpToDate
  SRV901G role:Primary
    peer-disk:UpToDate

Ora_Online role:Secondary
  disk:UpToDate
  SRV901G role:Primary
    peer-disk:UpToDate

db1 role:Secondary
  disk:UpToDate
  SRV901G role:Primary
    peer-disk:UpToDate

db2 role:Secondary
  disk:UpToDate
  SRV901G role:Primary
    peer-disk:UpToDate

=================
Not Correct Status
=================
root@SRVDBD901G:~>% drbdadm status
Ora_Exp role:Primary
  disk:UpToDate
  SRVDBD902G connection:StandAlone

Ora_Online role:Primary
  disk:UpToDate
  SRVDBD902G connection:StandAlone

db1 role:Primary
  disk:UpToDate
  SRVDBD902G connection:StandAlone

db2 role:Primary
  disk:UpToDate
  SRVDBD902G connection:StandAlone


root@SRVDBD902G:~>%  drbdadm status
Ora_Exp role:Secondary
  disk:UpToDate
  SRVDBD901G connection:StandAlone

Ora_Online role:Secondary
  disk:UpToDate
  SRVDBD901G connection:StandAlone

db1 role:Secondary
  disk:UpToDate
  SRVDBD901G connection:StandAlone

db2 role:Secondary
  disk:UpToDate
  SRVDBD901G connection:StandAlone



>% drbdadm status
Ora_Exp role:Secondary
  disk:Inconsistent open:no
  ro8-ogg-ora1 connection:Connecting

The Ora_Exp is stuck in Inconsistent state, and does not sync.

A. try to reboot the server.
B. Follow solution below, to rebuild drbd metadata.

In case the connection between sites cannot be restored, need to rebuild drbd metadata
1. check /var/log/messages
   Possible error: 
Jun  5 14:42:05 my_host kernel: drbd Ora_Exp my_host: conn( Connecting -> Connected ) peer( Unknown -> Secondary )
Jun  5 14:42:05 my_host kernel: drbd Ora_Exp/0 drbd4 my_host: drbd_sync_handshake:
Jun  5 14:42:05 my_host kernel: drbd Ora_Exp/0 drbd4 my_host: self A1AFF6AACC929146:4740BC40E4819C9C:54BF4A72763A34A6:0CA1C9B60B25B87E bits:8184550 flags:122
Jun  5 14:42:05 my_host kernel: drbd Ora_Exp/0 drbd4 my_host: peer D3401D4CCA4EA0C8:54BF4A72763A34A6:4740BC40E4819C9C:F0CF106B5ED25C7C bits:676 flags:120
Jun  5 14:42:05 my_host kernel: drbd Ora_Exp/0 drbd4 my_host: uuid_compare()=unrelated-data by rule 100
Jun  5 14:42:05 my_host kernel: drbd Ora_Exp/0 drbd4: Unrelated data, aborting!

The reason of the issue is that during split brain situation data has diverged beyond the point that the Peers no longer recognize each other’s generation identifiers.

The solution was to create the metadata again, and sync data. 

Run the following commands:

On Secondary node:
drbdadm down Ora_Exp
drbdadm wipe-md Ora_Exp
drbdadm create-md Ora_Exp
drbdadm up Ora_Exp
drbdadm disconnect Ora_Exp
drbdadm -- --discard-my-data connect Ora_Exp

Right after above, execute on Primary node:
drbdadm connect Ora_Exp

drbdadm status
drbdadm status


===============
Start drbd
===============
systemctl start drbd
systemctl status drbd
drbdadm status

===============
drbd utilities
===============
drbdmon - monitoring drbd utility
dmesg   - log message utility

Tuesday, July 26, 2022

Code Example - Run PL/SQL from bash.

===========
General:
===========
Example for Calling stored procedure from bash. 
In this case, the stored procedure is using input parameters to run EXECUTE IMMEDIATE statement using bind variables.

===========
Code
===========
cre_gwch.sh
cre_ga_w_counters_history.sql

cre_gwch.sh
 #!/bin/bash

USER_NAME=MY_USER
USER_PASS=MY_PASS
ORA_INST=orainst

WORK_DIR=`pwd`
HOSTNAME=`hostname`
FILE_NAME=`basename $0`
v_caller="'${WORK_DIR}/${FILE_NAME}@${HOSTNAME}'"

v_static_id='1'
v_counter_sum=2
v_counter_delta=3
v_dyn1='0'
v_dyn2='1'
v_dyn3='0'
v_dyn4='0'
v_dyn5='0'
v_is_processed=0
v_is_counter_restarted=0
v_ts_last_modified="'20220711 12:22:00'"
v_day=06
v_node_id=2131251
v_src_network_id='NULL'
v_ts_last_updated='NULL'
v_dyn_s1='NULL'
v_dyn_s2='NULL'
v_dyn_s3='NULL'
v_dyn_s4='NULL'
v_dyn_s5='NULL'
v_affiliate_id='NULL'
v_site_id=1

# echo "Running SQL exec cre_ga_w_counters_history($v_caller, $v_static_id, $v_counter_sum, $v_counter_delta, $v_dyn1, $v_dyn2, $v_dyn3, $v_dyn4, $v_dyn5, $v_is_processed, $v_is_counter_restarted, $v_ts_last_modified, $v_day, $v_node_id, $v_src_network_id, $v_ts_last_updated, $v_dyn_s1, $v_dyn_s2, $v_dyn_s3, $v_dyn_s4, $v_dyn_s5, $v_affiliate_id, $v_site_id);"

sqlplus -s  ${USER_NAME}/${USER_PASS}@${ORA_INST} <<EOF
set verify off define off  feedback off
BEGIN
  cre_ga_w_counters_history($v_caller, $v_static_id, $v_counter_sum, $v_counter_delta, $v_dyn1, $v_dyn2, $v_dyn3, $v_dyn4, $v_dyn5, $v_is_processed, $v_is_counter_restarted, $v_ts_last_modified, $v_day, $v_node_id, $v_src_network_id, $v_ts_last_updated, $v_dyn_s1, $v_dyn_s2, $v_dyn_s3, $v_dyn_s4, $v_dyn_s5, $v_affiliate_id, $v_site_id);
END;
/
commit;
exit;
EOF

cre_ga_w_counters_history.sql
CREATE OR REPLACE PROCEDURE CRE_GA_W_COUNTERS_HISTORY (
                            p_caller               IN VARCHAR2,
                            p_static_id            IN GA_W_COUNTERS_HISTORY.static_id%TYPE,
                            p_counter_sum          IN GA_W_COUNTERS_HISTORY.counter_sum%TYPE,
                            p_counter_delta        IN GA_W_COUNTERS_HISTORY.counter_delta%TYPE,
                            p_dyn1                 IN GA_W_COUNTERS_HISTORY.dyn1%TYPE,
                            p_dyn2                 IN GA_W_COUNTERS_HISTORY.dyn2%TYPE,
                            p_dyn3                 IN GA_W_COUNTERS_HISTORY.dyn3%TYPE,
                            p_dyn4                 IN GA_W_COUNTERS_HISTORY.dyn4%TYPE,
                            p_dyn5                 IN GA_W_COUNTERS_HISTORY.dyn5%TYPE,
                            p_is_processed         IN GA_W_COUNTERS_HISTORY.is_processed%TYPE,
                            p_is_counter_restarted IN GA_W_COUNTERS_HISTORY.is_counter_restarted%TYPE,
                            p_ts_last_modified     IN VARCHAR2,
                            p_day                  IN GA_W_COUNTERS_HISTORY.day%TYPE,
                            p_node_id              IN GA_W_COUNTERS_HISTORY.node_id%TYPE,
                            p_src_network_id       IN GA_W_COUNTERS_HISTORY.src_network_id%TYPE,
                            p_ts_last_updated      IN GA_W_COUNTERS_HISTORY.ts_last_updated%TYPE,
                            p_dyn_s1               IN GA_W_COUNTERS_HISTORY.dyn_s1%TYPE,
                            p_dyn_s2               IN GA_W_COUNTERS_HISTORY.dyn_s2%TYPE,
                            p_dyn_s3               IN GA_W_COUNTERS_HISTORY.dyn_s3%TYPE,
                            p_dyn_s4               IN GA_W_COUNTERS_HISTORY.dyn_s4%TYPE,
                            p_dyn_s5               IN GA_W_COUNTERS_HISTORY.dyn_s5%TYPE,
                            p_affiliate_id         IN GA_W_COUNTERS_HISTORY.affiliate_id%TYPE,
                            p_site_id              IN GA_W_COUNTERS_HISTORY.site_id%TYPE) IS

 v_sql_str     VARCHAR2(2000);
 v_module_name SGA_W_LOG.procedure_name%TYPE;
 v_msg_str     SGA_W_LOG.data%TYPE;
 
BEGIN
  
  v_module_name := 'CRE_GA_W_COUNTERS_HISTORY';
  
  v_msg_str := 'Starting from caller: '||p_caller;
  SUPPORT_UTIL_PKG.write_sga_w_log(v_module_name, v_msg_str);  
  
  v_sql_str:='INSERT INTO GA_W_COUNTERS_HISTORY (static_id, counter_sum, counter_delta, dyn1, dyn2, dyn3, dyn4, dyn5, is_processed, is_counter_restarted, ts_last_modified, day, node_id, src_network_id, ts_last_updated, dyn_s1, dyn_s2, dyn_s3, dyn_s4, dyn_s5, affiliate_id, site_id) VALUES (:1, :2, :3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, :14, :15, :16, :17, :18, :19, :20, :21, :22) ';

  EXECUTE IMMEDIATE v_sql_str USING p_static_id, p_counter_sum, p_counter_delta, p_dyn1, p_dyn2, p_dyn3, p_dyn4, p_dyn5, p_is_processed, p_is_counter_restarted, TO_DATE(p_ts_last_modified,'YYYYMMDD hh24:mi:ss'), p_day, p_node_id, p_src_network_id, p_ts_last_updated, p_dyn_s1, p_dyn_s2, p_dyn_s3, p_dyn_s4, p_dyn_s5, p_affiliate_id, p_site_id;

EXCEPTION
  WHEN OTHERS THEN
    v_msg_str := 'Unexpected Error from caller: '||p_caller;
    SUPPORT_UTIL_PKG.write_sga_w_log(v_module_name, v_msg_str);
    v_msg_str := 'Error : '||SQLERRM;
    SUPPORT_UTIL_PKG.write_sga_w_log(v_module_name, v_msg_str);
    RAISE;
END CRE_GA_W_COUNTERS_HISTORY;
/

Wednesday, June 8, 2022

When setting the table to NOLOGGING, what is the expected result?

When setting the table to NOLOGGING, what is the expected result?

The actual result would depend if database is in ARCHIVE MODE or not, and if the INSERT on table is in APPEND mode or not.

Table Mode  Insert Mode   ArchiveLog mode Result
----------- ------------- ----------------- --------------
LOGGING     APPEND   ARCHIVE LOG redo generated  NOLOGGING   APPEND   ARCHIVE LOG         no redo
LOGGING     NO APPEND   ARCHIVE LOG redo generated
NOLOGGING   NO APPEND   ARCHIVE LOG redo generated

LOGGING     APPEND   NOARCHIVE LOG MODE no redo
NOLOGGING   APPEND   NOARCHIVE LOG MODE no redo
LOGGING     NO APPEND   NOARCHIVE LOG MODE redo generated
NOLOGGING   NO APPEND   NOARCHIVE LOG MODE redo generated

Monday, May 16, 2022

Stop Cluster, unmount and remount oracle shared storage, Start Cluster .

===========
General
===========
In short:
Stop Cluster
unmount  Oracle shared storage
Do DBA work
remount Oracle shared storage
Start Cluster.

How to know if this is a Veritas or Pacemaker?
getaclu
VCS - > Veritas
PMK -> pacemaker

Starhome Technote
http://10.135.10.64/portal/projects/howto/mount-cl-fs-locally.html

=====================
Pacemaker
=====================

=============
Stop the cluster 
==============
Stop the cluster

#> pcs cluster stop --all

#> pcs status cluster
Error: cluster is not currently running on this node

Tag and enable 
#> for i in $(vgscan |grep Ora | cut -d '"' -f 2) ;do vgchange --addtag sometag $i ; vgchange -ay --config 'activation{volume_list=["@sometag"]}' $i ; done

  Volume group "OraVg3" successfully changed
  1 logical volume(s) in volume group "OraVg3" now active
  Volume group "OraVg2" successfully changed
  2 logical volume(s) in volume group "OraVg2" now active
  Volume group "OraVg1" successfully changed
  1 logical volume(s) in volume group "OraVg1" now active

Mount locally
#> mount -t xfs -f -b size=4096 -m crc=0 /dev/OraVg1/db1 /oracle_db/db1
#> mount -t xfs -f -b size=4096 -m crc=0  /dev/OraVg2/Ora_Exp /backup/ora_exp
#> mount -t xfs -f -b size=4096 -m crc=0  /dev/OraVg2/Ora_Online /backup/ora_online
#> mount -t xfs -f -b size=4096 -m crc=0  /dev/OraVg3/db2 /oracle_db/db2

or
mount /dev/OraVg1/db1 /oracle_db/db1
mount /dev/OraVg2/Ora_Exp /backup/ora_exp
mount /dev/OraVg2/Ora_Online /backup/ora_online
mount /dev/OraVg3/db2 /oracle_db/db2

==============
Perform Database Restore
==============

==============
Start the cluster 
==============
Unmount it all locally:
#> umount -f /mnt/oratmp /oracle_db/db1 /backup/ora_exp /backup/ora_online /oracle_db/db2

umount /oracle_db/db1
umount /oracle_db/db2
umount /backup/ora_exp
umount /backup/ora_online


Delete tag and deactivate 

#> for i in $(vgscan |grep Ora | cut -d '"' -f 2) ;do vgchange -an $i ; vgchange --deltag sometag $i ; done

Restart the cluster 
#> pcs cluster start --all

=====================
pcs commands
=====================
pcs cluster stop --all
pcs status cluster

=====================
VCS
=====================
Take screenshot of current status
df -hP | grep ora
/dev/vx/dsk/OraDg1/db1        79G   26G   54G  33% /oracle_db/db1
/dev/vx/dsk/OraDg2/Ora_Online 159G   16G  143G 10% /backup/ora_online
/dev/vx/dsk/OraDg2/Ora_Exp    100G  7.0G   93G  8% /backup/ora_exp
/dev/vx/dsk/OraDg3/db2        199G  662M  197G  1% /oracle_db/db2

Stop Cluster
hastop -all 
or
hastop -all -force

Perioticly check cluster status until it is unavailable - like the following message:
hastatus -summary

VCS ERROR V-16-1-10600 Cannot connect to VCS engine
VCS WARNING V-16-1-11046 Local system not available

Force stop oracle service, in case of PARTIAL status which cannot be resolved.
sudo hagrp -flush -force <service_group> -sys <host_group>
sudo hagrp -flush -force ora_igt_sg -sys apu-rm

or freeze just the oracle group
hagrp -freez ora_igt_sg

Mount locally the oracle mount points
vxdg import OraDg1
vxdg import OraDg2
vxdg import OraDg3

vxvol -g OraDg1 startall
vxvol -g OraDg2 startall
vxvol -g OraDg3 startall

mount -t vxfs /dev/vx/dsk/OraDg1/db1        /oracle_db/db1
mount -t vxfs /dev/vx/dsk/OraDg2/Ora_Online /backup/ora_online
mount -t vxfs /dev/vx/dsk/OraDg2/Ora_Exp    /backup/ora_exp
mount -t vxfs /dev/vx/dsk/OraDg3/db2        /oracle_db/db2

df -hP | grep ora

Do the Oracle stuff

Dismount locally the oracle mount points

umount /oracle_db/db1 
umount /backup/ora_online
umount /backup/ora_exp
umount /oracle_db/db2

vxvol -g OraDg1 stopall
vxvol -g OraDg2 stopall
vxvol -g OraDg3 stopall

vxdg deport OraDg1
vxdg deport OraDg2
vxdg deport OraDg3

Start the service
Run the following command on ALL cluster nodes:
node a
hastart

node b
hastart


===========
Additional Commands
===========
move service to another node
as root
pcs status
pcs resource cleanup ora_igt_rg
pcs resource disable ora_igt_rg
pcs resource enable ora_igt_rg
pcs resouce show ora_igt_rg

To create a service
as root Check on oracle service definition
/etc/sysconfig/env.oracledb 

for oracle service - check this file:
/etc/systemd/system/dbora.service
This defines the oracle service, ORACLE_HOME, ORACLE_SID
/etc/sysconfig/evn.oracledb

run this:
systemctl status dbora
systemctl status dbora.service
systemctl start dbora.service
systemctl deamon
pcs resource create dbora_igt_ap systemd:dbora op stop interval=0 timeout=120s on-fail="block" monitor interval=30s timeout=600s start interval=0 timeout=120s --group ora_igt_rg

pacemaker cluster commands info
pcs status - this will show cluster status
pcs resource show - this will show current node status
pcs resource show dbora_igt_ap - this will show oracle service info
 Resource: dbora_igt_ap (class=systemd type=dbora)
  Operations: monitor interval=30s timeout=600s (dbora_igt_ap-monitor-interval-30s)
              start interval=0 timeout=120s (dbora_igt_ap-start-interval-0)
              stop interval=0 on-fail=block timeout=120s (dbora_igt_ap-stop-interval-0)

pacemaker cluster commands oracle
pcs resource move ora_igt_rg PIPNVHED901G
pcs resource cleanup ora_igt_rg 
pcs resource disable ora_igt_rg
pcs resource enable ora_igt_rg

pacemaker cluster commands restart oracle service
pcs status
pcs resource cleanup ora_igt_rg
pcs resource disable ora_igt_rg
pcs resource enable ora_igt_rg
pcs resource restart ora_igt_rg PIPNVHED901G
pcs status

pacemaker cluster commands other

--pcs resource disable oracle
--pcs resource enable oracle/19/dbhome_1/rdbms/log/startup



Check corosync in short
root>% vi /etc/corosync/corosync.conf 
root>% pcs cluster sync
server901G: Succeeded
server902G: Succeeded
root>% pcs cluster reload corosync
Corosync reloaded
root>% corosync-cmapctl | grep totem.token
runtime.config.totem.token (u32) = 5000
runtime.config.totem.token_retransmit (u32) = 1190
runtime.config.totem.token_retransmits_before_loss_const (u32) = 4
totem.token (u32) = 5000

Change corosync timeout
1. Edit /etc/corosync/corosync.conf on one of the cluster nodes
Add the required line if does not exist or update the value if the line does exist.
For 5 seconds, set the value to 5000 msec.

totem {
   version: 2
   secauth: off
   cluster_name: rhel7-cluster
   transport: udpu
   rrp_mode: passive
   token: 15000      <--- If this line is missing, add it, otherwise update the value.-->
}

2. Propagate the updated corosync.conf to the rest of the nodes as follows:
pcs cluster sync

3. Reload corosync.
    This command can be run from one node to reload corosync on all nodes and does not require a downtime.
pcs cluster reload corosync

4. Confirm changes
corosync-cmapctl | grep totem.token

For example:
corosync-cmapctl | grep totem.token
runtime.config.totem.token (u32) = 5000
runtime.config.totem.token_retransmit (u32) = 1190
runtime.config.totem.token_retransmits_before_loss_const (u32) = 4

Thursday, May 12, 2022

User Permissions SQL Server


db_owner
Members of the  fixed database role can perform all configuration and maintenance activities on the database, and can also drop the database in SQL Server. 
db_datawriter
Members of the db_datawriter fixed database role can add, delete, or change data in all user tables.
db_ddladmin
Members of the db_ddladmin fixed database role can run any Data Definition Language (DDL) command in a database.


To change User permissions:
Database -> Security -> Users -> Properties -> membership -> add use to the required group