Pavan DBA's Blog

The DBA Knowledge Store

Archive for the ‘Admin’ Category

All about DUAL table

Posted by Pavan DBA on August 19, 2010

Friends, many of us know about DUAL and its usage. Lets learn few things about it…

1) can we drop a dual table?

Ans: Yes. but it will have serious impact on the database functionality. so you should never do that

2) Can we create DUAL table if dropped?

Ans: Yes. use the following steps for the same…

SQL> DROP TABLE SYS.DUAL ;
 
Table dropped.
 
SQL> CREATE TABLE SYS.DUAL
  2  (
  3    DUMMY  VARCHAR2(1 BYTE)
  4  )
  5  TABLESPACE SYSTEM;
 
Table created.
 
SQL> CREATE PUBLIC SYNONYM DUAL FOR SYS.DUAL;
 
Synonym created.
 
SQL> GRANT SELECT ON SYS.DUAL TO PUBLIC WITH GRANT OPTION;
 
Grant succeeded.
 
SQL> INSERT INTO dual VALUES (‘X’);
 
1 row created.
 
SQL> SELECT * FROM dual;
 
D                                                                              
-                                                                              
X        

3) Can i create my own DUAL table which is having same functionality?

Ans: Yes. use below script which will create MYDUAL as another DUAL table.

CREATE OR REPLACE PROCEDURE replace_mydual (
 table_name_in IN VARCHAR2
)
IS
BEGIN
 BEGIN
    EXECUTE IMMEDIATE ‘DROP TABLE ‘ || table_name_in;
 EXCEPTION
    WHEN OTHERS THEN NULL;
 END;

 EXECUTE IMMEDIATE ‘CREATE TABLE ‘
                   || table_name_in
                   || ‘ (dummy VARCHAR2(1))’;

 EXECUTE IMMEDIATE
    ‘CREATE OR REPLACE TRIGGER mydual_’ || table_name_in ||
    ‘  BEFORE INSERT
       ON ‘ || table_name_in || ‘
    DECLARE
       PRAGMA AUTONOMOUS_TRANSACTION;
       l_count PLS_INTEGER;
    BEGIN
       SELECT COUNT (*)
       INTO   l_count
       FROM   ‘ || table_name_in || ‘;

       IF l_count = 1
       THEN
          raise_application_error
          ( -20000
          , ”The ‘ || table_name_in || ‘ table can only have one row.” );
       END IF;
    END;’;

 EXECUTE IMMEDIATE ‘BEGIN INSERT INTO ‘
                   || table_name_in
                   || ‘ VALUES (”X”); COMMIT; END;’;

 EXECUTE IMMEDIATE ‘GRANT SELECT ON ‘
                   || table_name_in
                   || ‘ TO PUBLIC’;

 EXECUTE IMMEDIATE ‘CREATE PUBLIC SYNONYM ‘
                   || table_name_in
                   || ‘ FOR ‘
                   || table_name_in;

 EXECUTE IMMEDIATE
    ‘CREATE OR REPLACE FUNCTION next_pky (seq_in IN VARCHAR2)
        RETURN PLS_INTEGER AUTHID CURRENT_USER
     IS
        retval PLS_INTEGER;
     BEGIN
        EXECUTE IMMEDIATE ”SELECT ” || seq_in
                      || ”.NEXTVAL FROM ‘ || table_name_in ||
                      ‘|| ”INTO retval;
        RETURN retval;
     END next_pky;’;

END replace_mydual;

TOM KYTE explained about this in one of his articles and as always its best…

http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1562813956388

some more interesting part, why DUAL?
http://radiofreetooting.blogspot.com/2006/12/why-dual.html

All above ask your friend GOOGLE about this, lot of results will hit your door

HAPPY LEARNING…

Posted in Admin | Tagged: , , | 1 Comment »

how to resolve ORA-27102 error?

Posted by Pavan DBA on August 12, 2010

Good day friends…

Its been long time that i posted a technical article and reason is am busy with my new project KT.

yesterday when i am doing RMAN cloning to a different server to get a schema which is dropped, i got a peculiar error. i will post the steps to follow on how to retrieve a single table or schema using rman backup later.

when i about to start my new instance on a server (which already contains 3 databases), i got below error

SQL> startup
ORA-27102: out of memory
SVR4 Error: 22: Invalid argument

This is first time i got this error and wondered why it is…and then got a point that “may be RAM size is not sufficient to allocate memory to new instance”

i checked the cause as below

$ oerr ORA 27102
27102, 00000, “out of memory”
// *Cause: Out of memory
// *Action: Consult the trace file for details

now with this its clear that we don’t have a straight answer. then i checked alert log file and found following line

Starting ORACLE instance (normal)
Wed Aug 11 10:37:26 2010
WARNING: EINVAL creating segment of size 0×0000000080002000
fix shm parameters in /etc/system or equivalent

when i am checking at OS level, background processes are being started but OS is unable to allocate memory to SGA or PGA
After analysis, i found that either SHMMAX or SHMALL are not sufficiently mentioned at OS level kernel

In such cases, we need to do following

1. $ prtconf | grep Mem
Memory size: 8192 Megabytes

