Oracle DBA Tips and Techniques

By Arjun Raja

Archive for June, 2009

Flashback table

Posted by Gavin Soorma on June 29, 2009

FLASHBACK TABLE

Only FLASHBACK DATABASE requires flashback to be ‘ON’ since only FLASHBACK DATABASE uses flashback logs in the flash_recovery_area.

All other forms of FLASHBACK use the recycle bin and undo_tablespace.

Important info:

You cannot ‘flashback table to before drop’ a table which has been created in the SYSTEM tablespace.

The table is sent to the recyclebin only if it existed in some other tablespace other than SYSTEM tablespace and that tablespace must be locally managed.

When you drop a table, the objects are temporarily placed in a ‘recycle bin’ and still belong to the owner.

The space used by recycle bin objects is never reclaimed unless there is space pressure.

The space associated with the dropped object is not immediately reclaimable although it appears in the DBA_FREE_SPACE view.

Query the dba_recyclebin view as SYS or just recyclebin as the user for information about the recycle bin.

Flashback drop allows you to recover a dropped table.

Example.

Connect arjun/arjun

Create table tempp (col_1 number(10)) tablespace users;

Insert into tempp values (10);

1 row created.

SQL> drop table tempp;

Table dropped.

SQL> show recyclebin;

ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
—————- —————————— ———— ——————-
TEMPP BIN$AI2Gp/QiZsPgQAw5yUImEA==$0 TABLE 2005-09-12:10:49:16

SQL> flashback table tempp to before drop;

Flashback complete.

SQL> select * from tempp;

COL_1
———-
10

In case the table is created in the system tablespace :

SQL> show user

USER is “SYS”…..Default tablespace SYSTEM

SQL> create table arjun1 (col_1 number(10));

Table created.

SQL> drop table arjun1;

Table dropped.

SQL> select * from dba_recyclebin;

no rows selected

SQL> flashback table arjun1 to before drop;
flashback table arjun1 to before drop
*
ERROR at line 1:
ORA-38305: object not in RECYCLE BIN

Permanently drop without recycle bin
Drop table test purge;

QUERYING DROPPED TABLES

Dropped tables can be queried from the recycle bin. No DML or DDL operations are allowed on the table.

SQL> drop table tempp;

Table dropped.

SQL> show recyclebin;
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
—————- —————————— ———— ——————-
TEMPP BIN$AI9AwvFRdf7gQAw5yUIsGA==$0 TABLE 2005-09-12:13:15:22

While querying the recycle bin, make sure the system generated table name is enclosed in double quotes.

SQL> select * from BIN$AI9AwvFRdf7gQAw5yUIsGA==$0;
select * from BIN$AI9AwvFRdf7gQAw5yUIsGA==$0
*
ERROR at line 1:
ORA-00933: SQL command not properly ended

SQL> select * from ‘BIN$AI9AwvFRdf7gQAw5yUIsGA==$0’;
select * from ‘BIN$AI9AwvFRdf7gQAw5yUIsGA==$0’
*
ERROR at line 1:
ORA-00903: invalid table name

SQL> select * from “BIN$AI9AwvFRdf7gQAw5yUIsGA==$0”;

COL_1
———-
10

You cannot run any DML or DDL on dropped tables ….

SQL> Insert into tempp values(20);
Insert into tempp values(20)
*
ERROR at line 1:
ORA-00942: table or view does not exist

FLASHBACK TABLE TO A TIME IN THE PAST.

Firstly enable row movement for table test..

SQL> ALTER TABLE TEST ENABLE ROW MOVEMENT;

TIME : 08:00:00

SQL> select * from test;

SALARY
———-
5000

TIME :08:00:01

SQL> update test set salary =6000;

1 row updated.

SQL> select * from test;

SALARY
———-
6000

SQL> commit;

Commit complete.

Now flashback table to time 08:00:00

SQL> FLASHBACK TABLE TEST to timestamp TO_TIMESTAMP( ‘2005-09-13 08:00:00′,’YYYY-MM-DD HH24:MI:SS’);

Flashback complete.

SQL> SELECT * FROM TEST;

SALARY
———-
5000

Posted in Administration, High Availability | Leave a Comment »

MANUAL INSTALLATION OF DB CONTROL

Posted by Gavin Soorma on June 29, 2009

To manually install and administer a database using DBCONTROL –

cd $ORACLEHOME/bin
oraofsap(DATABASE)@xxxxx:pwd
/u01/app/oracle/product/10.2/bin

./emca -config dbcontrol db -repos create

