Tuesday, 18 June 2013

Thread 1 cannot allocate new log, sequence 124825, All online logs needed archiving
Last week I faced some interesting issue due to archiver process.

I got connection refused alert from web server. I verified the logs, Application user connections were refused for around 10 minutes.
I verified the oracle database alert log file & we found below information alert.

ARCH: Connecting to console port…
Thread 1 cannot allocate new log, sequence 124825
All online logs needed archiving


In database, log_archive_max_processes value is 2 & redo log file size is 250 MB (3 Groups only).

Why it’s happened?

Due to huge transactions (lot of DML operations – happened unexpectedly in database), archiver not able to archive the online redo log files.

Solution:


1.Increase the log_archive_max_processes from 2 to 5.
2.Add the new online redo log groups (3 groups to 5 groups).
3.Increase the online redo log file size from 250MB TO 500MB
.

Monday, 17 June 2013

Restore the table using flashback table from recyclebin , whether the index belong to this table will be build or not?

ANSWER
Restoring Tables from the Recycle Bin

Use the FLASHBACK TABLE ... TO BEFORE DROP statement to recover objects from the recycle bin. You can specify either the name of the table in the recycle bin or the original table name. An optional RENAME TO clause lets you rename the table as you recover it. The recycle bin name can be obtained from either theDBA_ or USER_RECYCLEBIN view.

      To use the FLASHBACK TABLE ... TO BEFORE DROP statement, you need the same privileges you need to drop the table.

The following example restores int_admin_emp table and assigns to it a new name:

FLASHBACK TABLE int_admin_emp TO BEFORE DROP RENAME TO int2_admin_emp;

The system-generated recycle bin name is very useful if you have dropped a table multiple times. For example, suppose you have three versions of theint2_admin_emp table in the recycle bin and you want to recover the second version. You can do this by issuing two FLASHBACK TABLE statements, or you can query the recycle bin and then flashback to the appropriate system-generated name, as shown in the following example. Including the create time in the query can help you verify that you are restoring the correct table.

SELECT object_name, original_name, createtime FROM recyclebin;   

OBJECT_NAME                    ORIGINAL_NAME   CREATETIME
------------------------------ --------------- -------------------
BIN$yrMKlZaLMhfgNAgAIMenRA==$0 INT2_ADMIN_EMP  2006-02-05:21:05:52
BIN$yrMKlZaVMhfgNAgAIMenRA==$0 INT2_ADMIN_EMP  2006-02-05:21:25:13
BIN$yrMKlZaQMhfgNAgAIMenRA==$0 INT2_ADMIN_EMP  2006-02-05:22:05:53

FLASHBACK TABLE BIN$yrMKlZaVMhfgNAgAIMenRA==$0 TO BEFORE DROP;

Restoring Dependent Objects

    When you restore a table from the recycle bin, dependent objects such as indexes do not get their original names back; they retain their system-generated recycle bin names. You must manually rename dependent objects if you want to restore their original names. If you plan to manually restore original names for dependent objects, ensure that you make note of each dependent object's system-generated recycle bin name before you restore the table.

The following is an example of restoring the original names of some of the indexes of the dropped table JOB_HISTORY, from the HR sample schema. The example assumes that you are logged in as the HR user.

1.     After dropping JOB_HISTORY and before restoring it from the recycle bin, run the following query:

SELECT OBJECT_NAME, ORIGINAL_NAME, TYPE FROM RECYCLEBIN;

OBJECT_NAME                    ORIGINAL_NAME             TYPE
------------------------------ ------------------------- --------
BIN$DBo9UChtZSbgQFeMiAdCcQ==$0 JHIST_JOB_IX              INDEX
BIN$DBo9UChuZSbgQFeMiAdCcQ==$0 JHIST_EMPLOYEE_IX         INDEX
BIN$DBo9UChvZSbgQFeMiAdCcQ==$0 JHIST_DEPARTMENT_IX       INDEX
BIN$DBo9UChwZSbgQFeMiAdCcQ==$0 JHIST_EMP_ID_ST_DATE_PK   INDEX
BIN$DBo9UChxZSbgQFeMiAdCcQ==$0 JOB_HISTORY               TABLE

