Friday, 8 March 2013

ORA-01994: GRANT failed: password file missing or disabled

I am attempting to add an entry to my orapwd file and I get this error:

SQL> grant sysdba to scott;
grant sysdba to scott
*
ERROR at line 1:
ORA-01994: GRANT failed: password file missing or disabled

Cause The operation failed either because the INIT.ORA parameter REMOTE_LOGIN_PASSWORDFILE was set to NONE or else because the password file was missing.

1) Check remote_login_passwordfile  value
SQL> show parameter REMOTE_LOGIN_PASSWORDFILE;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
remote_login_passwordfile            string      NONE


2) Change the exclusive remote_login_passwordfile  mode not to exclusive .This statics parameter
SQL> alter system set remote_login_passwordfile =exclusive scope=spfile;

System altered.
to implement the changes  you need to restart the database

SQL> shu immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup;
ORACLE instance started.

Total System Global Area  603979776 bytes
Fixed Size                  1250380 bytes
Variable Size             184552372 bytes
Database Buffers          411041792 bytes
Redo Buffers                7135232 bytes
Database mounted.
Database opened.

 
SQL> show parameter REMOTE_LOGIN_PASSWORDFILE;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
remote_login_passwordfile            string      EXCLUSIVE


now grant the sysdba privelages to user
SQL> grant sysdba to scott;

Grant succeeded.

You can caheck which user have sysdba privelages  tou can find using query

SQL> SELECT USERNAME FROM V$PWFILE_USERS WHERE USERNAME != 'SYS' AND SYSDBA='TRUE';

USERNAME
------------------------------
SCOTT

2) if  password file is missing then you need to creaet new password file using blow command
C:\Documents and Settings\vanita.sharma>orapwd FILE=C:\ORACLE\product\10.2.0\db_1\database\pwdorcl.ora password=pass ENTRIES=50 FORCE=y

DATA PUMP ARCHITECTURE AND STEPS TO PERFORME EXPORT/IMPORT USING DATAPUMP


INTRODUCTION
Oracle Data pump utility enables very fast bulk data and metadata movement between Oracle databases. It provides parallel Export and Import utilities (expdp and impdp) and Web-based Oracle Enterprise Manager Interface.Data Pump Export and Import utilities are typically much faster than the original Export and Import Utilities. A single thread of Data Pump Export is about twice as fast as original Export, while Data Pump Import is 15-45 times fast than original Import.Data Pump jobs can be restarted without loss of data, whether or not the stoppage was voluntary or involuntary.Data Pump jobs support fine-grained object selection. Virtually any type of object can be included or excluded in a Data Pump job. Data Pump supports the ability to load one instance directly from another (network import) and unload a remote instance (network export).

DATA PUMP ARCHITECTURE
Oracle Data Pump is made up of three distinct parts:
              The command-line clients, expdp and impdp
              The DBMS_DATAPUMP PL/SQL package (also known as the Data Pump API)
              The DBMS_METADATA PL/SQL package (also known as the Metadata API) 
EXPDP – Client interface to the Data Pump Export utility. The interface closely resembles its predecessor, Oracle Export.
IMPDP – Client interface to the Data Pump Import utility. The interface closely resembles its predecessor, Oracle Import.
Grid Control Interface – This is a web based interface, which provides access to the DBMS_DATA_PUMP PL/SQL package.
STEPS:
Creating Directory Objects
In order to use Data Pump, the database administrator must create a directory object and grant privileges to the user on that directory object. If a directory object is not specified, a default directory object called data_pump_dir is provided. The default Data_pump_dir is available only to privileged users unless access is granted by the DBA.
CONN / AS SYSDBA
CREATE OR REPLACE DIRECTORY test_dir AS '/u01/app/oracle/oradata/';

After a directory is created, we need to grant READ and WRITE permission on the directory to other users. For example, to allow the Oracle database to read and to write to files on behalf of user test in the directory named by test_dir, you must execute the following command:
GRANT READ, WRITE ON DIRECTORY test_dir TO test;
Once the directory is granted, we can export a user’s object with command arguments that are very similar to exp and imp:
Schema Exports/Imports
The OWNER parameter of exp has been replaced by the SCHEMAS parameter which is used to specify the schemas to be exported. The following is an example of the schema export and import syntax.
expdp test/test@tsn schemas=TEST directory=TEST_DIR dumpfile=TEST.dmp logfile=expdpTEST.log
impdp test/test@tsn schemas=TEST directory=TEST_DIR dumpfile=TEST.dmp logfile=impdpTEST.log

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 test/test@tsn tables=EMP,DEPT directory=TEST_DIR dumpfile=EMP_DEPT.dmp logfile=expdpEMP_DEPT.log
impdp test/test@tsn tables=EMP,DEPT directory=TEST_DIR dumpfile=EMP_DEPT.dmp logfile=impdpEMP_DEPT.log