STARTED EMCA at Oct 23, 2008 10:23:59 AM
EM Configuration Assistant, Version 10.2.0.1.0 Production
Copyright (c) 2003, 2005, Oracle. All rights reserved.

Enter the following information:
Database SID: test
Listener port number: 1521
Password for SYS user: ——– ENTER SYS PASSWORD
Password for DBSNMP user:——ENTER DBSNMP PASSWORD
Password for SYSMAN user: – no user exists so just give any password.
Email address for notifications (optional): Enter
Outgoing Mail (SMTP) server for notifications (optional):
—————————————————————–

You have specified the following settings

Database ORACLE_HOME …………… /u01/app/oracle/product/10.2

Database hostname ……………. xxxxxx.xxxxx.com
Listener port number ……………. 1521
Database SID ……………. test
Email address for notifications ……………
Outgoing Mail (SMTP) server for notifications ……………

—————————————————————–
Do you wish to continue? [yes(Y)/no(N)]: Y
Oct 23, 2008 10:26:36 AM oracle.sysman.emcp.EMConfig perform
INFO: This operation is being logged at /u01/app/oracle/product/10.2/cfgtoollogs/emca/test/emca_2008-10-23_10-23-58-AM.log.
Oct 23, 2008 10:26:40 AM oracle.sysman.emcp.EMReposConfig createRepository
INFO: Creating the EM repository (this may take a while) …

Oct 23, 2008 10:30:52 AM oracle.sysman.emcp.EMReposConfig invoke
INFO: Repository successfully created
Oct 23, 2008 10:31:07 AM oracle.sysman.emcp.util.DBControlUtil secureDBConsole
INFO: Securing Database Control (this may take a while) …
Oct 23, 2008 10:32:04 AM oracle.sysman.emcp.util.DBControlUtil secureDBConsole
INFO: Database Control secured successfully.
Oct 23, 2008 10:32:04 AM oracle.sysman.emcp.util.DBControlUtil startOMS
INFO: Starting Database Control (this may take a while) …
Oct 23, 2008 10:33:48 AM oracle.sysman.emcp.EMDBPostConfig performConfiguration
INFO: Database Control started successfully
Oct 23, 2008 10:33:48 AM oracle.sysman.emcp.EMDBPostConfig performConfiguration
INFO: >>>>>>>>>>> The Database Control URL is https://xxxxxx.xxxxx.com:1158/em <<<<<<<<<<< – use the I.P address also -https://10.254.203.177:1158/em
Enterprise Manager configuration completed successfully
FINISHED EMCA at Oct 23, 2008 10:33:48 AM
oracle(DATABASE)@xxxxx:

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

FLASHBACK DATABASE

Posted by Gavin Soorma on June 29, 2009

FLASHBACK DATABASE

Flashback database allows you to rollback database to a time in the past.

Useful if you have :

1. Dropped user
2. Truncated table
3. Batch job:Partial changes.

PRE-REQUISITE: DATABASE MUST BE IN ARCHIVELOG MODE AND YOU MUST SET FLASHBACK ON( BY DEFAULT IT IS OFF)

FLASHBACK LOGS ARE CREATED IN YOUR FLASH_RECOVERY_AREA SPECIFIED BY THE INIT.ORA PARAMETER – DB_RECOVERY_FILE_DEST

To set FLASHBACK ON in your 10g database.

shutdown immediate;

startup mount exclusive;….Must be mounted exclusive.

alter database flashback on;

alter database open;

To Flashback database…

Flashback database can be issued with 3 different conditions:

1. TO_TIME
2. TO SCN
3. TO SEQUENCE( LOG ARCHIVE SEQ)

FLASHBACK TO_TIME

PRESENT TIME IS 2009-06-29 07:40:00

drop user arjun cascade;

user dropped.

shutdown immediate;

startup mount;

flashback database to timestamp TO_TIMESTAMP( ‘2009-06-29 07:38:00′,’YYYY-MM-DD HH24:MI:SS’);

alter database open resetlogs;

select username from dba_users;

SQL> select username from dba_users;

USERNAME
——————————
SYS
SYSTEM
DBSNMP
ARJUN
OUTLN

After this is done you cannot flashback the database to a time before the original flashback…

Shutdown immediate;

Startup mount;

SQL> flashback database to timestamp TO_TIMESTAMP( ‘2009-06-29 07:35:00′,’YYYY-MM-DD HH24:MI:SS’);
flashback database to timestamp TO_TIMESTAMP( ‘2009-06-29 07:35:00′,’YYYY-MM-DD HH24:MI:SS’)
*
ERROR at line 1:
ORA-38729: Not enough flashback database log data to do FLASHBACK.

But you can flashback the tablespace to a time after the original flashback time of 07:38:00

SQL> flashback database to timestamp TO_TIMESTAMP( ‘2009-06-29 07:45:00′,’YYYY-MM-DD HH24:MI:SS’);

Flashback complete.

alter database open resetlogs;

FOR FLASHBACK TO SCN….

Alter database mount;

Flashback database to scn=12355;

To get current_scn: select current_scn from v$database;

TO FLASHBACK TO SEQUENCE NUMBER…

Alter database mount;

Flashback database to sequence=223 thread=1;

Posted in Backup and Recovery, High Availability | Leave a Comment »

ARCHIVE AREA FULL – CONNECT INTERNAL UNTIL FREED

Posted by Gavin Soorma on June 29, 2009

When a database is running in ARCHIVELOG mode, if the area which stores the archivelogs on disk gets full, the database comes to a halt and can be accessed only as a sysdba.

The error message when you try to connect as a normal user is ‘ CONNECT INTERNAL UNTIL FREED’

If the following parameter is in use – DB_RECOVERY_FILE_DEST as the archivelog destination , then the size of the parameter DB_RECOVERY_FILE_DEST_SIZE can be increased dynamically and then the database begins to function again –

Ex

SQL> show parameter db_recovery_file_dest;

NAME TYPE VALUE
———————————— ———– ——————————
db_recovery_file_dest string /opt/oracle/flash_recovery_area

db_recovery_file_dest_size big integer 1000M

SQL> SELECT * FROM V$RECOVERY_FILE_DEST;

NAME
——————————————————————————–
SPACE_LIMIT SPACE_USED SPACE_RECLAIMABLE NUMBER_OF_FILES
———– ———- —————– —————
/opt/oracle/flash_recovery_area

1048576000 1048260608 0 163

There are a couple of possible options.

1) Increase the parameter db_recovery_file_dest_size, which is dynamic.

SQL> alter system set db_recovery_file_dest_size=XG; (larger amount) – Example 2G

2) Stop using the db_recovery_file_dest by unsetting the parameter.
( This assumes you never really wanted to use this option )

Posted in Administration, High Availability | Tagged: , , | Leave a Comment »

RMAN – Clear Saved Configuration

Posted by Gavin Soorma on June 25, 2009

To clear the saved configuration in rman – example the configuration for Channel 1

RMAN> CONFIGURE CHANNEL 1 DEVICE TYPE DISK CLEAR;

starting full resync of recovery catalog
full resync complete
old RMAN configuration parameters:
CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT ‘/ora_export/backup/fin/%U’ MAXPIECESIZE 16 G;
old RMAN configuration parameters are successfully deleted
starting full resync of recovery catalog
full resync complete

Posted in Backup and Recovery | Leave a Comment »

Unix – remove file with unseen characters

Posted by Gavin Soorma on June 25, 2009

This works on AIX – Please test on other systems.

If a file name is vague and can’t be removed.

Ex – a file name has some hidden characters which prevents it’s removal as the name is not recognized by the rm command.

ls -lai sqlnet.log
19462 -rw-r—– 1 oraofsap dba 7741 Jun 4 13:14 sqlnet.log

look for number against file and rm number .

find . -inum 19462 -exec rm {} \;

Posted in Unix | Tagged: | Leave a Comment »

Export and Import schema statistics

Posted by Gavin Soorma on June 25, 2009

Easy way to export and import schema statistics – in case the optimizer is behaving strangely and you want to re-import old statistics when the optimizer behaved properly.

SCHEMA NAME – TEST

Create the table to store the statistics-
EXEC DBMS_STATS.CREATE_STAT_TABLE(‘TEST’, ‘STATS_TABLE’);

Export schema stats – will be stored in the ‘STATS_TABLE’
EXEC DBMS_STATS.export_schema_stats(‘TEST’,’STATS_TABLE’,NULL,’TEST’);

If required import these statistics back to TEST schema.
EXEC DBMS_STATS.import_schema_stats(‘TEST’,’STATS_TABLE’,NULL,’TEST’);

Finally drop the table created to backup the schema stats
EXEC DBMS_STATS.drop_stat_table(‘TEST’,’STATS_TABLE’);

Posted in Performance Tuning | Tagged: , | Leave a Comment »

11g Passwords can be case sensitive

Posted by Gavin Soorma on June 22, 2009

In 11g – Passwords are case sensitive but this can be controlled by an init.ora parameter –

