Download session 14

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Global serializability wikipedia , lookup

DBase wikipedia , lookup

Commitment ordering wikipedia , lookup

SQL wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Microsoft Access wikipedia , lookup

Serializability wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Btrieve wikipedia , lookup

IMDb wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Functional Database Model wikipedia , lookup

Ingres (database) wikipedia , lookup

PL/SQL wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Relational model wikipedia , lookup

Database wikipedia , lookup

Concurrency control wikipedia , lookup

Database model wikipedia , lookup

Clusterpoint wikipedia , lookup

Oracle Database wikipedia , lookup

ContactPoint wikipedia , lookup

Transcript
Oracle - Practical 14
INTRODUCTION TO ORACLE DBA
An Oracle database system can be quite large and serve many users. Therefore, it is often
necessary for one person or a group of people to be responsible for managing the database
system. The database administrator, or DBA, is the manager.
DBA Responsibilities:
1. Installing and upgrading the Oracle Server and application tools.
2. Creating primary database storage structures and primary objects.
3. Allocating system storage and planning future storage requirements for the database
system.
4. Modifying the database structure.
5. Enrolling users
6. Controlling and monitoring user access to the database
7. Backing up and recovering the database
8. Maintaining the system security
9. Monitoring and optimising database performance.
In some database systems there may be several DBAs with different responsibilities. For,
example different DBAs might be responsible for creating users, monitoring users, monitoring
system resources, and maintaining system security.
In contrast with the responsibilities of a DBA, an application developer in a database system
may be responsible for designing and developing database applications, designing database
objects, and tuning applications.
We will cover some of the tasks of a database administrator.
Today we will start with an overview of the Oracle Server architecture – this was covered in
more detail in your Lectures.
Oracle Server architecture :










The System Global Area is a group of the following shared memory constructs
Shared Pool
Database buffer cache
Redo Log Buffer
The background processes asynchronously perform distinct tasks on behalf of all
database users.
Server processes use shared memory to process SQL statements.
User processes run the tool or application and exchange SQL statement processing
with the server process.
An Oracle instance consists of the SGA and background processes.
An Oracle database contains all the datafiles, redo log files and control files.
Redo Log files record all changes made to the database, and are used for data
recovery.
A control file describes the structure of the database and is needed to mount and
open the database.
A parameter file is used to size the SGA and locate the control files when starting up
an Oracle instance.
An alert file of a database is a chronological log of messages and errors.
Page 1
Oracle - Practical 14
Summary
Oracle Instance
PMON
SMON
DBWR
SNPn
Shared Pool
LCKn
RECO
SGA
Database Buffer Cache
Snnn
Dnnn
Pnnn
Redo Log
Buffer
CKPT
LGWR
ARCH
Server
Processes
User
Processes
Oracle Database
Parameter File
Control Files
DataFiles
Redo Log Files
Next we will look at creating an Oracle database.
Considerations before creating a database :
1. Planning for database creation :
 Plan the database tables and indexes and estimate the amount of space they
will require.
 Plan the layout of the underlying operating system files that are to comprise
your database.
 Select the global database name, which is the name and location of the
database within the network structure. Create the global database name by
setting both the DB_NAME and DB_DOMAIN initialization parameters.
 Familiarize yourself with the initialization parameters that comprise the
initialization parameter file.
 Select the standard database block size. This is specified at database
creation by the DB_BLOCK_SIZE initialization parameter and cannot be
changed after the database is created. The DB_BLOCK_SIZE initialization
parameter specifies the standard block size for the database. This block size
is used for the SYSTEM tablespace and by default in other tablespaces.
Typically, DB_BLOCK_SIZE is set to either 4K or 8K. If not specified, the
default data block size is operating system specific, and is generally
adequate.
 Develop a backup and recovery strategy to protect the database from failure.
 Familiarize yourself with the principles and options of starting up and shutting
down an instance and mounting and opening a database.
 Ensure correct Licenses are obtained from Oracle.
Page 2
Oracle - Practical 14
2. Meeting creation prerequisites.
To create a new database, the following prerequisites must be met:
 The desired Oracle software is installed. This includes setting up various
environment variables unique to your operating system and establishing the
directory structure for software and database files.
 You have the operating system privileges associated with a fully operational
database administrator.
 There is sufficient memory available to start the Oracle instance.
 There is sufficient disk storage space for the planned database on the computer
