You are on page 1of 12

Oracle net configuration assistance

Listener configuration file is located in: C:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN


of my system
In sql*plus> type host, change the directory (cd) to
C:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN
Type: dir.
Type:lsnrctl to describe the configuration file of the listener
Note: you can have one or more listener each with its name and ort number
Note:you can password your listener to prevent people from starting and stopping the listener by
using the code:
Lsnrctl>change_password
Old password. If no password at first leave it blank
New password:ayua
Reenter New password:ayua
Lsnrctl>set password
Password:ayua
Save_config
Inside : C:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN >more listener.ora
This display all listener configuration settings.
Note: if u want to add some configuration
To run listener configuration using GUI
Type host then netca
And follow all the steps in the GUI

Using NETCA to configure naming method (tns)


Select naming method
Select local naming and easy connect naming
After it has created , display the sqlnet.ora file in sqlplus by
C:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN > type sqlnet.ora
To connect using easy connect naming
Sqlplus scott/tiger@oracle/localhost:port number(1521)/database name(orcl)
Using local naming
Open the tnsnames.ora by
C:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN >notepade tnsnames.ora
Change the orcl to test(any name)
Save from the file in notepade
In C:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN > tnsping test
You can configure this using GUI
C:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN >netca
Select local net service name conjuration
Service name: database name(orcl)
Tcp
Host name: localhost
Select: yes perform test
Click on change password
Enter system privileges password
Net service name : any name of your choice(sam)

How to use Sql*plus


You can run this in command prompt or in sqlplus from oracle database software install.
Using cmd:
Start cmd prompt :type sqlplus or sqlplus sys as sydba
If you forget which sid you log into then
Sql> define
You can also connect another user in same sqlplus open without login out the other user by:
Conn sys as sysdba. Or conn hr/hr etc

To view tables in user:


Select table_name from user_tables;
Hence u can choose one table to describe and view all columns
To change date format in your select statement
Alter session set nls_date_format =mm/dd/yyyy or any format of your choice.
To format a column with numbers datatype
Col column_name format $999,999.00
To change column name heading temporary while run queries
Col old_column_name heading new_column_name
Eg,col lastn heading staff |last name
Note: | take last name on a new line
You can also change the heading line to any symbol of our choice as :
Set underline =
To enlarge the column size in a query
Col column_name format a20
To remove or clear all the format :
Col column_name clear
Or clear columns; to clear all format on a column but not date format
To write queries and save in a file:
Save file_name.sql. eg save all_emp_table.sql;
To execute the file
Sql>@file_name eg. @all_emp_table
Note: you can also specified the path you want to save our file
Save c:\app\all_emp_table.sql
To execute sql> @c:\app\all_emp_table
To keep copy of your transaction and display it both in the file and sqlplus:
Spool output.txt
To end/stop keeping spooling : spool off;
To display the result from the spool file
Enter: type output.txt
To add or append output to existing file
Spool output.txt append; and then turn spool off
C:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN > type output.txt
To set page size of the sql*plus larger
Set pagesize 200;

To set pause on, in order to paginate and delay the output display
Set pause on;
To fined sql *plus command
Sql>help index
To fine help on each command :
Sql>help command name eg help define; etc.
To change password for a user:
Sql>Passw
To see the datafile we have in a database
Select file_name bytes/1024/1024 MB from dba_data_files;
Note: byte/1024/1024 is to convert the number to mb
To fined where logfile is:
Select member , status, group# from v$logfile;
Note:redo logfile is use for recovery
To view the logs:
Select group#, sequence#, bytes, archived, status from v$log;
To add more logs into a disk group:
Alter database add logfile member C:\app\oracle\oradata\orcl\redo01b.log to group 1;
Note:u can only change the group and redo number for each.
To make oracle see the group and the logs created:
Sql>Alter system switch logfile;
Note:this will be run depending on the number of groups created.
To drop logfile
Alter database Drop logfile group number(eg 1 or 2 etc)
TO fine trace file:
Show parameter background_dump_dest
This directory: C:\app\oracle\diag\rdbms\orcl\orcl\trace

Physical structure extension


Datafile, undo file .dbf
Control file .ctl
Trace file .trc
Redo log ,alert log .log

To view control file