TABLE_EXISTS_ACTION – The original imp would allow rows to be appended to existing tables if IGNORE=Y was specified. The TABLE_EXISTS_ACTION parameter for Data Pump impdp provides four options:
1. SKIP is the default: A table is skipped if it already exists.
2. APPEND will append rows if the target table’s geometry is compatible.
3. TRUNCATE will truncate the table, then load rows from the source if the geometries     are compatible and truncation is possible. For example, it is not possible to truncate a table if it is the target of referential constraints.
4. REPLACE will drop the existing table, then create and load it from the source.
INCLUDE and EXCLUDE
The INCLUDE and EXCLUDE parameters can be used to limit the export/import to specific objects. When the INCLUDE parameter is used, only those objects specified by it will be included in the export/import. When the EXCLUDE parameter is used, all objects except those specified by it will be included in the export/import. The two parameters are mutually exclusive, so use the parameter that requires the least entries to give you the result you require. The basic syntax for both parameters is the same. 
expdp test/test@tsn schemas=TEST include=TABLE:"IN ('EMP', 'DEPT')" directory=TEST_DIR dumpfile=TEST.dmp logfile=expdpTEST.log
expdp test/test@tsn schemas=TEST exclude=TABLE:"= 'BONUS'" directory=TEST_DIR dumpfile=TEST.dmp
logfile=expdpTEST.log
Other filters
INCLUDE=VIEW
INCLUDE=PACKAGE:"LIKE '%API'"

Network Exports/Imports (NETWORK_LINK)
The NETWORK_LINK parameter identifies a database link to be used as the source for a network export/import. The following database link will be used to demonstrate its use.
1)             Create database link
CONN test/test
CREATE DATABASE LINK remote_test CONNECT TO test IDENTIFIED BY test USING 'TEST';
2)             Export data using database link
expdp test/test@tsn tables=TEST.EMP network_link=REMOTE_TEST directory=TEST_DIR dumpfile=EMP.dmp logfile=expdpEMP.log
3)               Import data using database link
impdp test/test@tsn tables=TEST.EMP network_link=REMOTE_TEST directory=TEST_DIR logfile=impdpTEST.log remap_schema=TEST:TEST_NEW
We can Imports the objects directly from the source into the local server without being written to a dump file.
Attaching to and Stopping an Existing Job
The ATTACH command attaches the client session to an existing export job and  automatically places you in the interactive-command interface. Export displays a description of the job to which you are attached and also displays the export prompt. A
job name does not have to be specified if there is only one export job that is associated with your schema. The job you attach to can be either currently executing or stopped
Attach /Detach job in case of Export:-
A)            You have  started the export job
expdp mm_stg/mm_stg dumpfile=DPUMP:export.dmp logfile= DPUMP:export.log schemas=mm_stg job_name=SYS_EXPORT_SCHEMA
B)            If you want to pause the job for some time then press CTL+C , type the command given below
Export> STOP_JOB=IMMEDIATE
Are you sure you wish to stop this job ([yes]/no): yes
C)             Now you want to restart the job then you need to attach the job
         $ expdp mm_stg/mm_stg attach=SYS_EXPORT_SCHEMA
          Export> START_JOB
          Export> STATUS=600
          Export> CONTINUE_CLIENT

Attach /Detach job in case of Import:-
A)            You have  started the import job
impdp system/sys dumpfile=DPUMP:export3.dmp logfile=DPUMP:export2.log job_name=OEM_NEW_USER_job1
B)            If you want to pause the job for some time then press CTL+C , type the command given below
Export> STOP_JOB=IMMEDIATE
Are you sure you wish to stop this job ([yes]/no): yes
C)             Now you want to restart the job then you need to attach the job
impdp system/sys dumpfile=DPUMP:export3.dmp logfile=DPUMP:export2.log   attach=OEM_NEW_USER_job1
Export> START_JOB
          Export> STATUS=600
          Export> CONTINUE_CLIENT
Job Monitor
i.e  Typing "status" at this prompt allows you to monitor the current job.
Export> status