that executes Oracle.
 A user is required to own the Oracle databases and server. This user is normally
called oracle and must be a member of the dba group. Also ensure a home
directory is created for the user oracle.
3. Deciding how to create an Oracle database.
Creating a database includes the following operations:
 Creating information structures, including the data dictionary, that Oracle requires
to access and use the database
 Creating and initializing the control files and redo log files for the database
 Creating new datafiles or erasing data that existed in previous datafiles
You use the CREATE DATABASE statement to perform these operations, but other
actions are necessary before you have an operational database. A few of these
actions are creating users and temporary tablespaces, building views of the data
dictionary tables, and installing Oracle built-in packages. This is why the database
creation process involves executing prepared scripts.
You have the following options for creating your new Oracle database:



Oracle Universal Installer - depending upon the type of install that you select,
this provides a graphical user interface (GUI) that guides you through the
creation of a database.
Create the database manually from a script.
Migrate or upgrade an existing database - If you are using a previous release
of Oracle, database creation is required only if you want an entirely new
database. Otherwise, you can migrate or upgrade your existing Oracle
database managed by a previous version or release of Oracle and use it with
the new version of the Oracle software
Creating a database :
We will look at manually creating an Oracle database.
1. Decide on a unique Oracle system identifier (SID) for your instance and set the
ORACLE_SID environment variable accordingly. This identifier is used to avoid
confusion with other Oracle instances that you may create later and run concurrently
on your system.
The following example sets the SID for the instance and database we are about to
create:
% setenv ORACLE_SID mynewdb
Note : The value of the DB_NAME initialization parameter should match the SID
setting.
Page 3
Oracle - Practical 14
1. The instance (System Global Area and background processes) for any Oracle
database is started using an initialization parameter file. One way of getting started
on your initialization parameter file is to edit a copy of the sample initialization
parameter file that Oracle provides on the distribution media. For ease of operation,
store your initialization parameter file in Oracle's default location, using the default
name.
Default parameter file locations are shown in the following table:
Platform Default Name
Default Location
UNIX
init$ORACLE_SID.ora
For example, the initialization
parameter file for the mynewdb
database is named:
initmynewdb.ora
$ORACLE_HOME/dbs
For example, the initialization parameter file
for the mynewdb database is stored in the
following location:
/oracle/dbs/initmynewdb.ora
NT
init$ORACLE_SID.ora
$ORACLE_HOME\database
The following is the initialization parameter file used to create the mynewdb database.
Sample Initialization Parameter File :
# Cache and I/O
DB_BLOCK_SIZE=4096
DB_CACHE_SIZE=20971520
# Cursors and Library Cache
CURSOR_SHARING=SIMILAR
OPEN_CURSORS=300
# Diagnostics and Statistics
BACKGROUND_DUMP_DEST=/oracle/admin/mynewdb/bdump
CORE_DUMP_DEST=/oracle/admin/mynewdb/cdump
TIMED_STATISTICS=TRUE
USER_DUMP_DEST=/oracle/admin/mynewdb/udump
# Control File Configuration
CONTROL_FILES=("/oracle/oradata/mynewdb/control01.ctl",
"/oracle/oradata/mynewdb/control02.ctl",
"/oracle/oradata/mynewdb/control03.ctl")
# Archive
LOG_ARCHIVE_DEST_1='LOCATION=/oracle/oradata/mynewdb/archive'
LOG_ARCHIVE_FORMAT=%t_%s.dbf
LOG_ARCHIVE_START=TRUE
# Miscellaneous
COMPATIBLE=9.0.0
DB_NAME=mynewdb
# Pools
JAVA_POOL_SIZE=31457280
LARGE_POOL_SIZE=1048576
SHARED_POOL_SIZE=52428800
# Processes and Sessions
PROCESSES=150
Page 4
Oracle - Practical 14
# Sort, Hash Joins, Bitmap Indexes
SORT_AREA_SIZE=524288
1. Connect to the Instance :
Start Server Manager and connect to your Oracle instance AS SYSDBA.
SVRMGR> CONNECT SYS/password AS SYSDBA
2. Start the instance :
Start an instance without mounting a database. Typically, you do this only during
database creation. Use the STARTUP command with the NOMOUNT option.
STARTUP NOMOUNT
Note : SGA is allocated and the background processes will be started at this point.
3. Issue the create database statement :
To create the new database, use the CREATE DATABASE statement. When you
execute a CREATE DATABASE statement, Oracle performs the following operations.
Other operations are performed depending upon the clauses that you specify in the
CREATE DATABASE statement or initialization parameters that you have set.
 Creates the datafiles for the database
 Creates the control files for the database
 Creates the redo log files for the database and establishes the