Select name from v$controlfile;
Note:when the control file has problem users cant login again till the error is rectified.
To startup oracle database In an restricted mod:
Sql>startup restrict;
Only sysdba can login
To see whether the login is in a restricted mod:
Sql>Select logins from v$instance;
To remove the restriction:
Sql>Alter system disable restricted session;

EXPORT AND IMPORT OF DATA


EXPORT:
To get help about the export
C:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN > exp help = y
To grant import privileges
Grant exp_full_database to scot
Start export
exp user@DB FULL=Y FILE=PATH_TO_DUMPFILE
or
C:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN >exp
Username: sys as sysdba
Password: ayua
Hit enter for all this below
Enter array fetch buffer size: 4096 >
Export file: EXPDAT.DMP >
(1)E(ntire database), (2)U(sers), or (3)T(ables): (2)U > choose either 1 or 2 or 3 and enter
Export grants (yes/no): yes >
Export table data (yes/no): yes >
Compress extents (yes/no): yes >

To export user table :


C:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN >exp scott tables = person, cities log =
result.txt grants = n

To view our export result:


C:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN > type result.txt
To import data:
To get help about the import
C:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN >imp help =y
To grant import privileges
Grant imp_full_database to scot
THE START THE INPORT AS
Sql> C:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN > imp
Enter the username and the password. And follow the steps to that popup to import.
Creating a directory:
Create directory dp as C:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN
To grant users privileges to user in order to access it:
Grant read, write on directory dp to public;
Grant exp_full_database to scott;
Hence scott can performed full export as
Expdp scott/tiger full =y dumfile = dp :full%u.dmp logfile = dp: full.log job_name =full_export;
Database startup and shutdown
Startup restrict
Select logins from v$instance;
Alter system disable restricted session;
Suspend a database:
Alter system suspend
Select database_status from v$instance
Alter system resume;
Spfile
Show parameter spfile;
Create pfile from spfile;
To see all the object a user has
Select object_name, object_type from dba_objects where owner = HR;

Backup of database
Backup Script
The provided backup script performs online backups of a database that is in ARCHIVELOG mode
and offline backups of a database that is in NOARCHIVELOG mode. Online backups are backups
that can run while the database is running. Offline backups are backups that run when the database is
in the mounted (but not open) state. For offline backups, the backup script automatically puts the
database in the proper state. During offline backups, the database is unavailable to your applications.
You run the backup script by running the Backup Database command from the desktop.

Restore Script

The provided restore script restores the database differently depending on whether log archiving is on
or off:

Log archiving on (ARCHIVELOG mode)The restore script restores the backed up


database files, and then uses the online and archived redo log files to recover the database to
the state it was in before the software or media failure occurred. All committed transactions
that took place after the last backup are recovered, and any uncommitted transactions that
were under way when the failure took place are rolled back (using undo data from the
restored undo tablespace).
Log archiving off (NOARCHIVELOG mode)The restore script restores the database to its
state at the last backup. Any transactions that took place after the last backup are lost.

Viewing the Current ARCHIVELOG Mode Setting

SELECT LOG_MODE FROM V$DATABASE;


TO TURN ON ARCHIVELOG MODE:
SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
ALTER DATABASE ARCHIVELOG; OR NOARCHIVELOG
ALTER DATABASE OPEN;

Change the size of the flash recovery area to at least 15 gigabytes to allow for the extra space required
for archived log files.

For example, to set the flash recovery area size to 20 gigabytes, enter the following command:

ALTER SYSTEM SET DB_RECOVERY_FILE_DEST_SIZE =20G;

Archive log list;


Show parameter log_archive
B4 u enable or disable archive, we need to shut down the database
Shutdown immediate;
Startup mount;
Alter database archivelog;
Alter database open;
Archive log list;
Archive destination1 are empty so u have to set the location
SQL> alter system set log_archive_dest_1='location =C:\app\nspire_oracle\product
\11.2.0\dbhome_1\admin\sample\arch'; note:make sure that no space of should be allow in the
location
Show parameter log_archive_dest_1;
To create archivelog
Alter database switch logfile;
/
/
/
Show that create 3 logfile
To view the logfile created
C:\app\nspire_oracle\product> cd C:\app\nspire_oracle\product\11.2.0\dbhome_1\adm
in\sample\arch

