Search This Blog

Total Pageviews

Thursday 8 June 2017

DataFile Resize script

Oracle DataFile Resize script  ..


--- Oracle version 9 and higher 
REM -----------------------------------------------

set serveroutput on
exec dbms_output.enable(1000000);

declare

cursor c_dbfile is
select f.tablespace_name,f.file_name,f.file_id,f.blocks,t.block_size,decode(t.allocation_type,'UNIFORM',t.initial_extent/t.block_size,0) uni_extent
,decode(t.allocation_type,'UNIFORM',(128+(t.initial_extent/t.block_size)),128) file_min_size from dba_data_files f,dba_tablespaces t
where f.tablespace_name = t.tablespace_name
and t.status = 'ONLINE'
and t.tablespace_name='ANUJ'  ---- <<<<<<<<<<<<<<<<<<<<<TableSpace Name 
order by f.tablespace_name,f.file_id;

cursor c_freespace(v_file_id in number) is
select block_id, block_id+blocks max_block from dba_free_space
where file_id = v_file_id
order by block_id desc;

/* variables to check settings/values */
dummy number;
checkval varchar2(10);
block_correction number;

/* running variable to show (possible) end-of-file */
file_min_block number;

/* variables to check if recycle_bin is on and if extent as checked is in ... */
recycle_bin boolean:=false;
extent_in_recycle_bin boolean;

/* exception handler needed for non-existing tables note:344940.1 */
sqlstr varchar2(100);
table_does_not_exist exception;
pragma exception_init(table_does_not_exist,-942);

/* variable to spot space wastage in datafile of uniform tablespace */
space_wastage number;

begin

/* recyclebin is present in Oracle 10.2 and higher and might contain extent as checked */
begin
select value into checkval from v$parameter where name = 'recyclebin';
if checkval = 'on'
then
recycle_bin := true;
end if;
exception
when no_data_found
then
recycle_bin := false;
end;

/* main loop */
for c_file in c_dbfile
loop
/* initialization of loop variables */
dummy :=0;
extent_in_recycle_bin := false;
file_min_block := c_file.blocks;

begin

space_wastage:=0; /* reset for every file check */

<<check_free>>

for c_free in c_freespace(c_file.file_id)
loop
/* if blocks is an uneven value there is a need to correct 
with -1 to compare with end-of-file which is even */
block_correction := (0-mod(c_free.max_block,2));
if file_min_block = c_free.max_block+block_correction
then

/* free extent is at end so file can be resized */
file_min_block := c_free.block_id;

/* Uniform sized tablespace check if space at end of file
is less then uniform extent size */
elsif (c_file.uni_extent !=0) and ((c_file.blocks - c_free.max_block) < c_file.uni_extent) 
then

/* uniform tablespace which has a wastage of space in datafile 
due to fact that space at end of file is smaller than uniform extent size */

space_wastage:=c_file.blocks - c_free.max_block;
file_min_block := c_free.block_id;

else
/* no more free extent at end of file, file cannot be further resized */
exit check_free;
end if;
end loop;
end;

/* check if file can be resized, minimal size of file 128 {+ initial_extent} blocks */
if (file_min_block = c_file.blocks) or (c_file.blocks <= c_file.file_min_size)
then

dbms_output.put_line('Tablespace: '||c_file.tablespace_name||' Datafile: '||c_file.file_name);
dbms_output.put_line('cannot be resized no free extents found');
dbms_output.put_line('.');

else

/* file needs minimal no of blocks which does vary over versions, 
using safe value of 128 {+ initial_extent} */
if file_min_block < c_file.file_min_size
then
file_min_block := c_file.file_min_size;
end if;


dbms_output.put_line('Tablespace: '||c_file.tablespace_name||' Datafile: '||c_file.file_name);
dbms_output.put_line('current size: '||(c_file.blocks*c_file.block_size)/1024||'K'||' can be resized to: '||round((file_min_block*c_file.block_size)/1024)||'K (reduction of: '||round(((c_file.blocks-file_min_block)/c_file.blocks)*100,2)||' %)');


/* below is only true if recyclebin is on */
if recycle_bin
then
begin
sqlstr:='select distinct 1 from recyclebin$ where file#='||c_file.file_id;
execute immediate sqlstr into dummy;

if dummy > 0
then

