Wednesday, August 21, 2013

To add up column values in a file - UNIX

To all up all the values in a particular column of a file in unix use below command

Ex: sample.txt contains below data
10 20 30
40 50 60
70 80 90

Now I want to add all values in column two of above file sample.txt

$ cat sample.txt | awk -F' '  '{print $2}'  | awk '{total = total +$1}END{print total}'

Output: 150

How to rename or unzip or untar and vice-versa all files in a directory with same file extension - UNIX

To rename or unzip or untar and vice-versa all files in a directory use below commands

Command:
$ for i in `ls -latr *.txt.2013 | awk '{print $9}'`
do
mv $i `basename $i .2013`
done

The above command will rename all files in a directory for example test01.txt.2013, test02.txt.2013, test03.txt.2013 to test01.txt, test02.txt, test03.txt

Note: All lines after $ symbol line together form the command.

A similar command can be used to unzip or untar all files in a directory

Command:

$ for i in `ls -latr *.txt.gz | awk '{print $9}'`
do
gunzip $i
done

The above command will unizp all files in a directory for example test01.txt.gz, test02.txt.gz, test03.txt.gz to test01.txt, test02.txt, test03.txt

Note: All lines after $ symbol line together form the command.


How to print or trim end characters of a string/line in UNIX

The commands below help in printing end characters of a line or a string. I assume that ORACLE_SID is set to "TESTDB" for examples below.

Print last one character from ORACLE_SID: 

$ echo $ORACLE_SID | sed -e "s/^.*\(.\)$/1/"
Output: B

Print last two characters:
$ echo $ORACLE_SID | sed -e "s/^.*\(..\)$/1/"
Output: DB

Print last three characters:
$ echo $ORACLE_SID | sed -e "s/^.*\(...\)$/1/"
Output: TDB

The commands below help in trimming end characters of a line or a string.  I assume that ORACLE_SID is set to "TESTDB" for examples below.

Trims last one character:
$ echo $ORACLE_SID | sed 's/.$//'
Output: TESTD

Trims last two characters:
$ echo $ORACLE_SID | sed 's/..$//'
Output: TEST

Trims last three characters:
$ echo $ORACLE_SID | sed 's/...$//'
Output: TES

SQL Query to find top SQL's with two specific AWR Snapshots

SQL:

WITH subq as
(SELECT *
    FROM (SELECT s.sql_id,
                                  SUM(nvl(s.executions_delta, 0)) execs,
                                  SUM(round(s.elapsed_time_delta / 1000000, 3)) exec_time,
                                  SUM(round(s.buffer_gets_delta)) io_logical,
                                  SUM(round(s.cpu_time_delta / 1000000, 3)) cpu_time,
                                  SUM(nvl(s.parse_calls_delta, 0)) parse_calls,
                                  SUM(round(s.iowait_delta / 1000000, 3)) io_wait,
                                  SUM(nvl(s.disk_reads_delta, 0)) disk_reads
                     FROM dba_hist_sqlstat s, dba_hist_snapshot ss
                  WHERE s.snap_id BETWEEN start_snap_id AND end_snap_id
                        AND ss.snap_id = s.snap_id
                        AND ss.instance_number = s.instance_number
                        AND s.executions_delta > 0
                 GROUP BY s.sql_id
                 ORDER BY exec_time DESC)
  WHERE rownum < num_of_sqls)
SELECT subq.*, substr(sql_text, 1, 8000) sqltext
    FROM dba_hist_sqltext st, subq
 WHERE st.sql_id=subq.sql_id
 ORDER BY 3 desc

Things to replace in above sql before executing:

start_snap_id: replace this with starting AWR snapshot number of your database from your peak day snapshots for the period which you want collect the top SQL's. For example: Starting snapshot of database TEST on wednesday at 9AM is 12345.

end_snap_id: replace this with ending AWR snapshot number of your database from your peak day snapshots for the period which you want collect the top SQL's. For example: Ending snapshot of database TEST on wednesday at 9AM is 12355.

