Posts tagged oracle

Finding free/used temporary table space in Oracle

2


If you’re a freak who work around with Oracle as backend, you would face the sitution where the oracle temporary space would be exhausted.

The usage temporary tablespace can’t be found out exactly using DBA_FREE_SPACE. To find out the true value of temporary table space we may need to use V$TEMP_SPACE_HEADER data dictonary.

SELECT   tablespace_name, SUM (bytes_used), SUM (bytes_free)
    FROM v$temp_space_header
GROUP BY tablespace_name;

If you’re looking out to find out the usage of other table space we need to use the following script.

CLEAR
SET HEAD ON
SET VERIFY OFF
SPOOL file
COL tspace form a25 Heading "Tablespace"
COL tot_ts_size form 99999999999999 Heading "Size (Mb)"
COL free_ts_size form 99999999999999 Heading "Free (Mb)"
COL ts_pct form 9999 Heading "% Free"
COL ts_pct1 form 9999 Heading "% Used"
BREAK on report
COMPUTE sum of free_ts_size on report
COMPUTE sum of tot_ts_size on report
SELECT                                                            /* + RULE */
         df.tablespace_name tspace, df.BYTES / (1024 * 1024) tot_ts_size,
         SUM (fs.BYTES) / (1024 * 1024) free_ts_size,
         NVL (ROUND (SUM (fs.BYTES) * 100 / df.BYTES), 1) ts_pct,
         ROUND ((df.BYTES - SUM (fs.BYTES)) * 100 / df.BYTES) ts_pct1
    FROM dba_free_space fs,
         (SELECT   tablespace_name, SUM (BYTES) BYTES
              FROM dba_data_files
          GROUP BY tablespace_name) df
   WHERE fs.tablespace_name(+) = df.tablespace_name
GROUP BY df.tablespace_name, df.BYTES
UNION ALL
SELECT                                                            /* + RULE */
         df.tablespace_name tspace, fs.BYTES / (1024 * 1024) tot_ts_size,
         SUM (df.bytes_free) / (1024 * 1024) free_ts_size,
         NVL (ROUND ((SUM (fs.BYTES) - df.bytes_used) * 100 / fs.BYTES),
              1
             ) ts_pct,
         ROUND ((SUM (fs.BYTES) - df.bytes_free) * 100 / fs.BYTES) ts_pct1
    FROM dba_temp_files fs,
         (SELECT   tablespace_name, bytes_free, bytes_used
              FROM v$temp_space_header
          GROUP BY tablespace_name, bytes_free, bytes_used) df
   WHERE fs.tablespace_name(+) = df.tablespace_name
GROUP BY df.tablespace_name, fs.BYTES, df.bytes_free, df.bytes_used
ORDER BY 4 DESC
/
SPOOL off

To find the size of table different technique has to be used.

Finding locked objects in Oracle

3


If you’re wondering why particular query or procedure is talking a long such a long time to run; then make sure you check out whether the object you’re accessing is locked or not. There are quite a few dba views available to make our task less complicated. You can use the below query which will return you the list of locked objects.

SELECT c.owner, c.object_name, c.object_type, b.SID, b.serial#, b.status,
       b.osuser, b.machine
  FROM v$locked_object a, v$session b, dba_objects c
 WHERE b.SID = a.session_id AND a.object_id = c.object_id;

You can now decide whether to kill the job/ process or someother roundabout to remove the lock obtained on the particular object.

Oracle server uptime

0


The following query works well with Oracle 9i. i’ve no clue whether this works with others too or not.

SELECT TO_CHAR (startup_time, 'DD-MON-YYYY HH24:MI:SS') "DB Startup Time"
  FROM SYS.v_$instance;

even there is possiblity to find the startup time by quering logon_time from sys.v_$session view.

Oracle Hidden Parameters

0


Oracle initialization or INIT.ORA parameters with an underscore in front are hidden or unsupported parameters. One can get a list of all hidden parameters by executing this query:

SELECT *
  FROM SYS.x$ksppi
 WHERE SUBSTR (ksppinm, 1, 1) = '_';

The following query displays parameter names with their current value:

SELECT   a.ksppinm "Parameter", b.ksppstvl "Session Value",
         c.ksppstvl "Instance Value"
    FROM x$ksppi a, x$ksppcv b, x$ksppsv c
   WHERE a.indx = b.indx AND a.indx = c.indx AND SUBSTR (ksppinm, 1, 1) = '_'
ORDER BY a.ksppinm;

Remember: Thou shall not play with undocumented parameters! Using undocumented parameters without the consent of Oracle Support will make your database “un-supported”. You will be on your own if the parameters you’ve set cause problems or data corruption.

Rename Oracle database username

0

No, this is not available till now in Oracle and has been noted down as a enhancement request.
Still here is a workaround way of doing that:

  1. Do a user-level export of user A
  2. create new user B
  3. import system/manager from user=A to user=B
  4. drop user A
Go to Top