Oracle Database Administration
Agenda
- Oracle Database Architecture
( Memory Structure and Background Process)
- Physical and Logical Structure of Database
- Database startup and shutdown stage
- Manual and DBCA Database creation in 12c
- Indexes and Types of indexes and Its importan
- User and Role Management
- Checking Logs and Trace Files
- Backup and Recovery
- Health Check of Database
Role of a Database Administrator
- Install and upgrade Oracle Database products
- Creates and maintains all databases required for development, testing, education and production.
- Works in conjunction with System Administrators (SAs) to plan and allocate disk storage for each system. The process can often depend on the type of disk storage system and how it is integrated into the over system architecture.
- Work with software developers, network administrators and system administrators to monitor and perform tuning of the database. The DBA works closely with the software developers because the highest yielding adjustments are often in the sql code used within the application. The DBA works closely with the system administrators because they often have applications or tools to use in monitoring system usage and can help pinpoint system bottle necks.
- Works in concurrence with Security System Administrators (SSA) to implement and maintain database security including monitoring of auditing logs and database usage by users.
- Performs use maintenance
- Plan and implements backup and recovery strategy of Oracle databases.
- Controls migration of programs, database changes, and reference data changes through the development life cycle.
- Modify database structures as required by system/problem change requests (PCR).
- Acts as the principal Oracle support contact. This includes using oracle metalink to research questions and open trouble tickets at http://metalink.oracle.com
- Works with Change Management Team (CM) and Software Developers (SDs) to develop and maintain standards in application design and code. They also work with CM and SD to ensure that system / site standards are being adhered to.
- Evaluates and works with SA, SD, and CM to plan and integrate new releases of Oracle and its tools as well as any other third party products that have been integrated into the database administration or usage.
- Creates, enforces and maintains oracle database constraints to ensure integrity of the database.
- Works closely with software developers to provide technical support for database related issues as well as feedback on possible impact changes to the database objects may cause. It is the database administrators that perform all administration tasks related to database objects, including tables, clusters, indexes, views, sequences, packages and procedures.
- The DBA should work closely with system engineers and software developers to create and implement the physical database design.
Oracle Database Instance
A database instance is a set of memory structures that manage database files. A database is a set of physical files on disk created by the CREATE DATABASE statement. The instance manages its associated data and serves the users of the database.
Every running Oracle database is associated with at least one Oracle database instance. Because an instance exists in memory and a database exists on disk, an instance can exist without a database and a database can exist without an instance.
Database Instance Structure
When an instance is started, Oracle Database allocates a memory area called the system global area (SGA) and starts one or more background processes. The SGA serves various purposes, including the following:
- Maintaining internal data structures that are accessed by many processes and threads concurrently
- Caching data blocks read from disk
- Buffering redo data before writing it to the online redo log files
- Storing SQL execution plans
The SGA is shared by the Oracle processes, which include server processes and background processes, running on a single computer. The way in which Oracle processes are associated with the SGA varies according to operating system.
Oracle Database Architectural
- The user starts a tool such as SQL*Plus,sql developer,toad or runs an application developed using a tool such as Oracle Forms. This application or tool is executed as a user process.
- In the most basic configuration, when a user logs on to the Oracle server, a process is created on the computer running the Oracle server. This process is called a server process. The server process communicates with the Oracle instance on behalf of the user process that runs on the client. The server process executes SQL statements on behalf of the user.
- User Process is started at the time a database user requests a connection to the oracle server. Server Process connect to the oracle instance and started when a user establishes a session.
- user process & server process are used to manage the execution of sql/plsql statements.
- one-to-one correspondence between the User and Server Processes. This is called a Dedicated Server connection. An alternative configuration is to use a Shared Server where more than one User Process shares a Server Process.
- Server Process is the go-between for a Client Process and the Oracle Instance.
- Dedicated Server environment – there is a single Server Process to serve each Client Process.
- Shared Server environment – a Server Process can serve several User Processes, although with some performance reduction
The database has logical structures and physical structures. Because the physical and logical structures are separate, the physical storage of data can be managed without affecting the access to logical storage structures.
Logical Structure
- An Oracle database is made up of several logical storage structures, including data blocks, extents and segments, tablespaces, and schema objects.
- The actual physical storage space in the data files is logically allocated and deallocated in the form of Oracle data blocks. The Database Block Size (DB_BLOCK_SIZE) is the smallest unit of I/O that can be used for accessing data or index files in Oracle database. Oracle reserves a portion of each block for maintaining information, such as the address offset of all the rows contained in the block and the type of information stored in the block.
- An extent is a set of logically contiguous data blocks allocated for storing a specific type of information. Physically, they could be in different file system extents and/or different physical LUNs or drives. A table is comprised of one or more extents. The very first extent of a table is known as the initial extent. When the data blocks of the initial extent become full, Oracle allocates an incremental extent. The incremental extent does not have to be the same size (in bytes) as the initial extent.
- A segment is the collection of extents that contain all of the data for a particular logical storage structure in a tablespace,such as a table or index. There are four different types of segments, each corresponding to a specific logical storage structure type:
- Data segments
- Index segments
- Rollback (Undo) segments
- Temporary segments
Data segments store all the data contained in a table, partition, or cluster. Likewise,
Index segments store all the data contained in an index. For backward compatibility,
Rollback (undo) segments are used to hold the previous contents of an Oracle data block prior to any change made by a particular transaction. If any part of the transaction should not complete successfully, the information contained in the rollback (undo) segments is used to restore the data to its previous state.
In Oracle 9i, 10g and 11g this is achieved using automatic undo and undo tablespaces, which allows better control and use of the server resources.
Rollback (undo) segments are also used to provide read-consistency. There are two different types of read-consistency: statement-level and transaction-level.
Statement-level read consistency ensures that all of the data returned by an individual query comes from a specific point in time: the point at which the query started. This guarantees that the query does not see changes to the data made by other transactions that have committed since the query began.
This is the default level of read consistency provided by Oracle.
In addition, Oracle offers the option of enforcing transaction-level read consistency. Transaction-level read consistency ensures that all queries made within the same transaction do not see changes made by queries outside of that transaction but can see changes made within the transaction itself. These are known as serializable transactions.
Temporary segments are used as temporary workspaces during intermediate stages of a query’s execution.
They are typically used for sort operations that cannot be performed in memory.
The following types of queries may require a temporary segment:
SELECT.....ORDER BY
SELECT.....GROUP BY
SELECT.....UNION
SELECT.....INTERSECT
SELECT.....MINUS
SELECT DISTINCT.....
CREATE INDEX.…
Tablespaces are used to group related logical entities or objects together in order to simplify physical management of the database. Tablespaces are the primary means of allocating and distributing database data at the file system or physical disk level.
Tablespaces are used to:
- Control the physical disk space allocation for the database
- Control the availability of the data by taking the tablespaces online or off-line
- Distribute database objects across different physical storage devices to improve performance
- Regulate space for individual database users
- Every Oracle database contains tablespace named SYSTEM, which Oracle creates automatically when the database is created. The SYSTEM tablespace contains the data dictionary tables for the database used to describe its structure. The SYSAUX tablespace is an auxiliary tablespace to the SYSTEM tablespace. Many database components use the SYSAUX tablespace as their default location to store data. Therefore, the SYSAUX tablespace is always created during database creation or database upgrade.
- The SYSAUX tablespace provides a centralized location for database metadata that does not reside in the SYSTEM tablespace. It reduces the number of tablespaces created by default, both in the seed database and in user-defined databases.
- When the SYSTEM tablespace is locally managed, you must define at least one default temporary tablespace when creating a database.A locally managed SYSTEM tablespace cannot be used for default temporary storage. When SYSTEM is dictionary managed and if you do not define a default temporary tablespace when creating the database, then SYSTEM is still used for default temporary storage.
- Schema objects are the logical structures used to refer to the database’s data. A few examples of schema objects would be tables, indexes, views, and stored procedures. Schema objects, and the relationships between them, constitute the relational design of a database.
Oracle Physical Storage Structures
The Oracle database uses a number of physical storage structures on disk to hold and manage the data from user transactions.
Some of these storage structures, such as the datafiles, redo log files, and archived redo log files, hold actual user data; other structures, such as control files, maintain the state of the database objects, and
text-based alert and trace files contain logging information for both routine events and error conditions in the database.
Figure 1-3 shows the relationship between these physical structures and the logical storage structures
we reviewed in the earlier section “Oracle Logical Database Structures.”
Figure 1-3: Oracle physical storage structures
Datafiles
Every Oracle database must contain at least one datafile. One Oracle datafile corresponds to
one physical operating system file on disk. Each datafile in an Oracle database is a member of one and
only one tablespace; a tablespace, however, can consist of many datafiles.
(A bigfile tablespace consists of exactly one datafile.)
An Oracle datafile may automatically expand when it runs out of space,
if the DBA created the datafile with the AUTOEXTEND parameter.
The DBA can also limit the amount of expansion for a given datafile by using the MAXSIZE parameter. In any case, the size of the datafile is ultimately limited by the disk volume on which it resides.
Tip -The DBA often has to decide whether to allocate one datafile that can AUTOEXTEND indefinitely
or to allocate many smaller datafiles with a limit to how much each can extend.
In earlier releases of Oracle, you had no choice but to have multiple datafiles and
manage the tablespace at the datafile level. Now that you can have bigfile tablespaces,
you can manage most aspects at the tablespace level.
Now that RMAN can back up a bigfile tablespace in parallel as well (since Oracle Database 11g),
it makes sense to create one datafile and let it AUTOEXTEND when necessary.
The datafile is the ultimate resting place for all data in the database.
Frequently accessed blocks in a datafile are cached in memory; similarly,
new data blocks are not immediately written out to the datafile but
rather are written to the datafile depending on when the database writer process is active.
Before a user’s transaction is considered complete,
however, the transaction’s changes are written to the redo log files.
Tip -Create at least one user other than SYS or SYSTEM who has DBA privileges
for daily administrative tasks. If there is more than one DBA administering a database,
each DBA should have their own account with DBA privileges.
Alternatively, authentication for the SYSDBA and SYSOPER privileges
can be done with OS authentication; in this case, a password file does not have to be created,
and the initialization parameter REMOTE_LOGIN_PASSWORDFILE is set to NONE.
1.1.1Access to the database is granted to a database account known as a user.
A user may exist in the database without own ALL_%, DBA_%,USER_%Tables
There are many system tables which can be used to determine user/system information.
Data dictionary tables are not directly accessible, but you can access information in them through data dictionary views.
To list the data dictionary views available to you, query the view DICTIONARY.
SQL>select * from DICTIONARY
Many data dictionary tables have three corresponding views:
■ An ALL_ view displays all the information accessible to the current user,
including information from the current user's schema as well as information from objects in other schemas,
if the current user has access to those objects by way of grants of privileges or roles.
■ A DBA_ view displays all relevant information in the entire database. DBA_ views are intended only for administrators.
They can be accessed only by users with the SELECT ANY TABLE privilege.
This privilege is assigned to the DBA role when the system is initially installed.
■ A USER_ view displays all the information from the schema of the current user.
No special privileges are required to query these views.
Examples:
If you have the proper privileges you can see all the tables within a database by querying the DBA_TABLES view.
SQL>SELECT OWNER,TABLE_NAME FROM DBA_TABLES;
If you want to see all the tables the current user has access to view use the following SQL statement.
SQL>SELECT OWNER, TABLE_NAME FROM ALL_TABLES;
If you only want to see the tables the current user owner use the next SQL statement.
SQL>SELECT TABLE_NAME FROM USER_TABLES;
I will list a few of the essential ones below and you can do a DESC on them to see the available columns.
Table Name Use
*_ALL_TABLES Determine Table Information
*_CONS_COLUMNS Determine the type of constraints on columns.
*_CONSTRAINTS Determine all constraints
*_ERRORS *_ERRORS describes current errors on stored objects
(views, procedures, functions, packages, and package bodies) in the database.
DBA_LOCK, DBA_LOCKS DBA_LOCK lists all locks or latches held in the database,
and all outstanding requests for a lock or latch.
Database Startup Step
Database Shutdown
You can not go back down the stair step depicted in Figure 11, you have to SHUTDOWN the database completely and then you can open it to the state you need. The SHUTDOWN command closes the database, dismounts the database and then shuts down the instance. There are several SHUTDOWN options that can be employed.
SQL>SHUTDOWN NORMAL
The database will only SHUTDOWN when all users have logged off and all work is committed (or rolled back).
No new connections are allowed.
This option is difficult to use in man environments since the users are applications and all the applications have to be shutdown before the database would shutdown.
SQL>SHUTDOWN IMMEDIATE
Disconnects all users and performs rollback on all uncommitted data by using PMON
Terminates all current SQL statements
SQL>SHUTDOWN ABORT
Shuts down without tidying up; akin to system failure and requires system recovery on start-up
No rollback of uncommitted transactions
The Basics - Shutting Down Database
Position to the correct database (setting the Oracle SID):
For example, in UNIX: Or, in NT:
$ . oraenv c:\> set ORACLE_SID=PROD
PROD c:\> setORACLE_HOME=d:\oracle\v9204
Connect as sysdba (from a dba group user login, such as oracle):
Oracle 8.1.5 and above: Prior to Oracle 9i, use Server Manager:
$ sqlplus “/ as sysdba” $ svrmgrl
(SQL> connect / as sysdba) SVRMGR> connect internal
Shut down the database (connected as sysdba):
SQL> shutdown immediate (kills sessions, rolls back pending changes)
If “shutdown immediate” fails or hangs (do this in another session):
SQL> shutdown abort
SQL> startup
SQL> shutdown immediate
Real-Time Example
----------------
In this example ,We have creating easyuser and providing select privilete
1) check if user exist
select username,account_status,profile from dba_users where username like 'easyuser';
2) easyuser don't exist , so we will take metadata for similiar type of user
set long 9999999
set pagesize 0
set linesize 120
select DBMS_METADATA.GET_DDL('USER','EASYUSER2') from dual;
create user easyuser identified by <PASSWORD> default tablespace users temporary tablespace temp;
ALTER USER BZ2805 quota unlimited on users;
GRANT CREATE SESSION to easyuser;
Grant succeeded.
SQL> GRANT CONNECT to easyuser;
select username,account_status,profile from dba_users where username like 'easyuser';
grant READ_ROLE to easyuser
Dynamic query to generate privilege
select 'GRANT SELECT ON '||OWNER||'.'||object_name ||' TO R_ODS_DAT;'
from dba_objects where owner in ('INTERNSCHEMA','EASYSCHEMA') and object_type='TABLE';
To reset password
select
username,
last_login,
password
from
dba_users where username in ('EASYUSER','EASYUSER2')
col name format a20
col password format a60
select name,password from sys.user$ where name in ('EASYUSER','EASYUSER2')
alter user EASYUSER identified by Infra123
select username,account_status,profile from dba_users where username like 'easyuser';
To check privilege
SQL> select * from dba_role_privs where grantee='easyuser';
no rows selected
SQL> select * from dba_sys_privs where grantee='easyuser';
no rows selected
SQL>
select * from dba_tab_privs where grantee='easyuser';
grant CONNECT,EASY_ADMIN_ROLE to 'easyuser
grant create session to 'easyuser
grant CREATE SYNONYM to 'easyuser
Dear Recruiter,
ReplyDeleteGreetings from Internopening – One of most search job portal for Fresher in India.
This Christmas, Internopening is offering you free across all recruitment packages
Get access to internopening's resume database service with the lowest price ever. Cost effective way to hire fresher! We have 1.75 lakhs Database with 5 Lakh active candidates.
You can post job after registering https://internopening.com/login-register/
Looking for personal assistance? Do reach out to Vishnu, Your hiring manager @ 91-9606734482/+91-8041156843 or shoot an email to contact@InternOpening.com to avail this offer. Offer valid till 31th Jan, 2023.
Regards,
Team Internopening
Phone: +91 9606734482/+91 8041156843
Website : www.Internopening.com
Email: hr@internopening.com/contact@InternOpening.