What is a database?- Database offer a single point of mechanism for storing and retrieving information with the help of tables. - Table is made up of columns and rows where each column stores specific attribute and each row displays a value for the corresponding attribute. - It is a structure that stores information about the attributes of the entities and relationships among them. - It also stores data types for attributes and indexes. - Well known DBMS include Oracle, ibm db2, Microsoft sql server, Microsoft access, mysql and sqlLite.
|
What are the different types of storage systems available and which one is used by Oracle?Two types of storage systems are available - Relational Database Management System (RDBMS) and Hierarchical Storage Management System (HSM)
- Most databases use RDBMS model, Oracle also uses RDBMS model. - Hierarchical Storage Management System (HSM) - Information Management System (IMS) from IBM. - Integrated Database Management System (IDMS) from CA.
|
Explain some examples of join methods.Join methods are of mainly 3 types.
Merge Join - - Sorting both the tables using join key and then merge the rows which are sorted.
Nested loop join - - It gets a result set after applying filter conditions based on the outer table. - Then it joins the inner table with the respective result set.
Hash join - - It uses hash algorithm first on smaller table and then on the other table to produce joined columns. After that matching rows are returned.
|
What are the components of logical data model and list some differences between logical and physical data model?Components of logical data model are
Entity - Entity refers to an object that we use to store information. It has its own table.
Attribute - It represents the information of the entity that we are interested in. It is stored as a column of the table and has specific datatype associated with it.
Record - It refers to a collection of all the properties associated with an entity for one specific condition, represented as row in a table.
Domain - It is the set of all the possible values for a particular attribute.
Relation - Represents a relation between two entities.
Difference between Logical and Physical data model.
- Logical data model represents database in terms of logical objects, such as entities and relationships.
- Physical data model represents database in terms of physical objects, such as tables and constraints.
|
What is normalization? What are the different forms of normalization?- Normalization is a process of organizing the fields and tables of a relational database to minimize redundancy and dependency. - It saves storage space and ensures consistency of our data.
There are six different normal forms
First Normal Form - If all underlying domains contain atomic values only.
Second Normal Form - If it is in first normal form and every non key attribute is fully functionally dependent on primary key.
Third Normal Form - If it is in 2nd normal form and every non key attribute is non transitively dependent on the primary key.
Boyce Codd Normal Form - A relation R is in BCNF if and only every determinant is a candidate key.
Fourth Normal Form
Fifth Normal Form
|
Differentiate between a database and Instance and explain relation between them?- Database is a collection of three important files which include data files, control files and redo log files which physically exist on a disk
- Whereas instance is a combination of oracle background process (SMON, PMON, DBWR, LGWR) and memory structure (SGA, PGA).
- Oracle background processes running on a computer share same memory area.
- An instance can mount and open only a single database, ever.
- A database may be mounted and opened by one or more instances (using RAC).
|
What are the components of SGA?- SGA is used to store shared information across all database users. - It mainly includes Library cache, Data Dictionary cache, Database Buffer Cache, Redo log Buffer cache, Shared Pool.
Library cache - It is used to store Oracle statements.
Data Dictionary Cache - It contains the definition of Database objects and privileges granted to users.
Data Base buffer cache - It holds copies of data blocks which are frequently accessed, so that they can be retrieved faster for any future requests.
Redo log buffer cache - It records all changes made to the data files.
|
Difference between SGA and PGA.- SGA (System Global Area) is a memory area allocated during an instance start up. - SGA is allocated as 40% of RAM size by default. - SGA size is controlled by DB_CACHE_SIZE parameter defined in initialization parameter file (init.ora file or SPFILE).
- PGA (Program or Process Global Area) is a memory area that stores a user session specific information. - PGA is allocated as 10% of RAM size by default.
|
What are the disk components in Oracle?These are the physical components which gets stored in the disk.
- Data files - Redo Log files - Control files - Password files - Parameter files
|
What is System Change Number (SCN)?- SCN is a unique ID that Oracle generates for every committed transaction. - It is recorded for every change in the redo entry. - SCN is also generated for every checkpoint (CKPT) occurred. - It is an ever increasing number which is updated for every 3 seconds - You can get the SCN number by querying select SCN from v$database from SQLPLUS.
|
What is Database Writer (DBWR) and when does DBWR write to the data file?- DBWR is a background process that writes data blocks information from Database buffer cache to data files.
There are 4 important situations when DBWR writes to data file
- Every 3 seconds - Whenever checkpoint occurs - When server process needs free space in database buffer cache to read new blocks. - Whenever number of changed blocks reaches a maximum value.
|
What is Log Writer and when does LGWR writes to log file?- LGWR writes redo or changed information from redo log buffer cache to redo log files in database. - It is responsible for moving redo buffer information to online redo log files, when you commit and a log switch also occurs. - LGWR writes to redo files when the redo log buffer is 1/3 rd full. - It also writes for every 3 seconds. - Before DBWR writes modified blocks to the datafiles, LGWR writes to the log file
|
Which Table spaces are created automatically when you create a database?- SYSTEM tablespace is created automatically during database creation. - It will be always online when the database is open.
Other Tablespaces include
- SYSAUX tablespace - UNDO tablespace - TEMP tablespace - UNDO & TEMP tablespace are optional when you create a database.
|
Which file is accessed first when Oracle database is started and What is the difference between SPFILE and PFILE?- Init<SID>.ora parameter file or SPFILE is accessed first .( SID is instance name) - Settings required for starting a database are stored as parameters in this file. - SPFILE is by default created during database creation whereas PFILE should be created from SPFILE. - PFILE is client side text file whereas SPFILE is server side binary file. - SPFILE is a binary file (it can’t be opened) whereas PFILE is a text file we can edit it and set parameter values. - Changes made in SPFILE are dynamically effected with running database whereas PFILE changes are effected after bouncing the database. - We can backup SPFILE using RMAN.
|
What are advantages of using SPFILE over PFILE?- SPFILE is available from Oracle 9i and above. - Parameters in SPFILE are changed dynamically. - You can’t make any changes to PFILE when the database is up. - RMAN cant backup PFILE, It can backup SPFILE. - SPFILE parameters changes are checked before they are accepted as it is maintained by Oracle server thereby reducing the human typo errors.
|
How can you find out if the database is using PFILE or SPFILE?- You can query Dynamic performance view (v$parameter) to know your database is using PFILE or SPFILE. - SQL> select value from V$parameter where name= ‘SPFILE’; - A non-null value indicates the database is using SPFILE. - Null value indicates database is using PFILE. - You can force a database to use a PFILE by issuing a startup command as - SQL> startup PFILE = ‘full path of Pfile location’;
|
Where are parameter files stored and how can you start a database using a specific parameter file?- In UNIX they are stored in the location $ORACLE_HOME/dbs and ORACLE_HOME/database for Windows directory.
- Oracle by default starts with SPFILE located in $ORACLE_HOME/dbs.
- If you want to start the database with specific file we can append it at the startup command as SQL > startup PFILE = ‘full path of parameter file ‘;
- You can create PFILE from SPFILE as create PFILE from SPFILE;
- All the parameter values are now updated with SPFILE.
- Similarly, create SPFILE from PFILE; command creates SPFILE from PFILE.
|
What is PGA_AGGREGATE_TARGET parameter?- PGA_AGGREGATE TARGET parameter specifies target aggregate PGA memory available to all server process attached to an instance. - Oracle sets its value to 20% of SGA. - It is used to set overall size of work-area required by various components. - Its value can be known by querying v$pgastat dynamic performance view. - From sqlplus it can be known by using SQL> show parameter pga.
|
What is the purpose of configuring more than one Database Writer Processes? How many should be used? (On UNIX)- DBWn process writes modified buffers in Database Buffer Cache to data files, so that user process can always find free buffers.
- To efficiently free the buffer cache to make it available to user processes, you can use multiple DBWn processes.
- We can configure additional processes (DBW1 through DBW9 and DBWa through DBWj) to improve write performance if our system modifies data heavily.
- The initialization parameter DB_WRITER_PROCESSES specifies the number of DBWn processes upto a maximum number of 20.
- If the Unix system being used is capable of asynchronous input/output processing then only one DBWn process is enough, if not the case the total DBWn processes required will be twice the number of disks used by oracle, and this can be set with DB_WRITER_PROCESSES initialization parameter.
|
List out the major installation steps of oracle software on UNIX in brief?- Set up disk and make sure you have Installation file (run Installer) in your dump.
- Check the swap and TEMP space .
- Export the following environment variables 1. ORACLE_BASE 2. ORACLE_HOME 3. PATH 4. LD_LIBRARY_PATH 5. TNS_ADMIN
- Set up the kernel parameters and file maximum descriptors.
- Source the Environment file to the respective bash profile and now run Oracle Universal Installer.
|
Can we check number of instances running on Oracle server and how to set kernel parameters in Linux?- Editing the /etc/oratab file on a server gives the list of oracle instances running on your server.
- Editing /etc/sysctl.conf file with vi editor will open a text file listing out kernel level parameters.
- We can make changes to kernel parameters as required for our environment only as a root user. - To make the changes affected permanently to kernel run the command /sbin/sysctl –p. - We must also set file maximum descriptors during oracle installation which can be done by editing /etc/security/limits.conf as a root user.
|
What is System Activity Reporter (SAR) and SHMMAX?- SAR is a utility to display resource usage on the UNIX system. - sar –u shows CPU activity. - Sar –w shows swapping activity - Sar –b shows buffer activity - SHMMAX is the maximum size of a shared memory segment on a Linux system.
|
List out some major environment variable used in installation?- ORACLE_BASE=/u01/app/<installation-directory> - ORACLE_HOME=$ORACLE_BASE/product/11.2.0(for 11g)/dbhome_1 - ORACLE_SID=<instance-name> - PATH=$ORACLE_HOME/bin:$PATH - LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH - TNS_ADMIN=$ORACLE_HOME/network/admin - These are absolutely critical environment variables in running OUI.
|
What is a control file?- Control file is a binary file which records the physical structure of a database. - It includes number of log files and their respective location, Database name and timestamp when database is created, checkpoint information. - We find CONTROL_FILE parameter in initialization parameter file which stores information about control file location. - We can multiplex control files, store in different locations to make control files available even if one is corrupted. - We can also avoid the risk of single point of failure.
|
At what stage of instance, control file information is read and can we recover control file and how to know information in a control file?- During database mounting, control file information is read. - We can’t recover or restore lost control file, but we can still startup the database using control files created using multiplexing in different locations. - We can query the following command SQL> alter database backup controlfile to trace; - We find a trace file(.trc) in udump location,we can edit it and find the complete database structure. - Multiplexing can also be done using Following command SQL> alter database backup controlfile to <Different location/path>.
|
How can you obtain Information about control file?- Control file information can be shown in initialization parameter file. - We can query v$controlfile to display the names of control files - From sql we can execute SQL> show parameter control_files; - The above query gives the name, Location of control files in our physical disk. - We can edit PFILE using a vi editor and control_files parameter gives us information about number of and location of control files.
|
How do you resize a data file and tablespace?- Prior to Oracle 7.2 you can’t resize a datafile. - The solution was to delete the tablespace, recreating it with different sized datafiles. - After 7.2 you can resize a datafile by using ALTER DATABASE DATAFILE <file_name> RESIZE; - Resizing Table space includes creation of new data file or resizing existing data file. - ALTER TABLESPACE <tablespacename> ADD DATAFILE ‘<datafile name> ‘ size M; creates a new datafile.
|
Name the views used to look at the size of a datafile, controlfiles, block size, determine free space in a tablespace ?- DBA_DATA_FILES or v$datafile view can be used to look at the size of a datafile . - DBA_FREE_SPACE is used to determine free space in a tablespace. - V$contolfile used to look at the size of a control file which includes maxlogfiles, maxlogmembers, maxinstances. - Select * from v$controlfile gives the size of a controlfile. - From sqlplus, query show parameter block_size to get size of db_block_size.
|
What is archive log file?In archive log mode, the database will makes archive of all redo log files that are filled, called as archived redo logs or archive log files.
- By default your database runs in NO ARCHIVE LOG mode, so we can’t perform online backup’s (HOT backup). - You must shut down database to perform clean backup (COLD backup) and recovery can be done to the previous backup state. - Archive log files are stored in a default location called FRA (Flash Recovery Area). - We can also define our own backup location by setting log_archive_dest parameter.
|
Assume you work in an xyz company as senior DBA and on your absence your back up DBA has corrupted all the control files while working with the ALTER DATABASE BACKUP CONTROLFILE command. What do you do?- As long as all data files are safe and on a successful completion of BACKUP control file command by your Back up DBA you are in safe zone. - We can restore the control file by performing following commands 1. CONNECT INTERNAL STARTUP MOUNT 2. TAKE ANY OFFLINE TABLESPACE (Read-only) 3. ALTER DATABASE DATAFILE (OFFLINE) 4. RECOVER DATABASE USING BACKUP CONTROL FILE 5. ALTER DATABASE OPEN RESETLOGS 6. BRING READ ONLY TABLE SPACE BACK ONLINE
Shutdown and back up the system. Then restart.
- Then give the command ALTER DATABSE BACKUP CONTROL FILE TO TRACE - This output can be used for control file recovery as well.
If control file backup is not available, then the following will be required
1) CONNECT INTERNAL STARTUP NOMOUNT 2) CREATE CONTROL FILE .....;
- But we need to know all of the datafiles, logfiles, and settings of MAXLOGFILES, MAXLOGMEMBERS, MAXLOGHISTORY, MAXDATAFILES for the database to use the command.
|
Can we reduce the space of TEMP datafile? How?- Yes, we can reduce the space of the TEMP datafile.
- Prior to oracle 11g,,you had to recreate the datafile.
- In oracle 11g you reduce space of TEMP datafile by shrinking the TEMP tablespace.It is a new feature to 11g.
- The dynamic performance view can be very useful in determining which table space to shrink.
|
What do you mean by database backup and which files must be backed up?- Database stores most crucial data of business ,so it’s important to keep the data safe and this can be achieved by backup.
The following files must be backed up
- Database files (Header of datafiles is freezed during backup) - Control files - Archived log files - Parameter files (spfile and pfile) - Password file
|
What is a full backup and name some tools you use for full backup?- A full backup is a backup of all the control files, data files, and parameter file (SPFILE or PFILE). - You must also backup your ORACLE_HOME binaries which are used for cloning. - A full backup can be performed when our database runs in NON ARCHIVE LOG mode. - As a thumb rule, you must shutdown your database before you perform full backup. - Full or COLD backup can be performed by using copy command in unix.
|
What are the different types of backup’s available and also explain the difference between them?There are 2 types of backup’s
1. COLD backup(User managed & RMAN) 2. HOT backup(User managed & RMAN)
- Hot backup is taken when the database is still online and database should be in ARCHIVE LOG MODE. - Cold backup is taken when the database is in offline mode. - Hot backup is inconsistent backup where as cold backup is consistent backup. - You can begin backup by using the following command SQL> alter database begin backup; - End backup by SQL> alter database end backup;
|
How to recover database if we lost the control file and we do not have a backup and what is RMAN?- We can recover our database at any point of time, when we have backup of our control files in different mount points.
- Also check whether the control file is available in trace file located in USERDUMP or the alert log to recover the database. RMAN
- RMAN called as Recovery manager tool supplied by oracle that can be used to manage backup and recovery activities.
- You can perform both offline (Cold) and online (Hot) backup’s using RMAN.
- We need to configure Flash_Recovery_Area of database to use RMAN.
- RMAN maintains the repository of backup information in control file.
|
Name the architectural components of RMAN- RMAN executable - Server process - Channels - Target database - Recovery catalog database - Media management layer - Backup sets and backup pieces
|
What is a recovery catalog?- Recovery catalog is an inventory of backup taken by RMAN for the database. - The size of the recovery catalog schema depends upon the number of databases monitored by the catalog. - It is used to restore a physical backup, reconstruct it, and make it available to the oracle server. - RMAN can be used without recovery catalog. - Recovery catalog also holds RMAN stored scripts.
|
List some advantages of using RMAN.- Table spaces are not put in the backup mode ,therefore there is no extra redo log file during online backups. - Incremental backups that only copy data blocks, which have changed since last backup. - Detection of corrupt blocks. - Built in reporting and listing commands. - Parallelization of I/O operations.
|
How to bring a database from ARCHIVE LOG mode to NON ARCHIVE LOG MODE?- You should change your init.ora file with the following information - log_archive_dest=’/u01/oradata/archlog’ (for example) - log_archive_format=’%t_%s.dbf’ - log_archive_start=true (prior to 10g) - sql>shutdown; - sql> startup mount; - sql> alter database archivelog; - sql>alter database open; - Make sure you backup your database before switching to ARCHIVELOG mode.
|
What are the different stages of database startup?- Database undergoes different stages before making itself available to end users - Following stages are involved in the startup of database 1. NoMount 2. Mount 3. Open
NoMount - Oracle Instance is available based on the parameters defined in SPFile.
Mount - Based on the Information from parameter control files location in spfile, it opens and reads them and available to next stage.
Open - Datafiles, redo log files are available to the end users.
|
Name some of the important dynamic performance views used in Oracle.- V$Parameter - V$Database - V$Instance - V$Datafiles - V$controlfiles - V$logfiles
|
What are the different methods we can shutdown our database?- SHUTDOWN (or) SHUTDOWN NORMAL No new connections are accepted and wait for the user to close the session.
- SHUTDOWN TRANSACTIONAL No new connections are accepted and wait for the existing transactions to commit and logouts the session without the permission of user.
- SHUTDOWN IMMEDIATE No new connections are accepted and all committed transactions are reflected in database and all the transactions are about to commit are rolled back to previous value.
- SHUTDOWN ABORT It’s just like an immediate power off for a database, it doesn’t mind what are the transactions running it just stops entire activity -(even committed transactions are not reflected in database) and make database unavailable. SMON process takes responsibility for recovery during next startup of database.
- SHUTDOWN NORMAL, TRANSACTIONAL, IMMEDIATE are clean shutdown methods as database maintains its consistency.
- SHUTDOWN ABORT leaves our database in an inconsistent state,data integrity is lost.
|
What are the different types of indexes available in Oracle?Oracle provides several Indexing schemas B-tree index - Retrieves a small amount of information from a large table. Global and Local index - Relates to partitioned tables and indexes. Reverse Key Index - It Is most useful for oracle real application clusters applications. Domain Index - Refers to an application Hash cluster Index - Refers to the index that is defined specifically for a hash cluster.
|
What is the use of ALERT log file? Where can you find the ALERT log file?- Alert log file is a log file that records database-wide events which is used for trouble shooting. - We can find the Log file in BACKGROUND_DUMP_DEST parameter. - Following events are recorded in ALERT log file: - Database shutdown and startup information. - All non-default parameters. - Oracle internal (ORA-600) errors. - Information about a modified control file. - Log switch change.
|
What is a user process trace file?- It is an optional file which is produced by user session. - It is generated only if the value of SQL_TRACE parameter is set to true for a session. - SQL_TRACE parameter can be set at database, instance, or session level. - If it set at instance level, trace file will be created for all connected sessions. - If it is set at session level, trace file will be generated only for specified session. - The location of user process trace file is specified in the USER_DUMP_DEST parameter.
|
What are different types of locks?There are different types of locks, which are given as follows: System locks - controlled by oracle and held for a very brief period of time. User locks - Created and managed using dbms_lock package.
Different types of user locks are given as follows
UL Lock - Defined with dbms_lock package. TX Lock - Acquired once for every transaction. It isa row transaction lock. TM Lock - Acquired once for each object, which is being changed. It is a DML lock. The ID1 column identifies the object being modified.
|
What do db_file_sequential_read and db_file_scattered_read events define?- Db_file_sequential_read event generally indicates index usage. - It shows an access by row id. - While the db_file-scattered_read event indicates full table scan. - Db_file_sequential_read event reads a single block at one time. - Whereas db_file_scattered_read event reads multiple blocks.
|
What is a latch and explain its significance?- Latch is an on/off switch in oracle that a process must access in order to perform certain type of activities. - They enforce serial access to the resources and limit the amount of time for which a single process can use a resource. - A latch is acquired for a very short amount of time to ensure that the resource is allocated. - We may face performance issues which may be due to either of the two following reasons - Lack of availability of resource. - Poor application programming resulting in high number of requests for resource. - Latch information is available in the v$LATCH and v$LATCHHOLDER dynamic performance views.
|
Explain the architecture of data guard?Data guard architecture includes the following components
Primary database - Refers to the production database.
Standby Database - Refers to a copy of primary or production database.It may have more than one standby database.
Log transport service - Manages transfer of archive log files primary to standby database.
Network configuration - Refers to the network connection between primary and standby database. Applies archived logs to the standby database.
Role management services - Manages the role change between primary and standby database.
Data guard broker - Manages data guard creation process and monitors the dataguard.
|
What is role transition and when does it happen?- Database operates in one of the following mutually exclusive roles 1. Primary 2. Standby - Role transition is the change of role between primary and standby databases. - Data guard enables you to change this roles dynamically by issuing the sql statements. - Transition happens in between primary and standby databases in the following way - Switchover, where primary database is switched to standby database and standby to primary database. - Failover, where a standby database can be used as a disaster recovery solution in case of a failure in primary database. - DRM allows you to create resource plans, which specify resource allocation to various consumer groups. - DRM offers an easy-to-use and flexible system by defining distinct independent components. - Enables you to limit the length of time a user session can stay idle and automatically terminates long-running SQL statement and users sessions. - Sets the initial login priorities for various consumer groups. - DRM will automatically queue all the subsequent requests until the currently running sessions complete.
|