num_of_sqls: Give the number of how many top SQL's you want to collect using the query for example if you want to collect top 50 SQL's replace num_of_sqls with 50



Thursday, July 14, 2011

Undo Latch Contention

Here is the SQL to find sessions causing UNDO Latch Contention:

select
   swh.seq#,
   sess.sid,
   sess.username username,
   swh.event     event,
   swh.p1,
   swh.p2
from
   v$session               sess,
   v$session_wait_history  swh
where
   sess.sid = 798
and
   sess.sid = swh.sid
order by
   swh.seq#;


Sample Output:

     SEQ#     SID      USERNAME        EVENT                                                  P1                      P2
---------- -------    --------------- ------------------------------------   --------------       ----------
         1        798     ORCL               latch free                                              5.0440E+17        127
         2        798     ORCL               latch free                                              5.0440E+17        127
         3        798     ORCL               latch free                                              5.0440E+17        127
         4        798     ORCL               latch free                                              5.0440E+17        127
         5        798     ORCL               latch: cache buffers chains           5.0440E+17        122
   


5 rows selected.

To find list of objects accessed by a database session

Here is a simple query that shows all the objects accessed by a database:

SELECT sid,
       owner,
       TYPE,
       object
  FROM v$access
 WHERE sid = 'session_id';

Ex:
SELECT sid,
       owner,
       TYPE,
       object
  FROM v$access
 WHERE sid = '769';

Monday, August 30, 2010

Temporary Tablespace Space Monitoring

Here are some quick SQL's to monitor the usage of TEMP Tablespace:

Space Usage of TEMP Tablespace:

SELECT A.tablespace_name tablespace, D.mb_total,
SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_used,
D.mb_total - SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_free
FROM v$sort_segment A,
(
SELECT B.name, C.block_size, SUM (C.bytes) / 1024 / 1024 mb_total
FROM v$tablespace B, v$tempfile C
WHERE B.ts#= C.ts#
GROUP BY B.name, C.block_size
) D
WHERE A.tablespace_name = D.name
GROUP by A.tablespace_name, D.mb_total;

Temp Space Usage by Session:

SELECT S.sid || ',' || S.serial# sid_serial, S.username, S.osuser, P.spid, S.module,
S.program, SUM (T.blocks) * TBS.block_size / 1024 / 1024 mb_used, T.tablespace,
COUNT(*) sort_ops
FROM v$sort_usage T, v$session S, dba_tablespaces TBS, v$process P
WHERE T.session_addr = S.saddr
AND S.paddr = P.addr
AND T.tablespace = TBS.tablespace_name
GROUP BY S.sid, S.serial#, S.username, S.osuser, P.spid, S.module,
S.program, TBS.block_size, T.tablespace
ORDER BY sid_serial;
 
Temp Space Usage by Statement:
 
SELECT S.sid || ',' || S.serial# sid_serial, S.username,
T.blocks * TBS.block_size / 1024 / 1024 mb_used, T.tablespace,
T.sqladdr address, Q.hash_value, Q.sql_text
FROM v$sort_usage T, v$session S, v$sqlarea Q, dba_tablespaces TBS
WHERE T.session_addr = S.saddr
AND T.sqladdr = Q.address (+)
AND T.tablespace = TBS.tablespace_name
ORDER BY S.sid;

Thursday, August 26, 2010

Waits Related to Initialization Parameters

Wait Problem: Potential Fix
Free buffer: Increase the DB_CACHE_SIZE; shorten the checkpoint; tune the code
Buffer busy:  Segment Header — Add freelists or freelist groups or use ASSM
Buffer busy:  Data Block — Separate hot data; use reverse key indexes; small block sizes
Buffer busy:  Data Block — Increase initrans and/or maxtrans
Buffer busy:  Undo Header —Use automatic undo management
Buffer busy:  Undo Block — Commit more; use automatic undo management
Latch free:  Investigate the detail (listing in next table of this chapter for fixes)
Log buffer space: Increase the log buffer; use faster disks for the redo logs
Scattered read: Indicates many full table scans — tune the code; cache small tables
Sequential read: Indicates many index reads — tune the code (especially joins)
Write complete waits: Adds database writers; checkpoint more often; buffer cache too small

