Apps DBA Concepts

Just another WordPress.com weblog

Archive for the ‘Scripts’ Category

Scripts will be useful Apps DBA Life . Please use the script at your own risk .

Deleting Windows Services using perl

Posted by vasselva on June 2, 2008

Use it at your own risk

serviceDel.pl

print “Deleting Windows Services perl….\n”;
my $cmd =”sc query \”<SERVICE NAME>\” | grep RUNNING | cut -c33-“;
my $ret =`$cmd`;
chomp($ret);
$ret =~ s/^\s+//;
$ret =~ s/\s+$//;

if(“$ret” eq “RUNNING”){
my $cmd = “sc stop \”<SERVICE NAME>\””;
my $rt=system($cmd);
print “Stop service returned $rt…\n”;
}

while(true){
sleep(5);
my $cmd =”sc query \”<SERVICE NAME>\” | grep STOPPED | cut -c33-“;
my $c = `$cmd`;
chomp($c);
$c =~ s/^\s+//;
$c =~ s/\s+$//;
if ( “$c” eq “STOPPED”){print “SERVICE STOPPED \n”;last;}
print “SERVICE iS RUNNING \n”;
}

my $cmd = “sc delete \”<SERVICE NAME>\””;
my $rt  =  system($cmd);
print “Delete Service returned $rt…\n”;

Posted in Scripts | Leave a Comment »

Script to unlock the schema

Posted by vasselva on May 19, 2008

_____________________________________________________________________________________________________________________________
REM Script to unlock the schema
set linesize 132
select owner,table_name from dba_tab_statistics where  stattype_locked is not null and owner not in (‘SYS’,’SYSTEM’) ;
/
DECLARE
v_table1 VARCHAR2(30);
v_owner1 VARCHAR2(30);
cursor C1 is select owner,table_name from dba_tab_statistics where
stattype_locked is not null and owner not in (‘SYS’,’SYSTEM’) ;
BEGIN
OPEN C1;
loop
fetch C1 into v_owner1,v_table1;
exit when C1%NOTFOUND;
dbms_stats.unlock_schema_stats(v_owner1);
dbms_stats.unlock_table_stats(v_owner1,v_table1);
end loop;
close C1;
END;
/
select owner,table_name from dba_tab_statistics where  stattype_locked is not null and owner not in (‘SYS’,’SYSTEM’) ;
_____________________________________________________________________________________________________________________________

Posted in Scripts | 1 Comment »

Free Space SQL

Posted by vasselva on May 15, 2008

Free Space query
—————

SELECT dbaspace.tablespace_name “Tablespace Name”,
nvl(sum(dbaspace.total_space),0) “Total”,
nvl((sum(dbaspace.total_space) – sum(dbaspace.free_space)),0) “Used”,
nvl(sum(dbaspace.free_space),0) “Free”,
nvl((sum(dbaspace.free_space)/sum(dbaspace.total_space)*100),0) “Free Percentage”
FROM
(
select tablespace_name,0 total_space,sum(bytes/(1024*1024)) free_space
from dba_free_space
group by tablespace_name
union
select tablespace_name,0 total_space,sum(bytes/(1024*1024)) free_space
from dba_temp_files
group by tablespace_name
union
select tablespace_name,sum(bytes/(1024*1024)) total_space,0 from
dba_data_files
group by tablespace_name
union
select tablespace_name,sum(bytes/(1024*1024)) total_space,0 from
dba_temp_files
group by tablespace_name) dbaspace
group by dbaspace.tablespace_name
order by dbaspace.tablespace_name
/

Posted in Scripts | Leave a Comment »