0% found this document useful (0 votes)
181 views

DBA Scripts

The document contains SQL queries and commands for managing database objects, sessions, and performance in an Oracle database including: 1. Queries to view tablespace sizes, data files, tables, constraints, table sizes, active sessions, blocked objects, and invalid objects. 2. Commands to increase a tablespace size, kill sessions, move tables between tablespaces, rebuild indexes, and compile invalid objects. 3. Queries to view SQL statements from a session, PGA statistics, and fragmentation in tablespaces.

Uploaded by

miguelangelcg25
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
181 views

DBA Scripts

The document contains SQL queries and commands for managing database objects, sessions, and performance in an Oracle database including: 1. Queries to view tablespace sizes, data files, tables, constraints, table sizes, active sessions, blocked objects, and invalid objects. 2. Commands to increase a tablespace size, kill sessions, move tables between tablespaces, rebuild indexes, and compile invalid objects. 3. Queries to view SQL statements from a session, PGA statistics, and fragmentation in tablespaces.

Uploaded by

miguelangelcg25
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

--ESPACIO LIBRE EN TABLESPACE select t.tbt tablespace, t.total/1024/1024 "total MB", (t.total-u.

libre)/1024/10 24 "Ocupado MB" from (select sum(bytes) total,tablespace_name tbt from dba_data_files group by tablespace_name) t,(select sum(bytes) libre, tables pace_name tbu from dba_free_space group by tablespace_name) u where t.tbt=u.tbu / --AUMENTAR TAMA O DE TABLESPACE ALTER DATABASE DATAFILE 'C:\ORACLEXE\ORADATA\XE\USERS.DBF' RESIZE 3725M / --DATA FILES select FILE_NAME from dba_data_files / --TABLAS select * from dba_tables where owner = 'PORTAL' / --constraints que referencian a una tabla select owner,constraint_name,constraint_type,table_name,r_owner,r_constraint_nam e from all_constraints where constraint_type='R' and r_constraint_name in (select constraint_name from all_constraints where constraint_type in ('P','U') and table_name='PORTAL_INTERMEDIARIOS'); / --TAMA O DE LAS TABLAS select t.table_name, sum(bytes)/(1024*1024) MB from dba_tables T, dba_segments S where s.segment_name = t.table_name AND T.OWNER = 'SLABI' and t.table_name not like 'OWB%' group by t.table_name order by 2 desc, 1 / --SESIONES EN LA BBDD select sid, serial#, username, osuser, machine, program from v$session where osuser = 'leala' / --MATAR UNA SESION ALTER SYSTEM KILL SESSION '358,72' immediate; /

--MATAR SESIONES DE UN USUARIO select 'alter system kill session ' chr(39) s.sid ',' s.serial# chr(39) ' immediate;' from v$process p, v$session s where --p.spid= '&1' s.paddr = p.addr and s.username = 'APEX_PUBLIC_USER' order by spid /

select s.osuser, s.username, s.sid ',' s.serial# "SID,SERIAL", s.process "Client", p.spid "Server", p.program, s.program, s.status, s.sql_address, s.sql_hash_value from v$process p, v$session s where s.paddr = p.addr order by status / --OBJETOS BLOQUEADOS select --'alter system kill session ' chr(39) s.sid ',' s.serial# chr(39) ' immediate;' c.owner, c.object_name, c.object_type, s.sid, s.serial#, s.status, s.osuser, s.machine from v$locked_object a , v$session s, dba_objects c where s.sid = a.session_id and a.object_id = c.object_id --and object_name = 'COT_FINANCIAMIENTO' / --##COMPACTAR TABLAS --Mover tablas a otro TS SELECT 'alter table ANDES.' table_name ' ' 'move tablespace BASURA storage (initial 100K);' from dba_tables where owner='ANDES' AND tablespace_name='T_ANDES' --Mover de vuelta las tablas al TS original SELECT 'alter table' owner '.' table_name ' ' 'move

tablespace T_ANDES storage (initial 100K);' from dba_tables where owner='ANDES' AND tablespace_name='T_ANDES' --Reconstruir indices select 'alter index ' table_owner '.' index_name ' rebuild nologging tablespace ' tablespace_name ' online;' from DBA_indexes WHERE tablespace_name='T_ANDES' / --Fragmentacin de TS, a mayor % de indice de fragmentacion menor select tablespace_name, count(*) free_chunks, decode( round((max(bytes) / 1024000),2), null,0, round((max(bytes) / 1024000),2)) largest_chunk, 100 - nvl(round(sqrt(max(blocks)/sum(blocks))*(100/sqrt(sqrt(count(blocks)) ) ),2), 0) fragmentation_index from sys.dba_free_space group by tablespace_name order by 2 desc, 1; / --COMPILAR OBJETOS INVALIDOS SET SERVEROUTPUT ON SIZE 1000000 BEGIN FOR cur_rec IN (SELECT owner, object_name, object_type, DECODE(object_type, 'PACKAGE', 1, 'PACKAGE BODY', 2, 2) AS recompile_ order FROM dba_objects WHERE object_type IN ('PACKAGE', 'PACKAGE BODY') AND status != 'VALID' ORDER BY 4) LOOP BEGIN IF cur_rec.object_type = 'PACKAGE' THEN EXECUTE IMMEDIATE 'ALTER ' cur_rec.object_type ' "' cur_rec.owner '"."' cur_rec.object_name '" COMPILE' ; ElSE EXECUTE IMMEDIATE 'ALTER PACKAGE "' cur_rec.owner '"."' cur_rec.object_name '" COMPILE BODY'; END IF; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.put_line(cur_rec.object_type ' : ' cur_rec.owner ' : ' cur_rec.object_name); END;

END LOOP; END; / --CONSULTAS SQL DE UNA SESION SELECT sq.sql_text, s.username, s.machine, s.sid, s.serial#, p.spid FROM v$session s, v$sqltext_with_newlines sq, v$process p WHERE --s.sid = 159 --AND s.serial# = 24488 s.sql_address = sq.address AND --s.machine = 'SRV-BI' AND s.sql_hash_value = sq.hash_value and s.paddr = p.addr ORDER BY s.sid, s.serial#, sq.piece / --PGA --Estadsticas de rendimiento select name,value --/1024/1024 from v$pgastat where name in ('aggregate PGA target parameter', 'aggregate PGA auto target', 'total PGA inuse', 'total PGA allocated', 'over allocation count', 'extra bytes read/written', 'cache hit percentage'); /

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy