Posts

Showing posts from June, 2013

adding primary key to already existing table in oracle

lets assume that there was a table ABC that was already existing in the database and you want to add an additional column with unique primary key values. sql to create table abc :   CREATE TABLE "ABC"    (    "USERNAME" VARCHAR2(30 BYTE) NOT NULL ENABLE,     "USER_ID" NUMBER NOT NULL ENABLE,     "CREATED" DATE NOT NULL ENABLE )    TABLESPACE "QUIKPAY_USER" ; now we  can add an additional column ID which will be populated with all unique values. alter table abc add(ID NUMBER); you can create a sequence and get the values from the seq and insert them into table ID column: CREATE SEQUENCE SEQ_ID START WITH 1 INCREMENT BY 1 MAXVALUE 999999 MINVALUE 1 NOCYCLE; now insert the unique values into the database with below sql UPDATE abc SET ID = SEQ_ID.NEXTVAL; now you can make the column unique or add primary key to table,so that it wont take any more duplicate value into the table. alter table abc add primarykey (ID);

Performance - AWR report

Performance - AWR Display a list of snapshots Produce a report To see the snapshot interval and retention period Change the snapshot interval Change the retention period Manually take a snapshot List all baselines Create a baseline Remove a baseline Enable/Disable automatic snapshots Time model queries Produce an Active Session History (ASH) report Display a list of snapshots   set lines 100 pages 999 select     snap_id ,                snap_level ,                to_char(begin_interval_time, 'dd/mm/yy hh24:mi:ss') begin from       dba_hist_snapshot order by 1 / You can see what snapshots are currently in the AWR by using the DBA_HIST_SNAPSHOT view as seen in this example: SELECT snap_id, to_char(begin_interval_time,'dd/MON/yy hh24:mi') Begin_Interval, to_char(end_interval_time,'dd/MON/yy hh24:mi') End_I...

datapump basic's

CONN / AS SYSDBA ALTER USER scott IDENTIFIED BY tiger ACCOUNT UNLOCK; CREATE OR REPLACE DIRECTORY test_dir AS '/u01/app/oracle/oradata/'; GRANT READ, WRITE ON DIRECTORY test_dir TO scott; Note. Data Pump is a server-based technology, so it typically deals with directory objects pointing to physical directories on the database server. It does not write to the local file system on your client PC. Table Exports/Imports The TABLES parameter is used to specify the tables that are to be exported. The following is an example of the table export and import syntax. expdp scott/tiger@db10g tables=EMP,DEPT directory=TEST_DIR dumpfile=EMP_DEPT.dmp logfile=expdpEMP_DEPT.log impdp scott/tiger@db10g tables=EMP,DEPT directory=TEST_DIR dumpfile=EMP_DEPT.dmp logfile=impdpEMP_DEPT.log For example output files see expdpEMP_DEPT.log and impdpEMP_DEPT.log. The TABLE_EXISTS_ACTION=APPEND parameter allows data to be imported into existing tables. Schema Exports/Imports The OWNER parameter of exp has b...

scheduling crontab jobs in Linux or Unix

1. Scheduling a Job For a Specific Time The basic usage of cron is to execute a job in a specific time as shown below. This will execute the Full backup shell script (full-backup) on 10th June 08:30 AM . Please note that the time field uses 24 hours format. So, for 8 AM use 8, and for 8 PM use 20. 30 08 10 06 * /home/ramesh/full-backup 30 – 30th Minute 08 – 08 AM 10 – 10th Day 06 – 6th Month (June) * – Every day of the week 2. Schedule a Job For More Than One Instance (e.g. Twice a Day) The following script take a incremental backup twice a day every day. This example executes the specified incremental backup shell script (incremental-backup) at 11:00 and 16:00 on every day. The comma separated value in a field specifies that the command needs to be executed in all the mentioned time. 00 11,16 * * * /home/ramesh/bin/incremental-backup 00 – 0th Minute (Top of the hour) 11,16 – 11 AM and 4 PM * – Every day * – Every month * – Ev...

some basic sql's for beginners in Oracle database

Oracle Database Commands and Queries: 1.To view all the table from dictionary : SQL> select table_name from dictionary; 2.To identify the database name : SQL> select name from v$database; 3.To identify the instance name : SQL> select instance from v$thread; 4.To know the size of the database blocks SQL> select value from v$parameter where name =’db_block_size’; 5.List the name of the data files : SQL> select name from v$datafile; 6.Identify the datafile that makes up the system tablespace : SQL> select file_name from dba_data_files where tablespace_name = ‘SYSTEM’; 7.To check how much free space is available in database and how much is used: SQL>select sum(bytes)/1024 “free space in KB” from dba_free_space; SQL>select sum(bytes)/1024 “used space in KB” from dba_segments”; 8.List the name and creation date of database users : SQL>select username, created from dba_users; 9.Where is the existing Control file located and what is the name? SQL> select * from v$...

script to drop all objects in your schema

This script can be used to drop all the objects in your schema,very useful when you want a fresh schema and start from scratch.no need to delete objects individually or recreate user. ----------------------------------------------------------------------------- -----    plsql script to drop all the objects in your -----      current schema -------------------------------------------------------------- declare v_str1 varchar2(200) := null; cursor get_sql is select 'drop '||object_type||' '|| object_name|| DECODE(OBJECT_TYPE,'TABLE',' CASCADE CONSTRAINTS PURGE') v_str1 from user_objects where object_type in ('TABLE','VIEW','PACKAGE','TYPE','PROCEDURE','FUNCTION','TRIGGER','SEQUENCE','SYNONYM') order by object_type,object_name; begin open get_sql; loop fetch get_sql into v_str1; if get_sql%notfound then exit; end if; execute immediate v_str1; end loop; close get_sql; end; /

Some very usefull sql's for Datagaurd

Backup - DataGuard Startup commands To remove a delay from a standby Cancel managed recovery Register a missing log file If FAL doesn't work and it says the log is already registered Check which logs are missing Disable/Enable archive log destinations Turn on fal tracing on the primary db Stop the Data Guard broker Show the current instance role Logical standby apply stop/start See how up to date a physical standby is Display info about all log destinations Display log destinations options List any standby redo logs Startup commands  startup nomount alter database mount standby database; alter database recover managed standby database disconnect; To remove a delay from a standby  alter database recover managed standby database cancel; alter database recover managed standby database nodelay disconnect; SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE   DISCONNECT FROM SESSION; Cancel managed recovery  alter database recover managed standby database cancel; Regi...

disable password verify function in oracle

Password verify function can be disabled by setting it to null. To make the password more complex most DBA's set the complexity to  oracle provided package.As default password complexity provided in oracle script doesn't satisfy your organizations requirements. SOLUTION: alter profile default limit password_verify_function null; To Enable it back : alter profile default limit password_verify_function your-password-verify-function-name ; Similar Posts : http://arvindasdba.blogspot.com/2016/07/configure-complex-password-password.html http://arvindasdba.blogspot.com/2012/10/create-orapwd-oracle-password-file.html http://arvindasdba.blogspot.com/2013/08/oracle-password-verification-function.html

disable password verify function in oracle

Password verify function can be disabled by setting it to null. To make the password more complex most DBA's set the complexity to  oracle provided package.As default password complexity provided in oracle script doesn't satisfy your organizations requirements. SOLUTION: alter profile default limit password_verify_function null; To Enable it back : alter profile default limit password_verify_function your-password-verify-function-name ;

Failed to shutdown DBConsole Gracefully

Environment: Oracle: Oracle 10g Release 2  10.2.0.5 OS: Linux Summary: Fix Oracle EM problem:Failed to shutdown DBConsole Gracefully Today on a Linux Oracle machine without Oracle Enterprise Manger, I would like to install Oracle EM. Use command emca -config dbcontrol db -repos create It reports an error - An instance of Oracle Enterprise Manager 10g Database Control is already running. It is strange that I have never create or start an EM process. So I try to stop the existing EM process SQL>  emctl stop dbconsole Oracle Enterprise Manager 10g Database Control Release 10.2.0.5.0 Copyright (c) 1996, 2006 Oracle Corporation.  All rights reserved. http://oracletest:1158/em/console/aboutApplication Stopping Oracle Enterprise Manager 10g Database Control … — Failed to shutdown DBConsole Gracefully — failed. It fails, and also fails when I want to start EM SQL>  emctl start dbconsole Oracle Enterprise Manager 10g Database Control Release 10.2.0.5.0 Copyright (c) 199...