2. $ id -p
uid=500(oracle) gid=201(dba) projid=200(MCSDBT)

3. $ prctl -n project.max-shm-memory -i project 200
project: 200: MCSDBT
NAME    PRIVILEGE       VALUE    FLAG   ACTION                       RECIPIENT
project.max-shm-memory
        privileged      2.0GB      -   deny                                 -
        system          16.0EB    max   deny                                 -

here you can see the value privileged is only 2 GB. so we need to increase that using the below command

4. $ prctl -n project.max-shm-memory -r -v 10G -i project 200
5. $ prctl -n project.max-shm-memory -i project 200
project: 200: MCSDBT
NAME    PRIVILEGE       VALUE    FLAG   ACTION                       RECIPIENT
project.max-shm-memory
        privileged      10.0GB      -   deny                                 -
        system          16.0EB    max   deny                                 -

Now it was changed to 10G and try out, you will be able to start your instance.

Note: sometimes you may not have root privilege to execute this command, in such case you can take sys admin help.

The value which changed to 10G is temporary for that moment i.e it will be again 2 GB once you reboot server

Note : The above procedure will help in Oracle 10.2.0.4 running on Solaris 10. Commands may differ for other versions and OS flavours

Posted in Admin | Tagged: , , | Leave a Comment »

New background process in 11g

Posted by Pavan DBA on July 27, 2010

This article will enable you to learn about some of new background processes in 11g. As per Oracle documentation there are 56 new background processes added in 11g release 1

Lets have a look at some important one’s….

MMAN - this process is responsible for ASMM in 10g and AMM in 11g  which manages memory allocation to SGA and PGA

RCBG - this background process is responsible for processing data into server result cache

DIAG - In 11g we have a single location for all the trace files, alert log and other diagnostic files. DIAG is the process which performs  diagnostic dumps and executes oradebug commands

DIA0 – responsible for hang detection and deadlock resoultion

DBRM – Database resource manager is responsible for setting plans to users and all other database resource management activities

EMNC – Event Monitor Coordinator will coordinate with event management and notification activity

FBDA – Flashback Data Archiver process is responsible for all flashback related actions in 11g database

GEN0 - General task execution process which performs required tasks

SMCo – Space management coordinator executes various space management tasks like space reclaiming, allocation etc. It uses slave processes Wnnn whenever required

VKTM – Virtual keeper of time is  responsible for keeping track of the wall-clock time and used as a reference-time counter

Posted in Admin | Tagged: , , | Leave a Comment »

Automatic Memory Management in 11g

Posted by Pavan DBA on July 21, 2010

All of us by this time would have known about 11g new feature AMM. This allows to manage both SGA and PGA automatically by setting MEMORY_TARGET and MEMORY_MAX_TARGET parameters.

Now i got a doubt on how oracle will do this? i.e releasing shared memory and allocating it to private memory…

After so many searches in google, finally i found following

1. Oracle in 11g is using /dev/shm mount point for shared memory implementation

2. this is called Linux POSIX oriented SHM implementaion

So now all memory segments are treated as files on that mount point. If any one requires extra segment, Oracle will simply allocate the file which is free.

If you don’t have /dev/shm mounted (default it will be mounted), then you cannot use MEMORY_TARGET parameter and this will also happen if you have less size for tmpfs in Linux.

Plz refer to below link where Tanel explained in wonderful way about this.
http://blog.tanelpoder.com/2007/08/21/oracle-11g-internals-part-1-automatic-memory-management/

Posted in Admin | Tagged: , , , | 1 Comment »

How RESULT CACHE works?

Posted by Pavan DBA on July 15, 2010

Many of you may have known about new parameter RESULT_CACHE in 11g. It supports a new component of SGA called SERVER RESULT CACHE. Lets go and see its functionality

Normally sql statements will follow parse, execute and fetch phases to give required data to users. In that process, Oracle will copy blocks into buffer cache…and filtering of data out of that block will happen.

Oracle thought why can’t i store directly rows itself instead of blocks? and thats how it came up with a new SGA component SERVER RESULT CACHE.

RESULT CACHE resides in shared pool. when using this component in 11g, any sql statement will

1) first check for parsed statement in library cache and if got an already parsed statement with execution plan, it will move to result cache.

2) In result cache, it will search for data which is having the same execution plan. This will happen using execution plan id. From this we can understand that result cache also stores execution plan id along with data(rows of the required table)

3) Then the data is given to user directly even without execution and fetch (remember even it didn’t performed parsing). so you will get data in a flash…

Oracle suggests to use RESULT CACHE for OLTP environments or for statements which are frequently used (earlier versions, we used KEEP cache for the same…but in the form of blocks again). It also supports PL/SQL functions and will give more advantage when executing functions repeatedly.

RESULT_CACHE_MAX_SIZE parameter is used to size the result cache. Its size depends on…

1) when mentioned with MEMORY_TARGET parameter, it will take 0.25% of total SGA size

2) when mentioned only SGA_TARGET (without MEMORY_TARGET), it will take 0.5% of SGA size

3) when not using AMM or ASMM, it will take 1% memory from shared pool

Hope this small post gave you an idea on 11g new feature…

Posted in Admin | Tagged: , , , , | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 1,477 other followers