C:\app\nspire_oracle\product\11.2.0\dbhome_1\admin\sample\arch> dir.
So we can now use these archivelog to perform recovery if anything went wronged
To backup and create control file
alter database backup CONTROLFILE to 'C:\Users\nspire_oracle\orcl_log_02022010.trn';
or
Alter database backup controlfile to trace;
Hotbackup
To backup tablespace
Alter tablespace users begin backup;
///////////////
Alter tablespace user end backup;
Or whole database as
Alter database begin backup;
////////
Alter database end backup;
Hot backup for tablespace
Select file_name from dba_data_files where tablespace_name =USERS;
Alter tablespace users begin backup;
Copy the file to admin directory as:
Host

C:\app\nspire_oracle\product\11.2.0\dbhome_1\BIN> copy C:\APP\NSPIRE_ORACLE\ORAD


ATA\ORCL\USERS01.DBF c:\app\nspire_oracle
Exit
Alter tablespace users end backup;

Check backup file using below command.


select * from V$BACKUP;

To perform cold backup:


Select file_name from dba_data_files;
Now create a script to perform the coping for you as:
SQL> select 'cp' || file_name|| 'C:\app\nspire_oracle\product\11.2.0\dbhome_1' f
rom dba_DATA_files;
spool mybackup.bat;
/
Spool off;
Increamental backup:
Two types: deferential and cumulative

Oracle recovery manager using rman


You dont need to remember where those file are for recovery using rman.it handle all this for u
First create a database to perform the recovery as
Host;
Dbca;
Uncheck enterprise manger
Enter the password
Enable archiving
Set oracle_sid = new database created
Create user rman identified by change_me default tablespace users temporary tablespace temp;
Grant resource , connect to rman;
Alter user rman quota unlimited on users;
Grant recovery_catalog_owner to rman;
Host
Rman catalog rman@rman;
Enter username and password of user rman
RMAN> create catalog;
Quit
Exit
Select table_name from user_tables;
Select view_name from user_views;
Host
Set oracle_sid =orcl
Rman catalog rman@rman target /
Enter password of the orcl database
Register database;
Report schema;
Configuration part of rman
RMAN>show all;
RMAN>Configure retention policy redundancy 2;
RMAN>show all;
RMAN> configure retention policy to recovery window of 28 days;
RMAN> show all;
RMAN>configure controlfile autobackup on;
RMAN> show all;
Using rman command to perform administrative work:
RMAN> backup database tag=FULL_BACKUP;
Or to do incremental backup
RMAN>backup incremental level =0 database tag=SUNDAY;
RMAN>backup incremental level =1 database tag=MONDAY; ETC
TO BACKUP TABLESPACE:
RMAN> backup tablespace users tag=USERS;
RMAN>List backup summary;
Also we can backup archivelog file as:
RMAN> backup archivelog all tag=ARCHIVE_LOG;
TO CROSSCHECK BACKP FILE WHETHER IS AVALIABLE:
RMAN>crosscheck backup;
Report command: used to know which database file need backup
RMAN>report need backup;
List command tell us which backup has expired
RMAN> list expired backup;
RMAN>list archivelog all ;
Rman data view dictionary
Rc_database, rc_archived_log, rc_tablespace, rc_datafile, rc_backup_set, rc_backup_piece,
rc_backup_spfile etc

For connecting to new/other database


Conn sys@schooldb as sysdba
Password..

Monitoring users
Create user ayua identified by ayuaPassword default tablespace EXAMPLE temporary tablespace
TEMP quota 10m on EXAMPLE quota unlimited on EXAMPLE password expire account lock;
We can assign sysdba privileges to any user as
Grant sysdba to hr,scott;
Select * from V$pwfile_users;
Revoke sysdba from scott, hr;
How to fined password expiration date or limit for your account
Select * from user_password_limits; or
Select username,account_status, expiry_date from dba_users;
Alter profile default limit password_life_time unlimited; or 180 or 90; etc
Creating profile to control users work in the database
Create profile profile limit session_per_user 2
Idle_time 30
Connect_time 480
Failed_login_time 365
Password_lock_time 1/1440*5;
TO KILL A SESSION THAT IS STARTED BUT DOING NOTHING
Select sid, serial#,osuser,username,logon_time from v$session;
Alter system kill session 144,184;

Sql developer
How to create connection to the oracle database using sql developer
Click on the new connection (+) after you startup the sql developer and follow the steps

Another way to perform recovery and backup


set oracle_sie = orcl
sqlplus / as sysdba
create directory dpdir as C:\app\nspire_oracle\oradata;

You might also like