2.     Restore the table with the following command:

FLASHBACK TABLE JOB_HISTORY TO BEFORE DROP;

3.     Run the following query to verify that all JOB_HISTORY indexes retained their system-generated recycle bin names:

SELECT INDEX_NAME FROM USER_INDEXES WHERE TABLE_NAME = 'JOB_HISTORY';

INDEX_NAME
------------------------------
BIN$DBo9UChwZSbgQFeMiAdCcQ==$0
BIN$DBo9UChtZSbgQFeMiAdCcQ==$0
BIN$DBo9UChuZSbgQFeMiAdCcQ==$0
BIN$DBo9UChvZSbgQFeMiAdCcQ==$0

4.     Restore the original names of the first two indexes as follows:

ALTER INDEX "BIN$DBo9UChtZSbgQFeMiAdCcQ==$0" RENAME TO JHIST_JOB_IX;

ALTER INDEX "BIN$DBo9UChuZSbgQFeMiAdCcQ==$0" RENAME TO JHIST_EMPLOYEE_IX;

Saturday, 15 June 2013

How to check whether sql query captured in AWR?

We can generate the AWR report and manually search the sql using sql_id
or query string.
:-)

Oracle provide a easy method.

Using dbms_workload_repository.awr_sql_report_text function, we can
easily find whether sql query captured or not.

select * from table(dbms_workload_repository.awr_sql_report_text
(&v_db_id, &v_inst_num, :b_snap_id, :e_snap_id, '&v_sql_id'));

Wednesday, 5 June 2013

Moving table(s) to a different tablespace in Oracle,And what happen to the dependent objects like function, procedures, indexes