Latch Problem: Potential Fix

Library cache:  Use bind variables; adjust the shared_pool_size
Shared pool:  Use bind variables; adjust the shared_pool_size
Row cache objects: Increase the shared pool. This is not a common problem.
Cache buffers chain:  If you get this latch wait, it means you need to reduce logical I/O rates by tuning and minimizing the I/O requirements of the SQL involved. High I/O rates could be a sign of a hot block (meaning
a block highly accessed). Cache buffer lru chain latch contention can be resolved by increasing the size of the buffer cache and thereby reducing the rate at which new blocks are introduced into the buffer cache. You should adjust DB_BLOCK_BUFFERS, and possible DB_BLOCK_SIZE. Multiple buffer pools can help
reduce contention on this latch. You can create additional cache buffer lru chain latches by adjusting the configuration parameter DB_BLOCK_LRU_LATCHES. You may be able to reduce the load on the cache buffer chain latches by increasing the configuration parameter. _DB_BLOCK_HASH_BUCKETS may need to be increased or set to a prime number (in pre-9i versions).

Library Cache SQL

The following query uses the V$LIBRARYCACHE view to examine the reload ratio in the library cache:


select Sum(Pins) "Hits",
Sum(Reloads) "Misses",
((Sum(Reloads) / Sum(Pins)) * 100)"Reload %"
from V$LibraryCache;

Data Dictionary Cache Hit Ratio SQL

SQL:

select ((1 - (Sum(GetMisses) / (Sum(Gets) + Sum(GetMisses)))) * 100) "Hit Rate"
from V$RowCache
where Gets + GetMisses <> 0;

Session or System Modifiable Parameter SQL

There are two key fields in the V$PARAMETER view:
■ ISSES_MODIFIABLE Indicates if a user with the ALTER SESSION privilege can modify
this initialization parameter for their session.

■ ISSYS_MODIFIABLE Indicates if someone with ALTER SYSTEM privilege can modify
this particular parameter.


This query displays the initialization parameters that can be modified with an ALTER SYSTEM or ALTER SESSION command (partial result displayed):

select name, value, isdefault, isses_modifiable, issys_modifiable
from v$parameter
where issys_modifiable <> 'FALSE'
or isses_modifiable <> 'FALSE'
order by name;




Data Cache Hit Ratio SQL

Query to view the data cache hit ratio:

column phys format 999,999,999 heading 'Physical Reads'
column gets format 999,999,999 heading ' DB Block Gets'
column con_gets format 999,999,999 heading 'Consistent Gets'
column hitratio format 999.99 heading ' Hit Ratio '
select sum(decode(name,'physical reads',value,0)) phys,
sum(decode(name,'db block gets',value,0)) gets,
sum(decode(name,'consistent gets', value,0)) con_gets,
(1 - (sum(decode(name,'physical reads',value,0)) /
(sum(decode(name,'db block gets',value,0)) +
sum(decode(name,'consistent gets',value,0))))) * 100 hitratio
from v$sysstat;

Tuesday, August 24, 2010

Cardinality in Oracle Table Joins

Cardinatly: This is the number of rows that Oracle expects to process or expects to be the number rows that will be returned after joining the tables from the join condition.

More to follow...............

Check RMAN Backup Status

SQL to report on all backups i.e., Full, Incremental and Archive log backups:

col STATUS format a9
col hrs format 999.99
select SESSION_KEY, INPUT_TYPE, STATUS,
to_char(START_TIME,'mm/dd/yy hh24:mi') start_time,
to_char(END_TIME,'mm/dd/yy hh24:mi') end_time,
elapsed_seconds/3600 hrs
from V$RMAN_BACKUP_JOB_DETAILS
order by session_key;

SQL to report on all Full and Incremental backup but not Archive log backups:

col STATUS format a9
col hrs format 999.99
select SESSION_KEY, INPUT_TYPE, STATUS,
to_char(START_TIME,'mm/dd/yy hh24:mi') start_time,
to_char(END_TIME,'mm/dd/yy hh24:mi') end_time,
elapsed_seconds/3600 hrs
from V$RMAN_BACKUP_JOB_DETAILS
where input_type='DB INCR'
order by session_key;

To check progress of RMAN Backup:

select SID, START_TIME,TOTALWORK, sofar, (sofar/totalwork) * 100 done,
sysdate + TIME_REMAINING/3600/24 end_at
from v$session_longops
where totalwork > sofar
AND opname NOT LIKE '%aggregate%'
AND opname like 'RMAN%';

Monday, April 12, 2010

Resize/Add/Move/Rename/Drop datafile and temporary datafile in Oracle

Resize a datafile and tempfile:

SQL> alter database datafile '/u10/oradata/TEST/test.tst_tbspace.data.01.dbf' resize 50M;

SQL> alter database tempfile '/u09/oradata/TEST/test.tmp_tbspace.data.01.dbf' resize 50M;

Add a datafile:

SQL> alter tablespace tst_tbspace1 add datafile '/u10/oradata/TEST/test.tst_tbspace.data.02.dbf' size 2000M;

SQL> alter tablespace tmp_tbspace add tempfile '/u09/oradata/TEST/test.tmp_tbspace.data.02.dbf' size 2000M;


Steps to move and/or rename datafile in oracle:

1. Shutdown the database and exit out of the SQL prompt - Database level step

Ex: SQL> shutdown

2. At the unix prompt copy or move the datafile from current location to new location using the OS copy (cp) command - OS level step

Ex: $ mv /u10/oradata/TEST/test.tbspace.data.01.dbf /u01/oradata/TEST/test.tst_tbspace.data.01.dbf

you change the location and also rename the file at a time if you need to.

Ex: $ mv /u10/oradata/TEST/test.tst_tbspace.data.01.dbf /u01/oradata/TEST/test.tst_tbspace.datafile.02.dbf

3. Open a SQL session and startup mount the database - Database level step

Ex: SQL> startup mount

4. Rename the datafile using oracle rename command - Database level step

Ex: SQL> alter database rename file '/u10/oradata/TEST/test.tst_tbspace.data.01.dbf'
                 to '/u01/oradata/TEST/test.tbspace.data.01.dbf';

5. Open the database - Database level step

Ex: SQL> alter database open;

                       (or)

      SQL> shutdown

      SQL> startup

Drop datafile:

SQL>  alter database datafile '/u10/oradata/TEST/test.tst_tbspace.data.01.dbf' offline drop;

(or)

SQL> alter tablespace tst_tbspace drop datafile '/u10/oradata/TEST/test.tst_tbspace.data.01.dbf';

Rename/Copy a Table

A table in oracle can be renamed using the following syntax:

alter table table_name rename to new_table_name;

Ex: SQL> alter table dept rename to hist_dept;

Renaming a table doesn't update the oracle objects such as HTML DB, PL/SQL, Views some of which might be invalid based on their dependancy on the renamed object.

A copy of the original table can be created using the following syntax:

create table new_table_name as select * from table_name;

Ex: SQL> create hist_dept as select * from dept;

we need not necessarily need to include all the columns from the original table we can create a copy based on our choice of columns that we want to be included in the new table. The new table can be created either from one single table or multiple tables. The advantage of using CREATE TABLE....AS SELECT..(CTAS) it will create the new table with datatypes similar to old table(s).

A copy of the original table created including only the columns of our choice from a single table:

create table new_table_name as select column1, column2 from table_name;

Ex: SQL> create hist_dept as select dept_id, dept_name from dept;


A copy of the original table created including only the columns of our choice from a two tables:

create table new_table_name as select t1.column1, t2.column1, t2.column2 from table_name1 t1, table_name2 t2 where t1.column1 = t2.column1;

Ex: SQL> create hist_dept as select d.dept_id, e.emp_id, e.emp_anem from dept d, employee e where
                 d.dept_id = e.dept_id;

Thursday, April 08, 2010

Oracle Background Processes

Oracle Background Porcesses: To maximize performance and accommodate many users, a multiprocess Oracle Database system uses background processes. Background processes consolidate functions that would otherwise be handled by multiple database programs running for each user process. Background processes asynchronously perform I/O and monitor other Oracle Database processes to provide increased parallelism for better performance and reliability.

Basic Oracle Background Processes:
  • Database writer (DBWn): The database writer writes modified blocks from the database buffer cache to the datafiles. Oracle Database allows a maximum of 20 database writer processes (DBW0-DBW9 and DBWa-DBWj). The DB_WRITER_PROCESSES initialization parameter specifies the number of DBWn processes. The database selects an appropriate default setting for this initialization parameter or adjusts a user-specified setting based on the number of CPUs and the number of processor groups.

  • Log writer (LGWR): The log writer process writes redo log entries to disk. Redo log entries are generated in the redo log buffer of the system global area (SGA). LGWR writes the redo log entries sequentially into a redo log file. If the database has a multiplexed redo log, then LGWR writes the redo log entries to a group of redo log files.

  • Checkpoint (CKPT): At specific times, all modified database buffers in the system global area are written to the datafiles by DBWn. This event is called a checkpoint. The checkpoint process is responsible for signalling DBWn at checkpoints and updating all the datafiles and control files of the database to indicate the most recent checkpoint.

  • System monitor (SMON): The system monitor performs recovery when a failed instance starts up again. In a Real Application Clusters database, the SMON process of one instance can perform instance recovery for other instances that have failed. SMON also cleans up temporary segments that are no longer in use and recovers dead transactions skipped during system failure and instance recovery because of file-read or offline errors. These transactions are eventually recovered by SMON when the tablespace or file is brought back online.

  • Process monitor (PMON): The process monitor performs process recovery when a user process fails. PMON is responsible for cleaning up the cache and freeing resources that the process was using. PMON also checks on the dispatcher processes (described later in this table) and server processes and restarts them if they have failed.

  • Archiver (ARCn): One or more archiver processes copy the redo log files to archival storage when they are full or a log switch occurs.

  • Recoverer (RECO): The recoverer process is used to resolve distributed transactions that are pending because of a network or system failure in a distributed database. At timed intervals, the local RECO attempts to connect to remote databases and automatically complete the commit or rollback of the local portion of any pending distributed transactions.

  • Dispatcher (Dnnn): Dispatchers are optional background processes, present only when the shared server configuration is used.

  • Global Cache Service (LMS): In a Real Application Clusters environment, this process manages resources and provides inter-instance resource control.
Source: Oracle Documentation

Oracle Dedicated and Shared Server Processes

Oracle creates server processes whenever a user tries to connect to a database for handling all user requestss. Below are the two ways a server process can be:
  • A Dedicated Server Process, which serves only one user or one user connection
  • A Shared Server Process, which server multiple users or multiple user connections
Dedicated Server Processes:

Oracle databases are by default configured for dedicated server process and if you need to enable Shared server process you need to configure it manually by setting one or more initialization parameters. However a Dedicated server process is always required  for:
  • To submit a batch job (for example, when a job can allow little or no idle time for the server process)
  • To use Recovery Manager (RMAN) to back up, restore, or recover a database
To request a dedicated server connection when Oracle Database is configured for shared server, users must connect using a net service name that is configured to use a dedicated server. Specifically, the net service name value should include the SERVER=DEDICATED clause in the connect descriptor.




Figure 1: Oracle Database Dedicated Server Processes

Shared Server Process:



Figure 2: Oracle Database Shared Server Processes

In Shared server configuration a client user process connect a dispatcher and the dispatcher then communicates with the oracle database for client request processing once the processing is done oracle then sends back the output or solution back to the dispatcher which in turn communicates it to the client user process. One dispatcher can serve multiple client user processes by connection pooling which can be enabled for shared server process. Further, shared server can be configured for session multiplexing, which combines multiple sessions for transmission over a single network connection in order to conserve the operating system's resources.

Initialization Parameters for Shared Server:

The following initialization parameters control shared server operation:
  • SHARED_SERVERS: Specifies the initial number of shared servers to start and the minimum number of shared servers to keep. This is the only required parameter for using shared servers.
  • MAX_SHARED_SERVERS: Specifies the maximum number of shared servers that can run simultaneously.
  • SHARED_SERVER_SESSIONS: Specifies the total number of shared server user sessions that can run simultaneously. Setting this parameter enables you to reserve user sessions for dedicated servers.
  • DISPATCHERS: Configures dispatcher processes in the shared server architecture.
  • MAX_DISPATCHERS: Specifies the maximum number of dispatcher processes that can run simultaneously. This parameter can be ignored for now. It will only be useful in a future release when the number of dispatchers is auto-tuned according to the number of concurrent connections.
  • CIRCUITS: Specifies the total number of virtual circuits that are available for inbound and outbound network sessions.
Enabling Shared Server:

Shared server is enabled by setting the SHARED_SERVERS initialization parameter to a value greater than 0. The other shared server initialization parameters need not be set. Because shared server requires at least one dispatcher in order to work, a dispatcher is brought up even if no dispatcher has been configured.

Determining a Value for SHARED_SERVERS and others:

The SHARED_SERVERS initialization parameter specifies the minimum number of shared servers that you want created when the instance is started. After instance startup, Oracle Database can dynamically adjust the number of shared servers based on how busy existing shared servers are and the length of the request queue.
You can limit the number of shared servers that can be created by setting MAX_SHARED_SERVERS parameter specifies the maximum number of shared servers that can be automatically created by PMON. After you set the SHARED_SERVERS parameter oracle decides the number of shares servers that needs to be created based on how busy the system is.

The SHARED_SERVER_SESSIONS initialization parameter specifies the maximum number of concurrent shared server user sessions. Setting this parameter, which is a dynamic parameter, lets you reserve database sessions for dedicated servers.
Configuring Dispatchers:

Ex: This is a typical example of setting the DISPATCHERS initialization parameter.

DISPATCHERS="(PROTOCOL=TCP)(DISPATCHERS=2)"

You can use multiple different protocols for different dispatchers within the same initialization parameter.

Ex: DISPATCHERS='(PROT=tcp)(DISP=5)', '(PROT-tcps)(DISP=3)'

Monitor the following views to determine the load on the dispatcher processes:

  • V$QUEUE
  • V$DISPATCHER
  • V$DISPATCHER_RATE
Shutting down specific Dispatches process:
To identify the name of the specific dispatcher process to shut down, use the V$DISPATCHER dynamic performance view.

SQL> SELECT NAME, NETWORK FROM V$DISPATCHER;

Each dispatcher is uniquely identified by a name of the form Dnnn.To shut down dispatcher D002, issue the following statement:

SQL>ALTER SYSTEM SHUTDOWN IMMEDIATE 'D002';

Monitoring Shared Server:
The following views are useful for obtaining information about your shared server configuration and for monitoring performance.

  • V$DISPATCHER: Provides information on the dispatcher processes, including name, network address, status, various usage statistics, and index number.
  • V$DISPATCHER_CONFIG: Provides configuration information about the dispatchers.
  • V$DISPATCHER_RATE: Provides rate statistics for the dispatcher processes.
  • V$QUEUE: Contains information on the shared server message queues.
  • V$SHARED_SERVER: Contains information on the shared servers.
  • V$CIRCUIT: Contains information about virtual circuits, which are user connections to the database through dispatchers and servers.
  • V$SHARED_SERVER_MONITOR: Contains information for tuning shared server.
  • V$SGA: Contains size information about various system global area (SGA) groups. May be useful when tuning shared server.
  • V$SGASTAT: Contains detailed statistical information about the SGA, useful for tuning.
  • V$SHARED_POOL_RESERVED: Lists statistics to help tune the reserved pool and space within the shared pool.
