Quantcast
Channel: SCN : All Content - SAP NetWeaver Technology Platform
Viewing all articles
Browse latest Browse all 1967

How to speed up client deletions

$
0
0
When deleting large clients, long
runtimes are often a problem. Parallelism can help, but the real
bottleneck are large tables. So maybe this guide can help. The SQL
statements are for Oracle databases with SAPSR3 layout, for other
databases or layouts you have to modify them.

Manual deletion of tables

First
of all, you need to identify large, client specific tables. E. g. in
IS-U systems candidates are DFKKOP or SWWCNTP0. These tables are client
specific, so you can easily find out if the table can be truncated
without harming the other clients:
  1. SELECT mandt, count( * ) FROM sapsr3.dfkkop GROUPBY mandt; 
or
  1. SELECT client, count( * ) FROM sapsr3.swwcntp0 GROUPBY mandt; 
As
result, you see the number of rows for each client. When only the
client you want to delete has rows, you can truncate the tables
beforehand. This will significantly speed up the client deletion.

Copy & deletion of "unbalanced" tables

When
you identify tables, where only a few rows are contained in the clients
which will remain in the system and a huge amount of rows in the client
you want to delete, you can first copy all remaining rows in a new
table (assuming you want to delete client 100):
  1. CREATE TABLE sapsr3."dfkkop_tmp" TABLESPACE psapsr3 NOLOGGING PARALLEL 8 AS 
  2. SELECT /*+ INDEX("dfkkop""dfkkop~0") */ * FROM sapsr3."dfkkop"WHERE mandt NOTIN ('100'): 
After that, you just have to truncate the original table and insert all rows from the temp table:
  1. TRUNCATE TABLE sapsr3."dfkkop"
  2. INSERT INTO sapsr3."dfkkop"SELECT * FROM"dfkkop_tmp"
  3. COMMIT; 
  4. ALTER INDEX sapsr3."dfkkop~0" REBUILD ONLINE; 
Rebuilding the primary index is a good thing to speed up the client deletion afterwards.

Automation of finding tables / preparing statements

If
there are many huge tables and the time windows is very small, you may
use a scripting language to prepare the SQL statements. I prefer Perl,
as I know this language and as Oracle comes with Perl and the DBI
module. Connecting to your database is pretty simple:
  1. use DBI; 
  2. my $sid = "<SID>"; 
  3. my $hostname = "localhost"; 
  4. my $port = "<listener port>"; 
  5. my $sappw = "<password>"; 
  6. my $sapuser = "SAPSR3"; 
  7. my $connection = DBI->connect("DBI:Oracle:SID=$sid;host=$hostname;port=$port","$sapuser/$sappw") || die "Can't connect to $sid: $!"; 
You can start the script with $ORACLE_HOME/perl/bin/perl script.pl as oracle owner. Next
step will be to determine all client specific tables - in most cases,
the first column is named client, mandt or mandant. Here is a code
snippet which will give you number of rows in the remaining clients and
overall rows, you just have to adjust to your needs:
  1. my $mandt_exclude = '100'; 
  2. my $sql_all_tables = "SELECT object_name FROM dba_objects WHERE owner = 'SAPSR3' AND object_type = 'TABLE' ORDER BY object_name ASC"; 
  3. my $all_cursor = $connection->prepare($sql_all_tables); 
  4. $all_cursor->execute(); 
  5. while (my @table = $all_cursor->fetchrow_array) { 
  6. $sql_first_column = "SELECT table_name, column_name FROM dba_cons_columns WHERE table_name = '$table[0]' AND constraint_name = ( SELECT MIN( constraint_name ) FROM dba_cons_columns WHERE table_name = '$table[0]' )"; 
  7. my $first_col_cursor = $connection->prepare($sql_first_column); 
  8. $first_col_cursor->execute(); 
  9. while (my @col = $first_col_cursor->fetchrow_array) { 
  10.   if ($col[1] eq "CLIENT" or $col[1] eq "MANDANT" or $col[1] eq "MANDT") { 
  11.    $sql_count_all = "SELECT count( * ) FROM \"$table[0]\""; 
  12.    my $count_all_cursor = $connection->prepare($sql_count_all); 
  13.    $count_all_cursor->execute(); 
  14.    while (my @exc = $count_all_cursor->fetchrow_array) { 
  15. <Put your custom logic here> 
  16.    } 
  17.    $sql_count_exclude_mandt = "SELECT count( * ) FROM \"$table[0]\" WHERE $col[1] NOT IN ($mandt_exclude)"; 
  18.    my $count_exclude_cursor = $connection->prepare($sql_count_exclude_mandt); 
  19.    $count_exclude_cursor->execute(); 
  20.    while (my @exc = $count_exclude_cursor->fetchrow_array) { 
  21. <Put your custom logic here> 
You just have to add some output to build the SQL scripts.

Viewing all articles
Browse latest Browse all 1967

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>