dbms_output.put_line('Extents found in recyclebin for above file/tablespace');
dbms_output.put_line('Implying that purge of recyclebin might be needed in order to resize');
dbms_output.put_line('SQL> purge tablespace '||c_file.tablespace_name||';');
end if;
exception
when no_data_found
then null;
when table_does_not_exist
then null;
end;
end if;
dbms_output.put_line('SQL> alter database datafile '''||c_file.file_name||''' resize '||round((file_min_block*c_file.block_size)/1024)||'K;');

if space_wastage!=0
then
dbms_output.put_line('Datafile belongs to uniform sized tablespace and is not optimally sized.');
dbms_output.put_line('Size of datafile is not a multiple of NN*uniform_extent_size + overhead');
dbms_output.put_line('Space that cannot be used (space wastage): '||round((space_wastage*c_file.block_size)/1024)||'K');
dbms_output.put_line('For optimal usage of space in file either resize OR increase to: '||round(((c_file.blocks+(c_file.uni_extent-space_wastage))*c_file.block_size)/1024)||'K');
end if;

dbms_output.put_line('.');

end if;

end loop;

end;
/

Saturday 3 June 2017

Oracle Rac setup ssh key

Oracle Rac setup ssh key ..

setup ssh key

 Host detail !!
orarac12a  192.168.0.41
orarac12b  192.168.0.45


Imp!!!!
make a .ssh directory under user home directory on all nodes

mkdir ~/.ssh
chmod 700 ~/.ssh
cd ~/.ssh


[grid@orarac12a ~]$ mkdir ~/.ssh
[grid@orarac12a ~]$ chmod 700 ~/.ssh
[grid@orarac12a ~]$ cd ~/.ssh

command ssh-keygen -N '' -t rsa initiated the creation of the key pair without any password. private key will be  saved in .ssh/id_rsa. 

[grid@orarac12a .ssh]$ ssh-keygen -t rsa -N '' -f id_rsa
Generating public/private rsa key pair.
Your identification has been saved in id_rsa.
Your public key has been saved in id_rsa.pub.
The key fingerprint is:
6b:86:bf:f3:88:7b:7e:5c:fb:19:61:bd:34:ab:e0:98 grid@orarac12a
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|                 |
|               . |
|        S     oo.|
|       . .  ....+|
|      . +. o ..o |
|       =o.* o .o |
|      o+=E.. oo  |
+-----------------+

to  append the authorized keys

[grid@orarac12a .ssh]$ cat id_rsa.pub > authorized_keys

[grid@orarac12a .ssh]$ ls -ltr
total 12
-rw-r--r--. 1 grid oinstall  396 Jun  3 10:07 id_rsa.pub
-rw-------. 1 grid oinstall 1675 Jun  3 10:07 id_rsa
-rw-r--r--. 1 grid oinstall  396 Jun  3 10:07 authorized_keys

[grid@orarac12a .ssh]$ cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIdWRKqwbanBGpx1KJUSdN/T4ozvyBfmSU/WC5HaiHgHRXRDfQ8S6pd02j/2MzmQ7LH7BhLefcRiiaeqd6+DxOOqVDGQ0iciVEYyjqenlgnVSVy1fgMda85XTFP5H0xFiiAS+gJq7CxTr57ixrCRLsjpLNUkr8Kc45lI52l9kBHBl+1zAqliImVYj96+fbx96xwkpj2x2AltNlXyzg7v+Mv3jJM4Fs9BoDmPusYQvP4rFYS70GmuQtwCztoiHjMK7RoQ2rt8KFv+W0zdlpuKOh/d6/ec4HrJwLhXrrSd4ivgjLhej3XmRtAUB2pwGatEi0wmJG6heD7QcqVWiCHN3l grid@orarac12a


######################################################################################
Repeat this action for every node in the the cluster, until you've added the last node  
######################################################################################

To copy the key to other node 

[grid@orarac12a .ssh]$ ssh-copy-id grid@192.168.0.45
The authenticity of host '192.168.0.45 (192.168.0.45)' can't be established.
ECDSA key fingerprint is b4:c0:5d:61:87:5b:f9:15:a8:c3:61:ba:f6:13:87:03.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
grid@192.168.0.45's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'grid@192.168.0.45'"
and check to make sure that only the key(s) you wanted were added.

[grid@orarac12a .ssh]$ ls -ltr
total 16
-rw-r--r--. 1 grid oinstall  396 Jun  3 10:07 id_rsa.pub
-rw-------. 1 grid oinstall 1675 Jun  3 10:07 id_rsa
-rw-r--r--. 1 grid oinstall  174 Jun  3 10:10 known_hosts
-rw-r--r--. 1 grid oinstall  792 Jun  3 10:10 authorized_keys


and from other node 

ssh-copy-id grid@192.168.0.41


[grid@orarac12a .ssh]$ ssh 192.168.0.45
Last login: Sat Jun  3 10:04:52 2017

Oracle DBA

anuj blog Archive