Job: OEM_NEW_USER_JOB1
  Operation: IMPORT
  Mode: FULL
  State: EXECUTING
  Bytes Processed: 535,134,568
  Percent Done: 99
  Current Parallelism: 1
  Job Error Count: 0
  Dump File: /home/oracle/dpump/export3.dmp

Worker 1 Status:
  State: EXECUTING
  Object Type: SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
  Total Objects: 70
  Worker Parallelism: 1
Processing object type SCHEMA_EXPORT/MATERIALIZED_VIEW

EXPDP/IMPDP FEATURES



1) Oracle Data Pump export/imports is 20 to 40 times faster  (I have tested on test server) as compare to  exp/imp, even with parallelism set to 1, because of Oracle Data Pump's use of direct path (when possible).

2)  The INCLUDE and EXCLUDE parameters can be used to limit the export/import to specific objects. i.e  if we have  taken export backup on schema level and  at the time of import  we want to exclude specific table we simply need to specify the table name which we want to exclude from import list.
Imp  test/test schemas=test exclude=TABLE:"= 'TABLE_NAME'" directory=TEST_DIR dumpfile=esport_data.dmp logfile=expdptest.log
We  can Include index ,constraints ,query instead the INDEX=y,n or constraints=y,n in old exp/imp

3) Using  NETWORK_LINK parameter  we can exp/imp over the database link. i.e Imports the objects
are directly from the source into the local server without being written to a dump file.
impdp test/test@test tables=table_name  network_link=REMOTE_TEST directory=TEST_DIR logfile=impdptest.log remap_schema=Test:TEST_new                                                  
In above example emp table of test schema  exists on remote server directly imported on local server test_new  schema

4) Datapump have ability to write in many dump files simultaneously using parallel parameter.

5) Estimate parameters helps you estimate the size of export without taking export. It will help you create the required space or take backup on the disk having sufficient space , reduce the probability of exp fails due to lack space

6) Remapping capabilities of datapump you can remap user ,tablespaces , make it easy to transfer data from one tablespace to other tablespaces.
             impdp system\password@tnsname directory=data_pump_dir dumpfile=mydump01.dmp                         remap_schema=source_schema:dest_schema remap_tablespace=source_tablespace:dest_tablespace

7) In the expdp dump file always create on the server even if you taking the export from client dump file will creates on the server, it improves performance and no need to data transfer using network.

8)  Datapump have ability to restart job that have fails due to lack of space or due to other reasons

9)   The ability to detach from and reattach to long-running jobs without affecting the job itself. This allows DBAs and other operations personnel to monitor jobs from multiple locations. In exp if export/import is fails then you have to perform it again but expdp we don't need to bother about it .Because here you can attach or detach the job .
Steps :
A)
expdp mm_stg/mm_stg dumpfile=DPUMP:export.dmp logfile= DPUMP:export.log schemas=mm_stg job_name=SYS_EXPORT_SCHEMA
B) If you want to pause the job for some time then press CTL+C , type the command given below
Export> STOP_JOB=IMMEDIATEAre you sure you wish to stop this job ([yes]/no): yes
C)  Now you want to restart the job then you need to attach the job
         $ expdp mm_stg/mm_stg attach=SYS_EXPORT_SCHEMA
          Export> START_JOB
          Export> STATUS=600
          Export> CONTINUE_CLIENT
10) It has its own performance tuning features

11) It supports interactive mode that allows the dba to monitor or interact with ongoing jobs

12)  The Data Pump method for moving data between different database versions is different from the method used by original Export and Import. With original Export, you had to run  an older version of Export to produce a dump file that was compatible with an older database version. With Data Pump, you use the current Export version and simply use  the VERSION parameter to specify the target database version. You cannot specify  versions earlier than Oracle Database 10g (since Data Pump did not exist before 10g).
Example:
> expdp username/password TABLES=test.emp VERSION=10.1 dumpfile=DPUMP:export.dmp logfile= DPUMP:export.log

CONCLUSIONOracle Data Pump is a great tool for the fast movement of data between the databases and much of this performance improvement is derived from the use of parameter “parallelism.”  New export and import clients, expdp and impdp, that fully exploit the Data Pump Infrastructure. They are implemented as complete supersets of the original exp and imp, and will eventually replace them.


Thursday, 7 March 2013

TNS-12555 / TNS-12560 / TNS-00525 Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))

Few days back  got an issue when tried to start the listener