ARCHIVELOG mode
 Creates the SYSTEM tablespace and the SYSTEM rollback segment
 Creates the data dictionary
 Sets the character set that stores data in the database
 Sets the database time zone
 Mounts and opens the database for use
The following statement creates database mynewdb:
CREATE DATABASE mynewdb
MAXINSTANCES 1
MAXLOGHISTORY 1
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXDATAFILES 100
DATAFILE '/oracle/oradata/mynewdb/system01.dbf' SIZE 325M
DEFAULT TEMPORARY TABLESPACE temp
CHARACTER SET WE8ISO8859P1
LOGFILE GROUP 1 ('/oracle/oradata/mynewdb/redo01.log') SIZE 100M,
GROUP 2 ('/oracle/oradata/mynewdb/redo02.log') SIZE 100M,
GROUP 3 ('/oracle/oradata/mynewdb/redo03.log') SIZE 100M;
The database is created with the following characteristics:
 The database is named mynewdb
 Three control files are created as specified by the CONTROL_FILES
initialization parameter
 MAXINSTANCES specified that only one instance can have this database
mounted and open.
 MAXDATAFILES specifies the maximum number of datafiles that can be
open in the database
 The SYSTEM tablespace, consisting of the operating system file
/oracle/oradata/mynewdb/system01.dbf is created as specified by the
DATAFILE clause. If the file already exists, it is overwritten.
 The DEFAULT_TEMPORARY_TABLESPACE clause creates and names a
default temporary tablespace for this database.
Page 5
Oracle - Practical 14

The 8-bit WE8ISO8859P1 character set is used to store data in this
database.

The new database has three online redo log files as specified in the
LOGFILE
clause.
MAXLOGHISTORY,
MAXLOGFILES,
and
MAXLOGMEMBERS define limits for the redo log.
Because the ARCHIVELOG clause is not specified in this CREATE
DATABASE statement, redo log files will not initially be archived. This is
customary during database creation and an ALTER DATABASE statement
can be used later to switch to ARCHIVELOG mode. The initialization
parameters in the initialization parameter file for mynewdb affecting archiving
are
LOG_ARCHIVE_DEST_1,
LOG_ARCHIVE_FORMAT,
and
LOG_ARCHIVE_START.
The default database time zone is the same as the operating system's time
zone. You can set the database's default time zone by specifying the SET
TIME_ZONE clause of the CREATE DATABASE statement.


4. Create additional tablespaces :
To make the database functional, you need to create additional files and tablespaces
for users. The following sample script creates some additional tablespaces:
CONNECT SYS/password AS SYSDBA
-- create a user tablespace to be assigned as the default tablespace for users
CREATE TABLESPACE users
DATAFILE '/oracle/oradata/mynewdb/users01.dbf' SIZE 25M;
-- create a tablespace for tables needed by the Oracle Server Tools
CREATE TABLESPACE tools
DATAFILE '/oracle/oradata/mynewdb/tools01.dbf' SIZE 25M;
-- create a tablespace for indexes, separate from user tablespace
CREATE TABLESPACE indx
DATAFILE '/oracle/oradata/mynewdb/indx01.dbf' SIZE 25M;
-- create a tablespace for rollback.
CREATE TABLESPACE rollback
DATAFILE '/oracle/oradata/mynewdb/rollback01.dbf' SIZE 25M;
CREATE ROLLBACK SEGMENT r1 TABLESPACE rollback STORAGE 5M ;
ALTER rollback segment r1 ONLINE;
EXIT
5. Next run scripts to build data dictionary views :
Run the scripts necessary to build views, synonyms, and PL/SQL packages:
CONNECT SYS/password AS SYSDBA
@/oracle/rdbms/admin/catalog.sql;
@/oracle/rdbms/admin/catproc.sql;
EXIT;
Page 6
Oracle - Practical 14
The following table contains descriptions of the scripts:
Script
Description
CATALOG.SQL
Creates the views of the data dictionary tables, the dynamic performance
views, and public synonyms for many of the views. Grants PUBLIC access
to the synonyms.
CATPROC.SQL Runs all scripts required for or used with PL/SQL.
6. Run scripts to install Additional Options (optional) :
If you plan to install other Oracle products to work with this database, see the
installation instructions for those products. Some products require you to create
additional data dictionary tables. Usually, command files are provided to create and
load these tables into the database's data dictionary.
7. Backup the database :
You should make a full backup of the database to ensure that you have a complete
set of files from which to recover if a media failure occurs.
Starting the database :
When starting the database you must choose the state you want to start your database at.
Startup states:
NOMOUNT
Is used to create the database
MOUNT
Is used to alter file structure and modify control file flags.
OPEN
Makes the database available to all users.