SQL> show parameter SEC_CASE_SENSITIVE_LOGON ;

NAME TYPE VALUE
———————————— ———– ——————————
sec_case_sensitive_logon boolean TRUE

SQL> create user arjun identified by ARJUN; – Password in Upper Case.

User created.

SQL> grant create session to arjun;

Grant succeeded.

SQL> conn arjun/arjun; – Tried to connect with lower case password – FAILS.
ERROR:
ORA-01017: invalid username/password; logon denied

Warning: You are no longer connected to ORACLE.
SQL> exit
apex:/u01/oracle> sqlplus “sys as sysdba”

Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> conn arjun/ARJUN – CONNECTS –
Connected.
SQL>exit

Sqlplus “sys as sysdba”

Now alter the parameter to FALSE – so case sensitive passwords are not required.

SQL> alter system set sec_case_sensitive_logon=false;

System altered.

SQL> conn arjun/arjun; – Connects with lower case password although password at time of creation was in UPPER case.

Posted in Oracle 11g | Tagged: , , | Leave a Comment »

11g ACTIVE STANDBY

Posted by Arjun Raja on June 22, 2009

Active Standby :

PRIMARY DB- APEX

STANDBY DB- APEXDG

Now you can bring up the standby database in read-only mode and continue to have the standby database updated from the primary. Here are the steps to achieve that:

1. Stop the managed recovery process on STANDBY database :
In APEXDG ( Standby database )

SQL > alter database recover managed standby database cancel;
Database altered.

2. Open the APEXDG – standby database as read-only:
SQL > alter database open read only;
Database altered.

3. Restart the managed recovery process ON STANDBY DATABASE :

SQL > alter database recover managed standby database using current logfile disconnect;

Now the standby database is being updated, but it is simultaneously open for read-only access—this is the essence of Oracle Active Data Guard.

4. To test the “active” part of Oracle Active Data Guard, create a table in the primary database:

In PRIMARY database –
SQL > select table_name from dba_tables where table_name = ‘ARJUN’;
no rows selected

On STANDBY
SQL > select table_name from dba_tables where table_name = ‘ARJUN’;
no rows selected

In APEX database – PRIMARY
SQL > create table arjun (col1 number);

5. After a few seconds, check the existence of the table in the standby database:
SQL > select table_name from dba_tables where table_name = ‘ARJUN’;

TABLE_NAME
——————————
ARJUN

The table will be present !!

The standby database is open in read-only mode, but it is still applying the logs from the primary database.
This feature enables you to run reports against it without sacrificing the ability to put the standby database into the primary role quickly.

6. To confirm the application of redo logs on the primary database, first switch the log file:
alter system switch logfile;

7. Now observe the alert log of the standby database. Use the automatic diagnostic repository command interpreter (ADRCI) tool, new in Oracle Database 11g:

$ adrci
show alert -tail –f

kcrrvslf: active RFS archival for log 6 thread 1 sequence 15694
RFS[7]: Successfully opened standby log 5: ‘/u02/oradata/apexdg/standby02.log’
Media Recovery Log /u02/oradata/apexdg/arch/APEXDG/archivelog/2008_12_05/o1_mf_1_15694_4mk48s9y_.arc
Media Recovery Waiting for thread 1 sequence 15695 (in transit)
Recovery of Online Redo Log: Thread 1 Group 5 Seq 15695 Reading mem 0
Mem# 0: /u02/oradata/apexdg/standby02.log

Conclusion

The physical standby database is a physical replica of the primary database, kept in sync by the application of redo log entries from the primary database.
With Oracle Active Data Guard and real time apply, the log entries are applied in real time but the primary database does not wait for the redo application to complete, thereby protecting itself from failures or slowdowns in the shipment of log information from the primary to the standby database.
Using the Oracle Active Data Guard option, you can open the physical standby database for read-only operations while the managed recovery process is going on. You can offload all reporting applications and the Oracle RMAN backup to the standby database, easing the load on the primary database considerably.
And because the standby database is being recovered continuously with real time apply, the standby database can be activated and used immediately in case the primary database fails. This combination of features makes the investment in Oracle Active Data Guard very worthwhile.

Posted in Oracle 11g | Tagged: , , , | Leave a Comment »

List and remove all files older than 30 days

Posted by Gavin Soorma on June 22, 2009

 

 

find /u01/local/logs -mtime +30 -exec ls -l {} \;

find /u01/local/logs -mtime +30 -exec rm {} \;

 

Posted in Unix | Leave a Comment »