TNSLSNR for Linux: Version 10.2.0.2.0 – Production
System parameter file is /u01/app/oracle/oracle/product/10.2.0/db_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/oracle/product/10.2.0/db_1/network/log/listener.log
Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
TNS-12555: TNS:permission denied
TNS-12560: TNS:protocol adapter error
TNS-00525: Insufficient privilege for operation
Linux Error: 1: Operation not permitted
  
Causes

1) Ensure that /tmp/.oracle or /var/tmp/.oracle directory exists.
 2) If the /tmp directory has reached full capacity, this would cause the listener to fail to write the socket files.

when i exprore found below directories exists/var/tmp/.oracle  but still got error
then  recreated /var/tmp/.oracle directory using below steps

cd /var/tmp/
ls -lrtha
cp .oracle .oracleback
mkdir .oracle
chmod 01777 .oracle
chown root  .oracle
chgrp root  .oracle

Start the listener and it started successfully J J

TNS - 01190:the user is not authorized to execute the requested listener command




Few days back some os level issue on oracle server machine when we try to restart the listener we get below error
TNS - 01190:the user is not authorized to execute the requested listener command
checked  the services status of service using command

ps -ef | grep -i listener
output
 1091  78960       1   0   nov 20      -  0:33 /home/oracle/db_1/bin/tnslsnr LISTENER -inherit

Find the owner of listener service are changed or null

Above TNS - 01190 comes when we try to restart the listener which is running from different owner

then  tried to kill the services using os kill command but
it shows insufficient privileges .
Then i told my system administrator to kill the services from root user using

kill -9 78960

Now i started the listener from oracle user and it stated successfully.

lsnrctl start

Monday, 4 March 2013

How to install unixODBC on linux system


How to install unixODBC  on linux system

Open DataBase Connectivity (ODBC) is a cross-platform, call-level interface that allows applications to access data in any database for which there is an ODBC driver. Using ODBC, you can create database applications with access to any database for which your end-user has an ODBC driver. ODBC provides an API that allows your application to be independent of the source database management system (DBMS). This enables for software developers to write open database programs without the need of a proprietary interface
 1) download software
2) untart the files

gunzip  unixODBC-2.3.1.tar.gz
tar xvf unixODBC-2.3.1.tar
cd unixODBC-2.3.1

3) to install the unixodbc run below command

./configure  --libdir=/usr/lib64 --sysconfdir=/etc --enable-gui=no --enable-drivers=yes --enable-drivers-conf=yes
Make
make install
 

--enable-drivers: This parameter enables building the drivers that were installed by default in previous versions.

--enable-drivers-conf: This parameter enables building the driver configuration libraries that were installed by default in previous versions.
4) verify  the  installtion

]# odbcinst -j
unixODBC 2.3.1
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /etc/odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

5) Specify the Driver location in odbcinst.ini file


vi   /etc/odbcinst.ini

[PostgreSQL]
Description     = ODBC for PostgreSQL
Driver          = /usr/pgsql-9.1/lib/psqlodbcw.so
Setup           = /usr/lib64/libodbcpsqlS.so.1.0.0
FileUsage       = 1

6) Set  database connection information in odbc.ini file and specified the driver which you have mentioned in odbcinst.ini file

vi : /etc/odbc.ini

[MYDATA]
Driver                = PostgreSQL
Description           = PostgreSQL ODBC
Servername            = xyz
Port                  = 5432
Database              = mydb
Username              = myuser
Password              = pass
ReadOnly              = false
ShowSystemTables      = false
LegacySQLTables       = false
LoginTimeout          = 0
QueryTimeout          = 0
DateFormat            = 1
NumericAsChar         = false
SQLBitOneZero         = false
StripCRLF             = false
securityLevel         = preferredUnSecured
caCertFile            =


[ODBC]
IANAAppCodePage=4
InstallDir=/opt/odbc32v51
Trace=0
TraceDll=/opt/odbc32v51/lib/odbctrac.so
TraceFile=odbctrace.out
UseCursorLib=0

7) Export the environment variable

]#  export ODBCSYSINI=/etc
]# export ODBCINI=/etc/odbc.ini

8) test connection

]#  isql -v  MYDATA
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+

# query system dsn's

]#odbcinst -q -s
[MAYADATA]

Dltest -> is a utility used to check a share library to see if it can be loaded and if a given symbol exists in it.
Isqlà is an utility which can be used to submit SQL to a data source and to format/output results. It can be used in batch or interactive mode.
Iusql -> provides the same functionality as the isql program.
odbc_config -> is used to find out details about the installation of the unixODBC package.
Odbcinst->is an utility created for install script/RPM writers. It is a command line interface to key functionality in the libodbcin