Day-to-day Problems & Solutions for DBA’s Problems & Solutions # Records has to be inserted in a table which has foreign

keys and constraints. It’s like update the table and it may have duplicate values also. Solution # Findout all the foreign key’s and table constraints. (dba_constraints, dba_cons_columns) # Disable all constraints (ALTER TABLE table_name DISABLE CONSTRAINT constraint name;) # If unique constraint is present, Truncate the Table.* (Before truncating consult with developers, and team lead and read release notes if any) (TRUNCATE TABLE schema.tablename;) # Load the records into the table.(insertion) # Commit; # Enable all disabled constraints. (ALTER TABLE table_name ENABLE CONSTRAINT constraint_name;) * If unique constraints are prestnt ORA-02298 error will come,…..parent keys are not enabled, Findout out primary key difference in foreign table and delete the(those)records… (DELETE FROM foreign_table WHERE column_name = 799;) and proceed

# Allocate space for a user fernando who’s id already exists and grant write permissions in devalert73 database.

PCTINCREASE is set to 1 – SMON releases the freed extents # Create a new user with create session privilage Solustion: . What is a deadlock and how does oracle handle it? A deadlock is a condition where two or more users are waiting for data locked by each other. Oracle automatically detects a deadlock and resolves them by rolling .Solution: ALTER USER fernando QUTOA 5M ON users. GRANT develop TO fernando. ( develop – write permission role) # Next extent allocation failure for a table. Solution ALTER TABLE owner. CREATE USER roysys IDENTIFIED EXTERNALLY DEFAULT TABLESPACE users TERMPORARY TABLESPCAE temp. GRANT create session TO roysys. .table_name STORAGE (NEXT 500K PCTINCREASE 1).

DBWR crashed and then all other processes died.3. thus precluding a deadlock. This will kill the sessions in the database (status in v$session now becomes SNIPED) and they will eventually disconnect. For one of my databases. This shadow process is still counted towards the parameters of init.4 on digital unix 4. I Worked with oracle suppport on this. Another way of forcing disconnect (if your users come in via SQL*Net) is to put the file sqlnet. This process is killed and entry from v$session is released only when user again tries to do something. thus releasing one set of data locked by that statement. Comitting less often would be other solution. Multitable deadlocks can be avoided by locking the tables in same order in all the applications. When these extents are reused while these were still need by the query. As until transaction is comitted rollback segment can not be reused thus reducing the chances of a snapshot too old error. It does not always clean up the Unix session (LOCAL=NO sessions). What does 'SNIPED' status in v$session mean? When IDLE_TIME is set in the users' profiles or the default profile.0D.1 . I was running on 7. rollback segments created for that change are needed to make a read consistent image for the lon running query. this error occurs. These work in a circular fashion by looping around to reuse the extents which have been released by committed transactions. What is "snapshot too old" error and how to avoid it? First thing to be understood here is how rollback segments work. Thus in case of long running queries if data is changed while the query is running. After that neither svrmgrl not sqlplus were even starting.EXPIRE_TIME" in it to force the close of the SQL*Net session. Solution was to find shared memory segment for victim database by process of . Shared memory was still allocated for this instance and i was getting 6 trace files in udump directory every 5 minutes. At this time all oracle resources are released but the shadow processes remains and OS resources are not released. The errors in alert log were 600 and 7445 errors.back one of the statements involved in the deadlock. Database Crashed. Thus increasing the size of rollback segments and the value of OPTIMAL parameter should do the trick. These just returned back to unix prompt.ora on every client machine and include the parameter "SQLNET.4.3. Deadlocks are mostly caused by explicit locking because oracle does not do lock escalation and does not use read locks. because oracle can no longer provide a read consistent image of the data.ora. To avoid this error you need to postpone the reuse of extents. It seemed I had hit a bug resolved in 7. Statement rolled back is usually the one which detects the deadlock. Server manager doesn't come up This happened to me one fine morning.