Source: Oracle Documentation

All about startup migrate and startup upgrade

startup migrate:

=> Used to upgrade a database till 9i.
See the step 11 from the 9.2 manual upgrade guide :
http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96530/upgrade.htm#1009472


=> Used to downgrade a database till 9i.
See the step 5 from the 9.2 downgrade guide :
http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96530/downgrad.htm#248958


=> Used to downgrade a database since 10g.
See the step 18 from the 10.2 downgrade guide :
http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14238/downgrade.htm#sthref415


 startup upgrade
=> Used to upgrade a database since 10g.
See the step 7 from the 10.2 manual upgrade guide :
http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14238/upgrade.htm#CACGGHJC

Tuesday, April 06, 2010

Recompiling Invalid Schema Objects

Objects in a database tend to get invalid due to operation such as patches, DDL changes and upgrades etc. The invalid objects are to compiled to ensure proper health of the database and user's access to them. I will provide here the ways you can compile objects in Oracle.

Identifying Invalid Objects:

col format OBJECT_NAME a40

SQL> SELECT OBJECT_NAME,
                            OBJECT_TYPE,
                            OWNER,
                            STATUS
           FROM DBA_OBJECTS
           WHERE STATUS='INVALID'
           ORDER BY OBJECT_NAME, OBJECT_TYPE, OWNER;

to get invalid objects list for a particular schema below is the SQL:

col format OBJECT_NAME a40

SQL> SELECT OBJECT_NAME,
                          OBJECT_TYPE,
                          OWNER,
                          STATUS
           FROM DBA_OBJECTS
          WHERE OWNER='DEPT' AND STATUS='INVALID'
          ORDER BY OBJECT_NAME, OBJECT_TYPE, OWNER;

DBMS_UTILITY.COMPILE_SCHEMA:
DBMS_UTILITY package proides COMPILE_SCHEMA procedure to compile all the objects in a schema:

SQL> EXECUTE DBMS_UTILITY.COMPILE_SCHEMA ('SCHEMA_NAME');

UTLRP and UTLPRP:
UTLRP and UTLPRP are the oracle provided scripts to compile all invalid objects in oracle database.

Ex: SQL> ?/rdbms/admin/utlrp

Manual Approach:
Invalid Objects can be compiled individually after you have the list of invalid objects in your oracle database. Below are some of the examples:

SQL> ALTER PACKAGE package_name COMPILE;

SQL> ALTER PACKAGE package_name COMPILE BODY;

SQL> ALTER PROCEDURE procedure_name COMPILE;

SQL> ALTER FUNCTION function_name COMPILE;

SQL> ALTER TRIGGER trigger_name COMPILE;

SQL> ALTER VIEW view_name COMPILE;


An alternative approach is to use the DBMS_DDL package to perform the recompilations:

SQL> EXEC DBMS_DDL.alter_compile('PACKAGE', 'SCHEMA_NAME', 'PACKAGE_NAME');

SQL> EXEC DBMS_DDL.alter_compile('PACKAGE BODY', 'SCHEMA_NAME', 'PACKAGE_NAME');

SQL> EXEC DBMS_DDL.alter_compile('PROCEDURE', 'SCHEMA_NAME', 'PROCEDURE_NAME');

SQL> EXEC DBMS_DDL.alter_compile('FUNCTION', 'SCHEMA_NAME', 'FUNCTION_NAME');

SQL> EXEC DBMS_DDL.alter_compile('TRIGGER', 'SCHEMA_NAME', 'TRIGGER_NAME');
 
In addition to the above approaches you can write your own script to get the invalid objects and recompile them using the manual approach to recompile them all included in the script.