If STARTUP NOMOUNT is issued, the instance will be started – creates the SGA
and starts the background processes, but does not allow access to the database.
If STARTUP MOUNT is issued, the instance will be started and the control file will
be opened. The control files are read to obtain the names and status of the data
files and redo log files. The database can be mounted but not opened to alter the
existing file structure e.g. renaming log or datafiles or starting recovery.
To open the database from STARTUP MOUNT, use the ALTER DATABASE
OPEN command to make it available to all users.
Example:
$ svrmgrl
Oracle Server Manager Release 2.3.3.0.0 - Production
Copyright (c) Oracle Corporation 2000, 2001. All rights reserved.
Oracle7 Server Release 8.1.6.0.0 - Production Release
PL/SQL Release 2.3.3.0.0 - Production
SVRMGR> connect / as sysdba;
Connected.
SVRMGR> startup;
ORACLE instance started.
Page 7
Oracle - Practical 14
Total System Global Area
4313316 bytes
Fixed Size
41876 bytes
Variable Size
4140368 bytes
Database Buffers
122880 bytes
Redo Buffers
8192 bytes
Database mounted.
Database opened.
SVRMGR> exit;
Server Manager complete.
Shutting down the database :
Close the database and shut down the instance to make the database unavailable to all
users. This is usually done to make operating system offline backups of all physical
structures, and to modify the initialisation parameters.
Note: When shutting down the server without shutting down the Oracle database first there is
a high risk of corrupting the database.
Syntax :
SHUTDOWN



NORMAL
IMMEDIATE
ABORT
Normal – waits for all currently connected users to terminate their sessions normally.
No new connections are allowed. Normal is the default mode.
Immediate - terminates currently executing SQL statements and rolls back
uncommitted transactions. The Oracle Server does not wait for currently connected
users to disconnect from the database. This closes and dismounts the database and
shuts down the instance cleanly.
Abort – does not wait for calls to complete or users to disconnect. It does not roll back
uncommitted transactions. It does not close or dismount the database, but does
shutdown the instance.
Example :
$ svrmgrl
Oracle Server Manager Release 2.3.3.0.0 - Production
Copyright (c) Oracle Corporation 2000, 2001. All rights reserved.
Oracle7 Server Release 8.1.6.0.0 - Production Release
PL/SQL Release 2.3.3.0.0 - Production
SVRMGR> connect / as sysdba;
Connected.
SVRMGR> shutdown;
Database closed.
Database dismounted.
ORACLE instance shut down.
SVRMGR> exit;
Server Manager complete.
Page 8
Oracle - Practical 14
Altering and Creating Users :
The database, as created, has two special users which are automatically created with default
passwords. These are:
Username
SYSTEM
SYS
These users are typically used to hold the standard data dictionary information for the
database. It is a good idea to change the passwords from the defaults as soon as possible.
This can be achieved by:
alter user system identified by <newpassword>;
alter user sys identified by <newpassword>;
Refer to previous practicals on creating roles and new users.
Data Dictionary Views :




Identify all the rollback segments and their status:
SELECT
segment_name, status
FROM
dba_rollback_segs;
Display information about tablespace definitions:
COL TABLESPACE_NAME FORMAT A10
SELECT
tablespace_name, initial_extent,next_extent,status,contents
FROM
dba_tablespaces;
Display the names of the data files belonging to the database
COL file_name FORMAT A10
SELECT
*
FROM
dba_data_files;
Display information about unused space in the database
SELECT
*
FROM
dba_free_space;
Page 9