There are a couple of ways in which a table can be moved to a different tablespace:
1) One of them is to perform export/import.
2) Another approach is to use the ‘alter table’ command with ‘move tablespace’ clause.
Let us start by creating a table. Connect to SQL*Plus using proper credentials and run the following SQLs:
CREATE TABLE SAMPLE
(
SAMPLE_ID NUMBER(9) NOT NULL,
SAMPLE_DESC VARCHAR(10),
CONSTRAINT PK_SAMPLE PRIMARY KEY(SAMPLE_ID)
)
/
CREATE INDEX SAMPLE_IND_1 ON SAMPLE(SAMPLE_DESC)
/
Above SQLs creates table and index in user’s default tablespace. In our case it is ‘users’ tablespace. Run following SQL to check where these objects are created.
SELECT TABLE_NAME,TABLESPACE_NAME,STATUS
FROM User_Tables
WHERE TABLE_NAME = ‘SAMPLE’
UNION ALL
SELECT INDEX_NAME,TABLESPACE_NAME,STATUS
FROM User_Indexes
WHERE TABLE_NAME = ‘SAMPLE’
/
And the result is
TABLE_NAME TABLESPACE_NAME STATUS
—————————— —————————— ——–
SAMPLE      USERS     VALID
SAMPLE_IND_1    USERS    VALID
PK_SAMPLE      USERS     VALID
Since we are using UNION ALL, two indexes PK_SAMPLE (Primary key index) and SAMPLE_IND_1 are also shown under TABLE_NAME column. Result shows that table and its corresponding indexes are crated in USERS tablespace and in valid status. Now let us insert one record into the table.
INSERT INTO SAMPLE VALUES(1,’Hello’);
COMMIT;
Now let us retrieve value for SAMPLE_ID column along with value of pseudo column ROWID. We will explain you later in the article, why we are retrieving ROWID. Following is the SQL followed by result.
SQL> SELECT ROWID, SAMPLE_ID FROM SAMPLE;
ROWID SAMPLE_ID
—————— ———-
AAAQ+eAAEAAAA3tAAA 1
Now we will move the SAMPLE table to another tablespace ‘TEST’. We already have another tablespace TEST in place. If you don’t have another tablespace where you can move the table, please create the tablespace first for testing purpose. Following command will move table SAMPLE to new tablespace TEST.
SQL> ALTER TABLE SAMPLE MOVE TABLESPACE TEST;
Above command will move table to new tablespace TEST. Now let us check ROWID value again by re-issuing previous SQL.
SQL> SELECT ROWID, SAMPLE_ID FROM SAMPLE;
ROWID SAMPLE_ID
—————— ———-
AAAQ+hAAHAAAAAsAAA 1
So far we have moved only table. Moving table to new tablespace will make all the indexes on the table unusable. We can verify it by issuing the SQL we executed initially after creation of table and index.
TABLE_NAME TABLESPACE_NAME STATUS
—————————— —————————— ——–
SAMPLE    TEST     VALID
SAMPLE_IND_1    USERS     UNUSABLE
PK_SAMPLE       USERS      UNUSABLE
Result shows that table has been moved to new tablespace TEST and is in ‘valid’ status while indexes still point to older tablespace and are in ‘unusable’ status. Indexes in unusable state will prevent any DML activity on the table. We can verify this by inserting new record into SAMPLE table.
INSERT INTO SAMPLE VALUES(2,’World!’);
Running above SQL will result in following error.
ERROR at line 1:
ORA-01502: index ‘DECIPHER.PK_SAMPLE’ or partition of such index is in unusable
State
Why this happened? When we moved table to new tablespace, each row of the table got moved and got new ROWID. If you compare the ROWID values before and after the move, you will realize that ROWID for the same SAMPLE_ID is different. Indexes point to the previous location of the row and not to the current location. This warrants for rebuilding of an index. If you also want to move index to the new tablespace then you can include tablespace clause. If you want to keep the index in the same tablespace where it is currently, you just need to issue only rebuild clause. Following is the example of both.
ALTER INDEX PK_SAMPLE REBUILD;
ALTER INDEX SAMPLE_IND_1 REBUILD TABLESPACE TEST;
First statement only rebuilds the primary key index without moving it to new tablespace. Second statement rebuilds the index and also moves it to the other tablespace. Verify it by issuing following SQL.
SELECT INDEX_NAME,TABLESPACE_NAME,STATUS
FROM User_Indexes
WHERE TABLE_NAME = ‘SAMPLE’;
Result is
INDEX_NAME TABLESPACE_NAME STATUS
—————————— —————————— ——–
SAMPLE_IND_1 TEST VALID
PK_SAMPLE USERS VALID
Once indexes are rebuilt, all DML operations can be resumed on the table. If you try to insert the record, which gave error previously, should work fine after rebuilding all the indexes on the table. One thing to remember is that ‘MOVE TABLESPACE’ does not work if table contains column with LONG or LONG RAW data type. You will run into ‘ORA-00997: illegal use of LONG datatype’ error. Such tables can be moved to new tablespace using exp/imp command.

Sunday, 2 June 2013

Log actively being archived by another process
 Yesterday I saw my alert log for some issue. I found some information alert in my alert log file. I would like to share you.

Alert:
----------

ARC0: Evaluating archive log 2 thread 1 sequence 25821
ARC0: Unable to archive log 2 thread 1 sequence 25821
Log actively being archived by another process 
ARC1: Evaluating archive log 3 thread 1 sequence 25822
ARC1: Beginning to archive log 3 thread 1 sequence 25822

Why we getting this information alert?

Archiver process trying to archive a log (sequence# 25821) and its sees that another archiver process is already archiving the redo log files.

Is there any impact due to this alert?

There is no impact in database. This one is information alert. We can consider this one is noise alert & we can ignore it.