2).2).h How To Find Out The Size Of Database How to find the size of database? In general the size of the database is defined as total size of the physical datafiles. Some sample sizes are: O/S Log Block Size ======= ============== Solaris 512 bytes HP-UX 1024 bytes NT 512 bytes OpenVMS 512 bytes Digital UNIX 1024 bytes To get it from the operating system. nvl(round(c.tablespace_name.elimination using "oradebug ipc" on all other databases and "ipcs -b" on unix prompt and then removing the shared memory segments using ipcsrm (-s or -m for shared memory or semaphores) How to find your log block size? You can find your log block size in bytes with the following query (connected as SYS or internal): select distinct lebsz from x$kccle.bytes. round(a.bytes.99 column tbfree heading 'Free|(Mb) ' justify right format 9.999.bytes.'0') tbused.0)/nvl(a.999.99 column tbused heading 'Used|(Mb) ' justify right format 9. try grep DEV_BSIZE /usr/include/sys/param. Code: clear breaks clear computes clear columns set pagesize 50 set linesize 120 set heading on column tablespace_name heading 'Tablespace' justify left format a20 truncated column tbsize heading 'Size|(Mb) ' justify left format 9.bytes.2) tbsize. to_char(round(100 * (nvl(c.'0') tbfree.bytes. This is the unit in which you should set the log_checkpoint_interval parameter (otherwise known as the operating system block size).2)) || '%' tbusedpct.0)/nvl(a. The following query will help you for the space management of your database.999. to_char(round(100 * (nvl(b.1)). nvl(round(b.99 column tbusedpct heading 'Used % ' justify left format a8 column tbfreepct heading 'Free % ' justify left format a8 break on report compute sum label 'Totals:' of tbsize tbused tbfree on report select t.bytes.999.bytes.1)).999.999.2)) || '%' tbfreepct .

tablespace_name union select tmp. round(sum(e.tablespace_name (+) and t. v$sort_segment sort where tmp. (select tablespace_name.tablespace_name) c where t.tablespace_name (+) order by t. ALTER TABLE test ENABLE CONSTRAINT pk_test exceptions into exceptions.bytes)/1024/1024.bytes)/1024/1024.tablespace_name. .tablespace_name = sort.tablespace_name (+) and t.2) bytes from dba_temp_files group by tablespace_name ) a.tablespace_name = b.tablespace_name / Oracle FAQ How to find the version of each oracle product installed? $ORACLE_HOME/orainst/inspdver utility provides a list of all the oracle products installed on the server with their verion numbers Identifying culprit rows when enabling of a constraint fails When you need to upload huge amount of data. You can find the culprit records by using EXCEPTIONS clause of ALTER TABLE statement.2) bytes from dba_segments e group by e. round(sum(bytes)/1024/1024. round(sum(f.tablespace_name = c. where exceptions table can be created by running $ORACLE_HOME/rdbms/admin/utlexcpt. (select f. what if afterwards enabling of constraints fail due to bad data.sum(max_size)) bytes from dba_temp_files tmp.sql script. (sum(bytes/1024/1024) .tablespace_name = a.tablespace_name.tablespace_name group by tmp.tablespace_name.tablespace_name union select tablespace_name. everybody says.from dba_tablespaces t. sum(max_size) bytes from v$sort_segment group by tablespace_name) b. that it is better to disable the constraints to give better performance. round(sum(bytes)/1024/1024. (select e. But.2) bytes from dba_free_space f group by f. For ex.2) bytes from dba_data_files group by tablespace_name union select tablespace_name.

IF ERRORLEVEL 1 PLUS33 will startup the sqlplus if youspecified EXIT 1 to get out from the sqlplus. oops! there oes you index.. you can trap the error . where datefield >= to_date(to_char(date1.emts every 100th of a second.Simpler way of finding plan and statistics of a query Executing EXPLAIN PLAN and then selecting from plan_table is one way to get the execution plan of a sql statement.. SET AUTOT[RACE] {OFF | ON | TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]] thus SET AUTOTRACE ON will do the whole work for you How to trap errors from sqlplus in NT bat scripts There is a variable ERRORLEVEL in NT. When you exits from sqlplus with a constant and check this variable in NT script.’DD-MON-YYYY’)||'00:00:00'. Instead SQL*PLUS offers a nifty command to enable and disable the display of execution plan of each statement executed in that session. But for this you need syntax of both statements and patience to type all that stuff for each statement. Also in sys. This number can also be negative How to use date index while using date ranges It becomes tricky to use an index on date columns for date ranges beacause as soon as you use trunc(). How to measure less than a second of time interval? It is possible to measure time interval of upto 1/100th of a second inoracle. Thus it can only be used for measuring time intervals. DBMS_UTILITY. Or you could do it all in one query using a join. Keep in mind that this number can be negative as well. In addition to this it can display the statistics for each statement. You can then use FILE_ID to query DBA_DATA_FILES to find the name of the datafile. For ex.GET_TIME function returns a number which increments every 100th of second.’DD-MON-YYYY’)||'23:59:59'.v_$timer table the column hsecs contains a number which also incre. So here is a way to use your index on date column for date ranges.'DD-MONYYYYHH24:MI:SS') . How to find the datafile which contains a particular table? If you query DBA_EXTENTS based on segment_name equal to your table name you will see that the column FILE_ID will show you the database file where each extent is located.'DD-MONYYYYHH24:MI:SS') and datefield <= to_date(to_char(date2.

How to roll back sequences? Use a negative increment and select from the sequence once. .ora to initNEWDB. check init.Controlfiles. check init. alter sequence qcs_ranum increment by 1. SVRMGR>Alter Database backup controlfile to trace.RedoLog files. ORACLE_SID MAY BE or MAY NOT BE the same as the database name.Archived Redo log files etc etc. Check /etc/oratab file (or depending on Oracle version /var/opt/oracle/oratab) for a list of instances on the server.2 database instance running on Solaris 8 platform.ora for db_name parameter. select qcs_ranum. # this will generate an Ascii Trace file in $USER_DUMP_DEST directory which will have the Control File Creation Script.ora file? ORACLE_SID is the instance name. Change my SID name after Creating Database You need to REcreate the Control file to achieve this . Rename the sid: 1) Shutdown database. For example.ora 3) In DB startup script replace ORACLE_SID export ORACLE_SID=NEWDB 4) Rename sid in /etc/oratab (or /var/opt/oracle/oratadb) 5) Startup database. is it the same as the instance_name in the init. What if the person who installed database can't remember what it was. In need of a Unix/Solaris shell script that would rename the Oracle SID of our Oracle 9. Shutdown the Database and Do a Physical Backup of all the Datafiles. 1. 2. this should reset the qcs_ranum sequence back 100: alter sequence qcs_ranum increment by -100..ora for instance_name parameter. 2) In $ORACLE_HOME/dbs directory copy initOLDDB..nextval from dual.for Safety. then reset the increment back to its correct setting. Finding Oracle_SID Of A Database Need to set ORACLE_SID of a database.

acme. Rename the Init<oldSID>. In other words.acme.. One config tool looks for SERVICE NAME and then the next looks for SIDs! What's going on?! Oracle SID is the unique name that uniquely identifies your instance/database where as Service name is the TNS alias that you give when you remotely connect to your database and this Service name is recorded in Tnsnames.com.use SID in tnsnames.. Rename the Old Controlfiles to say control01. If database is registered with listener in this way then you can use SERVICE_NAME parameter in tnsnames.ora file on your clients and it can be the same as SID and you can also give it any other name you want.. <all others remain the Same> ..ora files in $ORACLE_HOME/dbs This is to prevent any errors during Database Startups looking for default 'pfile' names. widgetsales.ora to Init<NEWSID>.ora otherwise . What is the difference between Oracle SIDs and Oracle SERVICE NAMES. SERVICE_NAME is the new feature from oracle 8i onwards in which database can register itself with listener.3. 4.com You can also use service names to identify a single service that is available from two different databases through the use of replication. Edit the Control File creation Script . You can specify multiple services names in order to distinguish among different uses of the same database. For example: SERVICE_NAMES = sales.old etc This is to Create New Controlfile and not reuse the existing one.ora. the definition is . Understand Exactly What a Schema Is Trying to understand exactly what a schema is and how it relates to another persons schema. Also if you have OPS (RAC) you will have different SERVICE_NAME for each instance.It should read like: Startup nomount.ora and Config<NewSid>. 5. Create Controlfile set Database 'NEW_SID' Resetlogs . you must set this parameter for every instance. Open your database: alter database open resetlogs.. In an Oracle Parallel Server environment. SERVICE_NAMES specifies one or more names for the database service to which this instance connects. 6..ora and config<OLDSID>.

insert. but not necessarily any DDL) data. or more precisely. procedures. so the users can perform select. you can have users whom do not own any objects of their own. inserts affect my data? As I am starting a new job with multiple schemas exist I want to fully understand how the statement that I commit affects those around me. The CREATE SCHEMA statement lets one specify (in a single SQL statement) all data and privilege definitions for a new schema. You'll see everything Scott owns. If I give access to someone to the objects in my database am I therefore giving them access to my schema? Or do they have their own schema in my database? If they are using my schema then I assume that any DDL statements that they commit affects the objects that I use. indexes. Am I right to assume that a schema are all the objects that exist in a database of my own creation.Schema A schema is the set of objects (tables. packages. Run the same query as before. but not all users are schema owners. SQL> show user USER is "SYSTEM" SQL> create user some_user identified by some_password. It is often used as another way to refer to an Oracle account. new to using Oracle. The schema owner has granted privileges on his tables. views. One can also add definitions to the schema later using DDL statements.deletes. A little background. update and delete on records. Suppose you have an application with a schema owner (keep the schema owner separate from sys and system. or "sa" in SQL Server terms). To make this more concrete in terms of an example you can touch. triggers. The application allows for users to access (perform DML. User created. Otherwise. What are objects? Tables. etc. A schema is a collection of objects owned by a user (so that makes a schema owner a user as well). for example. As system (or as a user with the DBA role): select object_name from dba_objects where owner='SCOTT'. Now create a user: create user some_name identified by some_password. views. but this time the owner is some_user. do you have the Scott schema installed? If so. I am accustom to Microsofts Sql Server 2000. indexes. . Schema owners (you can have more than one in a database) are users. SQL> select object_name from dba_objects where owner='SOME_USER'. if they have their own schema in my database then do update. etc) belonging to an account. functions. try this experiment.

then logon as some_user. and the rest of the output should be fairly self-explanatory.emp * ERROR at line 1: ORA-00942: table or view does not exist SQL> conn scott/tiger Connected. SQL> select empno from emp.no rows selected Now connect as some_user: SQL> conn some_user/some_password ERROR: ORA-01045: user SOME_USER lacks CREATE SESSION privilege. SQL> conn system/manager Connected. EMPNO ---------7369 7499 7521 . Grant succeeded. logon denied Warning: You are no longer connected to ORACLE. SQL> conn some_user/some_password Connected. Re-connect as system and grant connect to some_user. select empno from emp * ERROR at line 1: ORA-00942: table or view does not exist SQL> select empno from scott. SQL> select empno from emp. Grant succeeded.emp. SQL> grant select on emp to some_user. SQL> conn some_user/some_password Connected. select empno from scott. SQL> grant connect to some_user.

etc. he may have to qualify the schema name via scott. .. Scott has a public synonym for his emp table.copy the $ORACLE_BASE to /mnt/disk1 (this will be /u01/app/) $ cd $ORACLE_BASE $ cp -R /u01/app/* /mnt/disk1 . but it should help convey the concept about accessing objects (e. there is not much space left on this drive. (You may want to "drop user some_user" when finished.shutdown your Oracle DB and listener .7566 7654 7698 7782 7788 7839 7844 7876 7900 7902 7934 14 rows selected. which has two hard drives. how do I move oracle installation to a different location. so for some_user to see the contents of emp.. tables) in other schemas. the current installation is at /u01/app/oracle/product/10. and that is why "select whatever from emp" works for some_user. That's a little beyond what you asked about.g.1. SQL> The error when some_user tried to select from emp is due to the fact that the table name does not exist in some_user's schema..let's say /mnt/disk1 .ora and control files. it would be apparent that there is not a public synonym for the scott.) So basically.find a partition with enough disk space and mount it . I guess I have to shutdown oracle. a database can have more then one schema inside it. If the emp table has to be referenced or qualified by schema.1/myoraclehome However. Access to a particular schema object depends on whether you have been given access to that particular object by the schema owner. Change Oracle Installation Location on Linux I installed oracle 10g on a linux machine.table_name.emp. change *.emp table. On LINUX you can use symbolic links to do that. In this case.

STATISTIC# and NAME like '%CPU used by this session%' and se. .. se.Join v$process & v$session & v$sqlarea to know what happens in.exe. it just kill Oracle session.SID order by VALUE desc . we can use $ORACLE_HOME/bin/orakill. So we also need to kill the server process.SID. we use 'kill' command to kill a process. On Windows. On *nix. (can be downloaded from microsoft site) Take note that using 'ALTER SYSTEM KILL SESSION' is not enough to kill absolutely a session.drop the /u01/app/oracle directory $ rm -rf /u01/app/oracle .USERNAME.create a symbolic link to it $ ln -s /mnt/disk1/oracle /u01/app/oracle Now you can startup the DB and listener Processes that Used Too Much CPU Resources .SID = ss. one session in V$SESSION will have one corresponding process on Server Operating System.Session id CPU Usage . VALUE cpu_usage from v$session ss. For that you have to install microsoft's qslice. Check alert log for any error messages/trace file generated. For finding which process eat much CPU resource.CPU centiseconds used by this session (divide by 100 to get real CPU seconds) select nvl(ss.Name of the user SID . v$statname sn where se. v$sesstat se. You can also sice the oracle processes in windows.STATISTIC# = sn.'ORACLE PROC') username.Use 'top' command to find which processes (PID) eat much CPUs. As we know. you can use this sql CODE: CPU Usage By Session CPU USAGE BY SESSION NOTES: Username .

Add database name to tnsnames. We have implemented this and using UNICODE: 1.ora on second server 4.ora... For storing this data you have to set-up your front-end / client accordingly.And it has got many ways. you can not see them via sql+ like we use for English characters. etc for the copy database on second server 3. Now I want to store data in hindi format and also want to retrieve the data in same format.e.. Install Oracle server on new machine 2. etc.. Using NVARCHAR datatype will use the Database National Character Set for storage and it will store Multi-byte characters in less storage. Hindi Data.. For this I do not think Hindi Datatypes are needed. Create directories. Once your data is stored. Create database service with ORADIM (if OS is Windows) 5.That's you have to decide. Japanese.. 2.. 4... configuring database in above character set also stores ENGLISH. Create a Oracle9i database having UTF8 characterset. ..Hindi Format In Oracle Database I am working in Oracle 9i database. you have to use isql+. 3. . Cloning Database From Hot Backup To clone a db on another machine from hot backup. You need to configure that. follow these steps: 1.. . 6.sql. Use NVACHAR datatype to stotes the Unicode data i. 5. The best part is that. For that. Rename trace file to create_control. So how I'll set up the dataase so that it will possible. edited. initfile..as well as Mutibyte character sets like HINDI. listener. contents are as follows: STARTUP NOMOUNT CREATE CONTROLFILE SET DATABASE "<SID>" RESETLOGS ARCHIVELOG .. On original OPEN db: ALTER DATABASE BACKUP CONTROL FILE TO TRACE RESETLOGS.

ora.log' size 100M. -------------------------------------------------------------------------------------------------If you have 9i then use RMAN to create a duplicate the database.7. Copy the ORADATA dirctory including archived logs to second server 9. allocate auxiliary channel d1 type disk. 8.RMAN script without SET NEWNAME run { set until logseq 18 thread 1. etc.RMAN script with SET NEWNAME . db_file_name_convert = ('/DATA/ORACLE/ORADATA/HOMEBD'. Run the CREATE CONTROL file script shown above 12. '/DATA/ORACLE/ORADATA/CLNE') log_file_name_convert = ('/DATA/ORACLE/ORADATA/HOMEDB'. Delete the control files already copied over using OS commands 11.ORA NAME_CONVERT parameters.log' size 100M. } -. password file. Go to second server. Then do: ALTER SYSTEM ARCHIVE LOG CURRENT. I am using the DB_FILE_NAME_CONVERT and LOG_FILE_NAME_CONVERT parameters in the init.ora file for the clone database: Example: -. '/data/oracle/oradata/clne/redo03. '/DATA/ORACLE/ORADATA/CLNE') Then use one of these RMAN scripts ( if you want or don't want to change the SID): -. Create the necessary folders. duplicate target database to CLNE logfile '/data/oracle/oradata/clne/redo01.log' size 100M. and use sqlplus to connect as SYSDBA 10. Issue: RECOVER DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL.INIT. set SID. '/data/oracle/oradata/clne/redo02. init.

SET echo off SET feedback off SET linesize 512 PROMPT PROMPT Server Statisitics PROMPT COLUMN dummy noprint . set newname for datafile 7 to '/data/oracle/oradata/clne/tools01.dbf'. set newname for datafile 4 to '/data/oracle/oradata/clne/drsys01. } How Can We Calculate Hit Ratios How can we calculate hit ratios in a cluster environment? I mean RAC. '/data/oracle/oradata/clne/redo03.dbf'. In RAC. set newname for datafile 3 to '/data/oracle/oradata/clne/cwmlite01. '/data/oracle/oradata/clne/redo02. Because each instance has its own parameter file. You can get the information from gv$views (gv$librarycache / gv$sysstat ) etc But. Programmatically.log' size 100M. and 2 or more instance will be attached to one database.run { set newname for datafile 1 to '/data/oracle/oradata/clne/system01.log' size 100M. For RAC env please use this scripts to find stats.dbf'. set newname for datafile 5 to '/data/oracle/oradata/clne/example01. Hit ratios like buffer cache Hit ratio are not a valid UNIT of measure for performance. It is just JUNK data. but is useless to use stats for any pratical purpose.dbf'. duplicate target database to CLNE logfile '/data/oracle/oradata/clne/redo01. set newname for datafile 8 to '/data/oracle/oradata/clne/users01. allocate auxiliary channel d1 type disk.log' size 100M. So the hit ratios you will get from database dictionary is of which node.dbf'.dbf'. you can get any hitratio you want.dbf'. set newname for datafile 2 to '/data/oracle/oradata/clne/undotbs01. set newname for datafile 6 to '/data/oracle/oradata/clne/indx01.dbf'. Please try to use oracle OWI for any practical tuning purpose. set until logseq 18 thread 1.

ROUND (( ( 1 . SUM (gethits) / SUM (gets) * 100 VALUE FROM gv$librarycache group by inst_id UNION ALL SELECT 4. decode(inst_id. decode(inst_id.( SUM (DECODE (NAME. VALUE.COLUMN value format 999.'taurus'.'taurus'. SUM (pinhits) / SUM (pins) * 100 VALUE FROM gv$librarycache group by inst_id / .(SUM (getmisses) / SUM (gets))) * 100 VALUE FROM gv$rowcache group by inst_id UNION ALL SELECT 3.'taurus'.decode(inst_id. (1 . 2 ) VALUE FROM gv$sysstat group by inst_id UNION ALL SELECT 2. 'Buffer Cache Hit Ratio' statname. 0)) + (SUM (DECODE (NAME.'Dictionary Hit Ratio'.1.'Library Cache Get Pin Ratio'. 0))) ) ) ) * 100 ).'libra') NODE.'libra') NODE.99 COLUMN statname format a30 heading 'Statistics Name' COLUMN NODE format a10 BREAK on report SELECT 1 dummy.1. 'db block gets'. inst_id NODE. 'physical reads'.'Library Cache Get Hit Ratio'. VALUE.1. VALUE. 0)) / ( SUM (DECODE (NAME.'libra') NODE. 'consistent gets'.

Sign up to vote on this title
UsefulNot useful