Oracle DBA LAB Manual

Download as pdf or txt
Download as pdf or txt
You are on page 1of 47

Information Systems Department, Imam University

Oracle DBA LAB

Starting Up and Shutting Down

Starting Up the Database Using the SQL Command Line

At the operating system prompt, enter the following command to start the SQL
Command Line and connect to the database:

SQLPLUS / AS SYSDBA

The slash (/) indicates that the database should authenticate you with operating system
authentication.

At SQL command prompt enter the following command to connect to the database

CONNECT / AS SYSDBA

At the SQL Command Line prompt, enter the following command:

SQL> STARTUP

If the command is successful, it displays output similar to the following. (System global
area sizes will vary depending on the amount of physical memory in your Oracle
Database XE host computer.)

ORACLE instance started.

Total System Global Area 599785472 bytes


Fixed Size 1220804 bytes
Variable Size 180358972 bytes
Database Buffers 415236096 bytes
Redo Buffers 2969600 bytes
Database mounted.
Database opened.

To exit the SQL Command Line. enter the following command:

SQL> EXIT

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Starting Up an Instance

• NOMOUNT—Start the instance without mounting a database. This does not allow
access to the database and usually would be done only for database creation or
the re-creation of control files.
• MOUNT—Start the instance and mount the database, but leave it closed. This state
allows for certain DBA activities, but does not allow general access to the
database.
• OPEN—Start the instance, and mount and open the database. This can be done in
unrestricted mode, allowing access to all users, or in restricted mode, allowing
access for database administrators only.
• FORCE—Force the instance to start after a startup or shutdown problem.
• OPEN RECOVER—Start the instance and have complete media recovery begin
immediately.

Product Release Number


Oracle Database Release Number Format
SELECT * FROM PRODUCT_COMPONENT_VERSION;
SELECT * FROM V$VERSION;

1.2.3.4.5
1 Major database release number
2 Maintenance release number
3 application server release number
4 component specific release number
5 platform specific release number

Shutting Down the Database

At the operating system prompt, enter the following command to start the SQL
Command Line and connect to the database:

SQLPLUS / AS SYSDBA

The slash (/) indicates that the database should authenticate you with operating system
authentication.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Shutting Down with the Normal Mode

The NORMAL clause of the SQL*Plus SHUTDOWN command is optional because this is the
default shutdown method

Normal database shutdown proceeds with the following conditions:

• No new connections are allowed after the statement is issued.


• Before the database is shut down, the database waits for all currently connected
users to disconnect from the database.

The next startup of the database will not require any instance recovery procedures.

Shutting Down with the Immediate Mode

Use immediate database shutdown only in the following situations:

• To initiate an automated and unattended backup


• When a power shutdown is going to occur soon
• When the database or one of its applications is functioning irregularly and you
cannot contact users to ask them to log off or they are unable to log off

Immediate database shutdown proceeds with the following conditions:

• No new connections are allowed, nor are new transactions allowed to be started,
after the statement is issued.
• Any uncommitted transactions are rolled back. (If long uncommitted transactions
exist, this method of shutdown might not complete quickly, despite its name.)
• Oracle Database does not wait for users currently connected to the database to
disconnect. The database implicitly rolls back active transactions and disconnects
all connected users.

The next startup of the database will not require any instance recovery procedures.

Shutting Down with the Transactional Mode

Performing a planned shutdown of an instance while allowing active transactions to


complete first.

Transactional database shutdown proceeds with the following conditions:

• No new connections are allowed, nor are new transactions allowed to be started,
after the statement is issued.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
• After all transactions have completed, any client still connected to the instance is
disconnected.
• At this point, the instance shuts down just as it would when a SHUTDOWN
IMMEDIATE statement is submitted.

The next startup of the database will not require any instance recovery procedures.

A transactional shutdown prevents clients from losing work, and at the same time, does
not require all users to log off.

Shutting Down with the Abort Mode

You can shut down a database instantaneously by aborting the database instance. If
possible, perform this type of shutdown only in the following situations:

The database or one of its applications is functioning irregularly and none of the other
types of shutdown works.

• You must shut down the database instantaneously (for example, if you know a
power shutdown is going to occur in one minute).
• You experience problems when starting a database instance.

An aborted database shutdown proceeds with the following conditions:

• No new connections are allowed, nor are new transactions allowed to be started,
after the statement is issued.
• Current client SQL statements being processed by Oracle Database are
immediately terminated.
• Uncommitted transactions are not rolled back.
• Oracle Database does not wait for users currently connected to the database to
disconnect. The database implicitly disconnects all connected users.

The next startup of the database will require automatic instance recovery procedures.

Shutdown Timeout

Shutdown modes that wait for users to disconnect or for transactions to complete have
a limit on the amount of time that they wait.

At the SQL Command Line prompt, enter the following command:

SQL> SHUTDOWN IMMEDIATE

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Note that this command may take a short while to complete. If the command is
successful, it displays the following output:

Database closed.
Database dismounted.
ORACLE instance shut down.

If the command displays no output after a number of minutes, indicating that the
shutdown operation is not proceeding, you can press CTRL-C to interrupt the command,
and then enter the following command:

SQL> SHUTDOWN ABORT

The database must go through a recovery process when it starts up after


a SHUTDOWN ABORT command. It is recommended that you enable the recovery process to
take place immediately, after which you can shut down the database normally. To do
this, enter the following commands when the SHUTDOWN ABORT completes:

SQL> STARTUP
SQL> SHUTDOWN IMMEDIATE

To exit the SQL Command Line. enter the following command:

SQL> EXIT

The following statement opens a database in read-only mode:

ALTER DATABASE OPEN READ ONLY;

You can also open a database in read/write mode as follows:

ALTER DATABASE OPEN READ WRITE;

However, read/write is the default mode.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Connecting to Database
Local Connections

Connecting Locally with the SQL Command Line

On Windows: Click Start, point to Programs (or All Programs), point to Oracle Database
11g Express Edition, and then select Run SQL Command Line.

At the SQL Command Line prompt, enter the following command:

CONNECT username/password

Starting the SQL Command Line from a Terminal Session or Command


Window

To start the SQL Command Line from a terminal session or command window and
connect locally:

1. If not already open, open a terminal session (Linux) or a command window


(Windows).
2. Enter the following command at the operating system prompt:

SQLPLUS /NOLOG

3. At the SQL Command Line prompt, enter the following command:

CONNECT username/password

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Remote Connections

Connect Strings

To connect remotely, you must supply not just a user name and password, but a
complete Oracle Net connect string. In addition to the database user name and
password, aconnect string includes a host name or host IP address, an optional TCP
port number, and an optional database service name. These additional parameters are
required to help Oracle Net find the right host computer and connect to Oracle
Database XE. An Oracle Net connect string has the following format:

username/password@[//]host[:port][/service_name]

where:

• // is optional
• host is the host name or IP address of the computer that is running Oracle
Database XE
• port (optional) is the TCP port number on which the Oracle Net listener is
listening. If not specified, the default port number 1521 is assumed.
• service_name (optional) is the name of the database service to which to connect.
For Oracle Database XE, the service name is XE. If service_name is omitted, Oracle
Database XE Client appends a request for the default database service, which is
configured during installation as XE.

Example 1 This example initiates a remote connection from Oracle Database XE, using
the default port number.

CONNECT system/[email protected]

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Example 2 This example initiates a remote connection from Oracle Database XE, using
a nondefault port number (1522):

CONNECT system/[email protected]:1522

Example 3 This example initiates a remote connection using the default port number,
and includes the optional service name.

CONNECT system/[email protected]/XE

Managing Users and Security

User Privileges and Roles

When creating a user, you grant privileges to enable the user to connect to the
database, to run queries and make updates, and to create schema objects. There are
two main types of user privileges:

• System privileges—A system privilege is the right to perform a particular


action, or to perform an action on any schema objects of a particular type. For
example, the privileges to create tables and to delete the rows of any table in a
database are system privileges.
• Object privileges—An object privilege is a right to perform a particular action
on a specific schema object. Different object privileges are available for different
types of schema objects. The privilege to delete rows from the DEPARTMENTS table
is an example of an object privilege.
• Table - Oracle Database Express Edition Predefined Roles

Role
Name Description
CONNECT Enables a user to connect to the database. Grant this role to any user or
application that needs database access.
RESOURCE Enables a user to create certain types of schema objects in that user's own
schema. Grant this role only to developers and to other users that must
create schema objects. This role grants a subset of the create object system
privileges. For example, it grants the CREATE TABLEsystem privilege, but does
not grant the CREATE VIEW system privilege. It grants only the following
privileges: CREATE CLUSTER, CREATEINDEXTYPE, CREATE OPERATOR, CREATE PROCEDURE,
CREATE SEQUENCE, CREATE TABLE, CREATE TRIGGER, CREATE TYPE
DBA Enables a user to perform most administrative functions, including creating
users and granting privileges; creating and granting roles; creating and

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Role
Name Description
dropping schema objects in other users' schemas; and more. It grants all
system privileges, but does not include the privileges to start up or shut
down the database. It is by default granted to user SYSTEM.

The SYS and SYSTEM Users

The following administrative user accounts are automatically created when you install
Oracle Database Express Edition (Oracle Database XE). They are both created with the
password that you supplied upon installation (Windows operating systems) or
configuration (Linux operating systems).

• SYSTEM

This is the user account that you log in with to perform all administrative
functions other than starting up and shutting down the database.

• SYS

All base tables and views for the database data dictionary are stored in
the SYS schema. These base tables and views are critical for the operation of
Oracle Database XE. To maintain the integrity of the data dictionary, tables in
the SYS schema are manipulated only by the database. They should never be
modified by any user or database administrator. You must not create any tables
in the SYS schema.

The SYSDBA System Privilege

SYSDBA is a system privilege that is assigned only to user SYS. It enables SYS to perform
high-level administrative tasks such as starting up and shutting down the database.

Although under typical circumstances it is not necessary to log in to the database as


user SYS, if you want to log in as SYS with the SQL Command Line (SQL*Plus), you must
connect to the database "AS SYSDBA." Connecting AS SYSDBA invokes the SYSDBA privilege.
If you omit the AS SYSDBA clause when logging in as user SYS, the SQL Command Line
rejects the login attempt.

The following example illustrates how to connect to the database with


the SYSDBA privilege from the SQL Command Line:

SQL > connect sys/password as sysdba

password is the password for the SYS user account.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Table - Database Administrator Login Methods

Login Method Permitted In Notes See


Log in to the The Oracle For routine administrative tasks like "Logging In as
database as Database XE managing memory and managing User SYSTEM"
userSYSTEM graphical user users. You must supply the
interface and the password for theSYSTEM user.
SQL Command
Line
Log in to the The Oracle For routine administrative tasks like "Logging In as
database as a Database XE managing users. An administrator a User with the
user who has graphical user must first grant the DBA role to the DBA Role"
been granted interface and the user.
theDBA role SQL Command
Line
Log in and the SQL For high-level administrative tasks "Logging In
connect to the Command Line like starting up and shutting down and
database the database, and changing Connecting to
as SYSDBA the SYS password. You can connect the Database
as SYSDBA using the SYSuser name as SYSDBA"
and password, or using operating
system authentication.

Changing Administrative User Passwords

To change the password for user SYS or SYSTEM:

1. Using the SQL Command Line, connect to the database as SYSDBA.


2. Enter one of the following commands:

ALTER USER SYS IDENTIFIED BY newpassword;


ALTER USER SYSTEM IDENTIFIED BY newpassword;

Managing Database Users


Creating a User

Suppose you want to create a user account for a database application developer named
Nick. Because Nick is a developer, you want to grant him all CREATE system privileges so
that he can create the schema objects that his applications require. In addition, you
want to create his account with the password firesign.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
To create the user Nick:

1. Right-click the Other Users node in the SQL Developer Connections navigator
and select Create User.
2. In the Create/Edit User dialog box, for the User tab, enter the information
shown in the following figure:

User Name: NICK

New Password and Confirm Password: Desired password for the user.

Password expired (user must change): Select or not, as desired. (It is not
selected in the figure.)

Account is Locked: Select or not, as desired. (It is not selected in the figure.)

Edition Enabled: Select or not, as desired. (It is not selected in the figure.)

Default Tablespace: USERS

Temporary Tablespace: TEMP

3. In the Create/Edit User dialog box, click the Roles tab, and under Granted select
the following roles:
o CONNECT
o RESOURCE
4. In the Create/Edit User dialog box, click the System Privileges tab, and under
Granted select the following privileges because you want to be sure that NICK will
have them):
o CREATE DATABASE LINK
o CREATE MATERIALIZED VIEW

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
o CREATE PROCEDURE
o CREATE PUBLIC SYNONYM
o CREATE ROLE
o CREATE SEQUENCE
o CREATE SYNONYM
o CREATE TRIGGER
o CREATE TYPE
o CREATE VIEW
5. In the Create/Edit User dialog box, click Apply, then click Close.

Creating User from Command Prompt


>Create user [username] identified by [password];

User Created

>Grant connect, resource, DBA to [username];

Altering a User

Suppose Nick is promoted to senior developer, and he has shown an interest in helping
with routine database administration tasks. You decide to grant the DBA role to Nick.

To alter Nick's user account:

1. In the SQL Developer Connections navigator, expand the SYSTEM connection and
right-click the Other Users node.
2. Right-click NICK and select Edit User.
3. In the Create/Edit User dialog box, click the Roles tab.
4. Under Granted, select DBA.
5. In the Create/Edit User dialog box, click Apply, then click Close.

Locking and Unlocking User Accounts

To lock or unlock a user account:

1. In the SQL Developer Connections navigator, expand the SYSTEM connection and
right-click the Other Users node.
2. Right-click the desired user and select Edit User.
3. In the Create/Edit User dialog box, in the User tab, select or deselect Account is
Locked: selecting (checking) causes the account to be locked; deselecting
(unchecking) causes the account to be unlocked.
4. In the Create/Edit User dialog box, click Apply, then click Close.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Expiring a Password

Suppose Nick's password becomes compromised, and you want to assign him a new
one. The easiest way to do this is to expire his current password. The next time that
Nick logs in with the compromised password, he is prompted to choose a new
password.

To expire Nick's password:

1. In the SQL Developer Connections navigator, expand the SYSTEM connection and
right-click the Other Users node.
2. Right-click NICK and select Edit User.
3. In the Create/Edit User dialog box, in the User tab, select (check) Password
expired (user must change next login).
4. In the Create/Edit User dialog box, click Apply, then click Close.

Dropping a User

Suppose Nick's project is canceled and Nick takes a position in another department. You
want to drop the user NICK and all associated schema objects.

To drop user NICK and all his owned schema objects:

1. In the SQL Developer Connections navigator, expand the SYSTEM connection and
right-click the Other Users node.
2. Right-click NICK and select Drop User.
3. In the Drop User dialog box, (check) Cascade

This indicates that you want to drop the user's schema objects also. If the user
has schema objects and you do not select this option, you receive an error
message if you attempt to complete the drop operation.

4. In the Drop User dialog box, click Apply.

Managing Network Connections

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
About Network Connections and the Oracle Net Listener

Oracle Database Express Edition (Oracle Database XE) supports connections from client
applications both remotely over the network and locally. Remote client applications and
the database communicate through Oracle Net, which is a software layer that resides
both on the remote computer and on the Oracle Database XE host computer. Oracle
Net establishes the connection between the client application and the database, and
exchanges messages between them using TCP/IP. Oracle Net is automatically installed
when you install Oracle Database XE and Oracle Database Express Edition Client.

Included with Oracle Net in an Oracle Database XE installation is the Oracle Net
listener, commonly known as the listener. It is the host process that listens on specific
TCP/IP ports for connection requests. When the listener receives a valid connection
request from a client application, it routes the connection request to the database. The
client application and the database then communicate directly.

Table - Types of Connection Requests Handled by the Listener

Default
Connection TCP Port
Request Type Number Used For

Database 1521 Database connections using Oracle Net over TCP/IP. Examples
include:
• Remote connection from the SQL Command Line.
• Remote connection from a Java application that connects with
JDBC.
HTTP 8080 Database connections using the HTTP protocol. Examples include:
• Accessing Oracle Application Express applications that you
create on the local system.
• Accessing the Oracle XML DB repository. Oracle XML DB is
the Oracle Database XE feature that provides high-
performance, native XML storage and retrieval. Through the
Oracle XML DB repository, you can access XML data with the
HTTP and WebDAV (Web folder) protocols. SeeOracle XML
DB Developer's Guide for more information.

You can disable certain types of connection requests by manually stopping the listener,
and reenable them by restarting the listener. (The listener is automatically started when
you install Oracle Database XE and when you restart the Oracle Database XE host
computer.)

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Table - Connections That Require the Listener

Connection Type Local Connection Remote Connection


Database Not required Required
HTTP Required Required

Viewing Listener Status

You view listener status to determine if the listener is started and to check listener
properties (such as the TCP/IP port numbers that the listener is listening on). You do so
with the Listener Control (lsnrctl) utility.

To view listener status:

1. Do one of the following:


o On Windows: Log in to the Oracle Database XE host computer as the user
who installed Oracle Database XE, and then open a command window.
2. Enter the following command:

LSNRCTL STATUS

If the listener is not started, the command displays the following error messages:

TNS-12541: TNS:no listener


TNS-12560: TNS:protocol adapter error
TNS-00511: No listener

If the listener is started, the command displays a report that looks something like this:

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for 32-bit Windows: Version 11.2.0.2.0 - Production
Start Date 08-MAR-2011 16:12:26
Uptime 0 days 1 hr. 57 min. 59 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Default Service XE
Listener Parameter File
C:\oraclexe\app\oracle\product\11.2.0\server\network\admin\listener.ora
Listener Log File
C:\oraclexe\app\oracle\diag\tnslsnr\user1-pc\listener\alert\log.xml
Listening Endpoints Summary...

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1ipc)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=user1-pc.example.com)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=user1-
pc.example.com)(PORT=8080))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "CLRExtProc" has 1 instance(s).
Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "XEXDB" has 1 instance(s).
Instance "xe", status READY, has 1 handler(s) for this service...
Service "xe" has 1 instance(s).
Instance "xe", status READY, has 1 handler(s) for this service...
The command completed successfully

Stopping the Listener

To stop the listener:

1. Do one of the following:


o On Windows: Log in to the Oracle Database XE host computer as the user
who installed Oracle Database XE, and then open a command window.
2. Enter the following command:

LSNRCTL STOP

The command displays the following output if successful.

On Windows:

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
The command completed successfully

If the listener was already stopped, the command displays one or more TNS: no
listener messages.

Starting the Listener

To start the listener:

1. Do one of the following:


o On Windows: Log in to the Oracle Database XE host computer as the user
who installed Oracle Database XE, and then open a command window.
2. Enter the following command:

LSNRCTL START

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Changing Listener Port Numbers

You would need to change a default listener port number only if there were a port
number conflict with another TCP/IP service. You are given the opportunity to change
listener port numbers during installation (Windows) or configuration (Linux). This
section explains how to change port numbers after installation or configuration. It
contains the following topics:

• "Changing the Listener Port Number for Database Connection Requests"


• "Changing the Listener Port Number for HTTP Connection Requests"

Changing the Listener Port Number for Database Connection


Requests

If you change the listener port number for database connection requests, you must
ensure that all future database connection requests use the new port number. This
means that connection requests such as those discussed in "Connecting Remotely with
the SQL Command Line" must explicitly include the port number.

For example, if you change the port number for database connection requests to 1522,
subsequent the SQL Command Line (SQL*Plus) connect statements must be similar to
the following (assuming a connection from Oracle Database Express Edition Client):

connect system/[email protected]:1522

Example: Changing Listener Port Number for Database Connection Requests

Assume that your Oracle Database XE host computer is named myhost.example.com and
that you want to install a new software package on this computer that requires TCP
port number 1521. Assume also that the port number for that software package cannot
be configured, and that you must therefore resolve the port number conflict by
reconfiguring Oracle Database XE. You decide to change the listener port number for
database connection requests to 1522.

To change the listener port number for database connection requests to 1522:

1. Stop the listener.

See "Stopping and Starting the Listener" for instructions.

2. Open the file listener.ora with a text editor.

Table 4-3 shows the location of this file on each platform.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Table 4-3 Location of the listener.ora File

Platform Location

Linux /usr/lib/oracle/xe/app/oracle/product/11.2.0/server/network/admin/
Windows c:\oraclexe\app\oracle\product\11.2.0\server\NETWORK\ADMIN\

3. Locate the following section of the file:


4. LISTENER =
5. (DESCRIPTION_LIST =
6. (DESCRIPTION =
7. (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
8. (ADDRESS = (PROTOCOL = TCP)(HOST = myhost)(PORT = 1521))
9. )
10. )

Note that the line indicated in bold may or may not be present in the file.

11. Change the text (PORT = 1521) to (PORT = 1522).


12. Save the modified listener.ora file.
13. Start the listener.
14. Start the SQL Command Line and connect to the database as user SYSTEM.
15. Enter the following two commands:

ALTER SYSTEM SET LOCAL_LISTENER =


"(ADDRESS=(PROTOCOL=TCP)(HOST=myhost.example.com)(PORT=1522))";

ALTER SYSTEM REGISTER;

16. Exit the SQL Command Line and run the lsnrctl status command to verify the
port number change.

The new port number should be displayed in the Listening Endpoints Summary
section of the status report, and the report should include the following lines:

Service "XE" has 1 instance(s). Instance "XE", status READY, has 1 handler(s)
for this service...

Changing the Listener Port Number for HTTP Connection Requests

If you change the listener port number for HTTP connection requests, you must ensure
that all future HTTP connection requests use the new port number.

For example, if you change the listener port number for HTTP requests to 8087, you
must use the following URL to access the Oracle Application Express login page locally:

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
http://127.0.0.1:8087/apex
Note:
When you change the listener port number for HTTP, the Get Started menu item on the
desktop can no longer open the Database Home Page. The following procedure contains an
optional step that explains how to modify this menu item to function with the new port number.

To change the listener port number for HTTP connection requests:

1. Do one of the following:


o On Windows: Log in to the Oracle Database XE host computer as the user
who installed Oracle Database XE, and then open a command window.
2. Ensure that the listener is started.
3. Enter the following command at the operating system prompt to start the SQL
Command Line:

SQLPLUS /NOLOG

4. At the SQL Command Line prompt, enter the following command:

CONNECT SYSTEM/password

where password is the SYSTEM password that you set upon installation (Windows)
or configuration (Linux) of Oracle Database XE.

5. At the SQL Command Line prompt, enter the following command:

EXEC DBMS_XDB.SETHTTPPORT(nnnn);

where nnnn represents the new port number to use for HTTP connection
requests. Be certain that you select a port number that is not already in use.

For example, to use port number 8087 for HTTP connection requests, enter this
command:

EXEC DBMS_XDB.SETHTTPPORT(8087);

If the command is successful, the following message is displayed:

PL/SQL procedure successfully completed.

6. Exit the SQL Command Line (by entering the exit command) and view listener
status to verify the port number change.
7. (Optional) To enable the Get Started command on the desktop to work with the
new port number, change the port number in the script or shortcut that this
command uses. The following table shows the script or shortcut that you must
change on each platform.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Platform Script or Shortcut to Change for Changing the Listener Port for HTTP Connection Requests

Linux /usr/lib/oracle/xe/app/oracle/product/11.2.0/server/config/scripts/DatabaseHomePage.sh

Windows C:\oraclexe\app\oracle\product\11.2.0\server\Database_homepage

Enabling Remote HTTP Connection to the Database

After installation, database connection requests with the HTTP protocol are enabled
only on the computer on which you installed Oracle Database XE. This means that
remote users cannot access applications that you create using Oracle Application
Express on the local system. As an administrator, you can enable HTTP access for
remote users, thereby enabling them to access the Oracle Database XE graphical user
interface.

Security Note:
With remote HTTP access to Oracle Database XE, all information exchanged between the
browser and the database is in clear text—that is, unencrypted—including database user names
and passwords. If this is cause for concern, do not enable remote HTTP connection to the
database.

Enabling Remote HTTP Connection with the SQL Command Line

To enable remote HTTP connection requests using the SQL Command Line:

1. Start the SQL Command Line and connect to the database as user SYSTEM.
Provide the SYSTEM password that you assigned upon installation (Windows) or
configuration (Linux) of Oracle Database XE.
2. At the SQL Command Line prompt, enter the following command:

EXEC DBMS_XDB.SETLISTENERLOCALACCESS(FALSE);

Managing Database Memory

Automatic Memory Management

Oracle Database XE uses automatic memory management, which you cannot


disable. With automatic memory management in Oracle Database XE, the database

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
dynamically exchanges memory between the System Global Area (SGA) and the
instance Program Global Area (PGA) as needed to meet processing demands. The
database also dynamically tunes the sizes of the individual SGA components and the
sizes of the individual PGAs.

There are two types of memory that the Oracle instance allocates:

• System global area (SGA)—A shared memory area that contains data buffers and
control information for the instance. The SGA is divided into separate buffer
areas and data pools. These are described in "SGA Components".
• Program global area (PGA)—A memory area used by a single Oracle server
process. An Oracle server process is a process that services a client's requests.
Oracle Database XE creates a new server process whenever it receives a new
database connection request. Each new server process then allocates its own
private PGA area. The PGA is used to process SQL statements and to hold logon
and other session information.

Changing SGA and PGA Aggregate Sizes

Suppose you just upgraded the computer running Oracle Database Express Edition
(Oracle Database XE) to add 1 gigabyte (GB) or more of system memory, and you want
to increase the memory for the database by 250 MB. Of this 250 MB, you want to add
200 MB to the SGA and 50 MB to the PGA Aggregate.

The SHOW SGA SQL command will show you the SGA memory allocations. In order to
execute SHOW SGA you must be connected with the special privilege SYSDBA .

SQL> connect / as sysdba


Connected.
SQL> show sga

Total System Global Area 1610612736 bytes


Fixed Size 2084296 bytes
Variable Size 1006633528 bytes
Database Buffers 587202560 bytes
Redo Buffers 14692352 bytes
The granule size that is currently being used for the SGA for each component can be
viewed in the view V$SGAINFO. The size of each component and the time and type of
the last resize operation performed on each component can be viewed in the
view V$SGA_DYNAMIC_COMPONENTS.

SQL> select * from v$sgainfo;


More...

NAME BYTES RES


-------------------------------- ---------- ---

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Fixed SGA Size 2084296 No
Redo Buffers 14692352 No
Buffer Cache Size 587202560 Yes
Shared Pool Size 956301312 Yes
Large Pool Size 16777216 Yes
Java Pool Size 33554432 Yes93
Streams Pool Size 0 Yes
Granule Size 16777216 No
Maximum SGA Size 1610612736 No
Startup overhead in Shared Pool 67108864 No
Free SGA Memory Available 0

11 rows selected.

You can dynamically change the size of the Database Buffer Cache with the ALTER
SYSTEM command like the one shown here:

ALTER SYSTEM SET DB_CACHE_SIZE = 96M;

To accomplish this, you can the DBA navigator in SQL Developer to check the current
values of the SGA_TARGET and PGA_AGGREGATE TARGET initialization parameters,
and then use the ALTER SYSTEM command to reset the values of these parameters, as
follows:

1. In SQL Developer, click View, then DBA to display the DBA navigator.
2. If a connection to the SYSTEM user does not already exist in that navigator, add
one by clicking the Connections node, selecting Add Connection, and
completing the actions for adding the SYSTEM account connection.
3. In the DBA navigator, expand the SYSTEM connection, expand Database
Configuration, and click Initialization Parameters.

Note the current values for pga_aggregate_target and sga_target, and calculate
the desired new values. Assume for this example that the desired new values are
140 megabytes for pga_aggregate_target and 472 megabytes for sga_target.

4. In the Connections navigator, select the SYSTEM connection; and if a SQL


Worksheet is not already open for that connection, right-click SYSTEM and
select Open SQL Worksheet.
5. In the SQL Worksheet for the SYSTEM connection, enter the following command
lines:

ALTER SYSTEM SET pga_aggregate_target = 140 M;


ALTER SYSTEM SET sga_target = 472 M;

6. In the SQL Worksheet for the SYSTEM connection, click the Run Script icon to
execute these statements.
7. At the next convenient time, shut down and restart the database to enable the
SGA size changes to take effect.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Managing Database Storage

Monitoring Storage Space Usage

Because Oracle Database Express Edition (Oracle Database XE) is limited to just over
four gigabytes (GB) of user data, your most important storage management task is
monitoring the amount of free storage space and storage space used for any
tablespaces used for storing user data.

To check this usage information:

1. In SQL Developer, click the Reports navigator tab, and expand the hierarchy as
follows: All Reports, then Data Dictionary Reports, then Database
Administration, then Storage.
2. Under Storage, click Free Space, then select a database connection for a
privileged user such as SYSTEM, as shown in Figure 6-2.

Figure : Selecting a Connection for the Free Space Report

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University

Description of "Figure 6-2 Selecting a Connection for the Free Space Report"

3. Click OK in the Select Connection dialog box to display the Free Space report,
which is shown in Figure 6-3.

Figure : Free Space Report

Description of "Figure Free Space Report"

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
You are interested in the USERS tablespace because it is typically used only for
user data, not for Oracle-maintained system data. In Figure 6-3, only about 2.6
percent (0.025625) of the available allocated space for the USERS tablespace is
actually being used.

If you notice that space remaining is becoming low, you can attempt to free some
space by doing the following:

1. For each schema:


a. Log in as the schema owner.
b. Drop (delete) unused database objects.
c. Purge the recycle bin.
2. Compact storage.

If this procedure does not free a significant amount of space and you expect space
requirements to continue to grow, you must consider upgrading to Oracle Database
Standard Edition or Enterprise Edition.

Compacting Storage

If you notice that space remaining in the database is becoming low, you can compact
storage. Compacting storage attempts to recover unused fragmented free space in the
database. Depending on the state of the database, compacting storage may or may not
recover unused space.

Viewing Tablespaces

You can use the Oracle Database XE graphical user interface to view a list of
tablespaces in the database, view tablespace properties, and view datafile properties.

To view Oracle Database XE tablespaces:

1. From the Oracle Database 11g Express Edition menu, select Get Started.
2. Click Storage.

If prompted for administrator credentials, enter the SYSTEM user name and
password or another administrator user name and password, and then
click Login.

The Storage page appears.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University

Description of the illustration xe_tablespaces.jpg

Depending on datafile settings, a tablespace can grow beyond its currently


allocated size. For example, the USERS tablespace may start with one datafile with
an initially allocated size of 100 megabytes (MB), but the datafile can autoextend
as needed, 10 MB at a time.

3. (Optional) Click a tablespace name to view information on that tablespace's


segments.

Viewing Redo Log Files

You can use the DBA navigator in SQL Developer to view location and status
information for the online redo log files.

1. In SQL Developer, if the DBA navigator is not visible, click View, then DBA.
2. If the DBA navigator does not already include a connection to the SYSTEM user,
right-click Connections in the DBA navigator, select Add Connection, and select
the connection for SYSTEM. (This does not create a new database connection; it
just makes the SYSTEM connection visible in the DBA navigator.)
3. Expand the SYSTEM connection in the DBA navigator; then expand Storage and
select Redo Log Groups.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University

Description of the illustration redo_log_file.jpg

4. You can select any redo log group to see, for each redo log file in the group, its
location, type, and whether it was created in the flash recovery area.

Changing the Flash Recovery Area Size

Oracle Database Express Edition (Oracle Database XE) stores database backups, online
redo log files, and archived redo log files in the flash recovery area.

To change the flash recovery area size:

1. Using the SQL Command Line, log in and connect to the database as SYSDBA.
2. Enter the following command at the SQL Command Line prompt:
ALTER SYSTEM SET DB_RECOVERY_FILE_DEST_SIZE = new_size;

where new_size can be of the format nK (kilobytes), nM (megabytes)


or nG (gigabytes).

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;

3. Enter the following command to exit the SQL Command Line:


EXIT

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Monitoring the Database

As an administrator, you can monitor the activities of the database and its users. You
can use this information for tuning, troubleshooting, and more.

Monitoring Sessions

You can use SQL Developer to monitor the current database sessions. This enables you
to determine the users who are currently logged in to the database and what
applications they are running.

You can also kill a session—to cause it to be disconnected and its resources to be
relinquished.

Viewing Sessions

To view sessions:

1. In SQL Developer, click Tools, then Monitor Sessions.


2. In the Select Connection dialog box, select a connection to SYSTEM (or another
account with full DBA privileges)

A Sessions tab is displayed. Figure shows part of the display.

Figure : Monitor Sessions Page

Description of "Figure Monitor Sessions Page"

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
3. (Optional) Right-click in any row in the display, and explore the options available
as shown in the context menu commands, which include Trace Session, Kill
Session, and Find/Highlight (to search for rows in the grid that contain a
specified text string).

Killing (Terminating) a Session

You can use SQL Developer to kill (terminate) a database session. This logs off and
disconnects the user running the session. If the user is processing a transaction when
you kill the session, the transaction is rolled back.

Reasons to kill a session include the following:

• The session is not responding.


• You want to perform an administrative function that requires all users to log off
first, but the user is not available to end his or her session.

To kill a session:

1. In SQL Developer, click Tools, then Monitor Sessions.


2. In the Select Connection dialog box, select a connection to SYSTEM (or another
account with full DBA privileges)
3. Right-click in the row for the session to be terminated, and select Kill Session.

Monitoring the Top SQL Statements

The "top" SQL statements represent the SQL statements that are executed most often,
that use more system resources than other SQL statements, or that use system
resources more frequently than other SQL statements. Viewing the top SQL statements
reports that are available in SQL Developer enables you to focus your SQL tuning
efforts on the statements that can have the most impact on database performance.

Note:
Some of the statements that appear in the top SQL statements report may be from Oracle
Database XE internal operations, including automatically scheduled internal database jobs (such
as statistics gathering jobs).

To monitor the top SQL statements:

1. In SQL Developer, click the Reports navigator tab, and expand the hierarchy as
follows: All Reports, then Data Dictionary Reports, then Database
Administration, then Top SQL.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University

Description of the illustration top_sql_reports.jpg

2. Under Top SQL, select any of the listed "Top SQL by" reports: Buffer Gets,
Buffer Gets/Rows Proc, CPU, Disk Reads, Executions, or Waits.

If you are asked to select a connection, select one for SYS AS SYSDBA (the one
named /as sysdba if you created local connections automatically, as explained
in"Logging In and Connecting to the Database as SYSDBA").

Each available report lists the top SQL statements in that category, with the
following information for each statement: SQL (the SQL statement),
CPU_Seconds, Disk_Reads, Executions, Buffer_gets/rows_proc,
Buffer_gets/executions, Elapsed_Seconds, Module.

Monitoring Long Operations

The Active Sessions report in SQL Developer lists active sessions and include the
current "up time" for each, which you can check to see if any are running much longer
than you would expect.

To monitor long operations:

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
1. In SQL Developer, click the Reports navigator tab, and expand the hierarchy as
follows: All Reports, then Data Dictionary Reports, then Database
Administration, then Sessions.
2. Under Sessions, select Active Sessions.

If you are asked to select a connection, select one for SYS AS SYSDBA (the one
named /as sysdba if you created local connections automatically, as explained
in"Logging In and Connecting to the Database as SYSDBA").

3. Check the UP_TIME value for each listed session, and note any that you
consider to be longer than desired or expected.

Viewing Database Version and Globalization Information

Viewing Database Version Information

To view database version information:

1. In SQL Developer, click the Reports tab on the left, near the Connections
navigator. (If this tab is not visible, click View, then Reports.)
2. In the Reports navigator, expand Data Dictionary Reports.
3. Under Data Dictionary Reports, expand About Your Database.
4. Under About Your Database, click Version Banner.

The Version Banner report is displayed, as shown in Figure .

Figure : Version Banner Report

Description of "Figure Version Banner Report"

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Viewing Database Globalization Information

To view database globalization (national language support, or NLS) parameter


information:

1. In SQL Developer, click the Reports tab on the left, near the Connections
navigator. (If this tab is not visible, click View, then Reports.)
2. In the Reports navigator, expand Data Dictionary Reports.
3. Under Data Dictionary Reports, expand About Your Database.
4. Under About Your Database, click National Language Support Parameters.

The National Language Support Parameters report is displayed, as shown


in Figure .

Figure : National Language Support Parameters Report

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Exporting and Importing Metadata and Data
Using SQL Developer for Exporting and Importing

SQL Developer provides convenient wizards for exporting and importing metadata and
data:

• To export metadata or data, or both, use the Export Wizard: click Tools,
then Database Export.
• To import metadata or data, or both, use an appropriate method depending on
how the material to be imported was created, or the format of the data to be
imported. This method might be running a script file, or using the Data Import
Wizard to import from a data file (such as a .csv file or a Microsoft Excel .xls file).

Exporting Metadata and Data for a Table

Assume that you want to export the REGIONS table, which is part of the HR sample
schema, so that it can be created, along with its data, in another schema (either in the
same Oracle database or another Oracle database).

To unload the REGIONS table:

1. In SQL Developer, click Tools, then Database Export. Figure 10-1 shows the first
page of the Export Wizard, but with entries reflecting selections that you will
make.

Figure : Export Wizard: Source/Destination

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University

Description of "Figure : Export Wizard: Source/Destination"

2. Accept the default values for the Source/Destination page options, except as
follows:

Connection: Select HR.

Show Schema: Deselect (uncheck) this option, so that the HR schema name is
not included in CREATE and INSERT statements in the .sql script file that will be
created. (This enables you to re-create the table in a schema with any name,
such as one not named HR.)

Save As location: Enter or browse to a desired folder on your local hard drive,
and specify the file name for the script file. (In the figure, this file
isC:\temp\export.sql.) The script file containing CREATE and INSERT statements
will be created in this location.

Note:

For explanations of the options on this or any other wizard page, click the Help button.

For example, Format has other possible values besides the default insert , which
causes SQL INSERT statements to be included to insert the data. Other values
include loader to cause SQL*Loader files to be created, and xls to cause a
Microsoft Excel .xls file to be created.

3. Click Next.
4. On the Types to Export page, deselect Toggle All, then
select only Tables (because you only want to export a table).
5. Click Next.
6. On the Specify Objects page, click Lookup, then double-click the REGIONS table on
the left to move it to the right-hand column. Figure 10-2 shows the result of
these actions.

Figure : Export Wizard: Specify Objects

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University

Description of "Figure : Export Wizard: Specify Objects"

7. Click Next.
8. On the Specify Data page, accept the defaults and click Next.

By default, all data from the specified table or tables is exported; however, if you
want to limit the data to be exported, you can specify one or more
"WHERE clauses" in the bottom part of this page.

9. On the Summary page, review the information; and if it is what you want,
click Finish. (Given what you specified, this causes the export script to be
created asC:\temp\export.sql.)

If you need to make any changes, go back to the appropriate page or pages and
make them, and then move forward to the Summary page again.

Importing Metadata and Data Using a Script File

Assume that you wanted to re-create the REGIONS table that you exported in "Example:
Exporting Metadata and Data for a Table", but in a different schema. This other schema
can be an existing one or one that you create.

For example, assume that you created a user named NICK following the instructions
in "Example: Creating a User". To re-create the REGIONS table in the schema of
userNICK by invoking the script in C:\temp\export.sql follow these steps using SQL
Developer:

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
1. If you have not already created a database connection for NICK, create the
connection.
2. Open the NICK connection.
3. In the SQL Worksheet for the NICK connection, type the following:
4. @c:\temp\export.sql
5. Click the Run Script icon.

The Script Output pane shows that the REGIONS table has been created and four
rows have been inserted.

6. In the Connections navigator, expand the Tables node under the NICK connection.
You now see the REGIONS table.
7. Optionally, click the REGIONS table in the Connections navigator, and examine the
information under the Columns and Data tabs in the main display area.

Exporting Data to a Microsoft Excel File

Assume that you want to export only the data from the REGIONS table, which is part of
the HR sample schema, so that the data can be imported into a table with the same
column definitions. This might be a REGIONS table in another schema (either in the same
Oracle database or another Oracle database).

You sue the same Database Export wizard, but export only the data, and not the DDL
(Data Definition Language statements for creating database objects).

To export the data the REGIONS table:

1. In SQL Developer, click Tools, then Database Export. Figure shows the first
page of the Export Wizard, but with entries reflecting selections that you will
make.

Figure : Export Wizard: Source/Destination Specifying Data Export


Only

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University

Description of "Figure : Export Wizard: Source/Destination Specifying Data Export Only"

2. Accept the default values for the Source/Destination page options, except as
follows:

Connection: Select HR.

Export DDL: Deselect (uncheck) this option. If a .sql script file is generated
(which will not happen in this example), it will not contain any CREATE statements,
but only INSERT statements.

Format: Select xls to have the data saved to a Microsoft Excel .xls file.

Save As location: Enter or browse to a desired folder on your local hard drive,
and specify the file name for the .xls file. (In the figure, this file
isC:\temp\export.xls.)

3. Click Next.
4. On the Types to Export page, deselect Toggle All, then
select only Tables (because you only want to export data for a table).
5. Click Next.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
6. On the Specify Objects page, click Lookup, then double-click the REGIONS table on
the left to have it appear in a row in the bottom part of the page. Figure shows
the result of these actions.

Figure : Export Wizard: Specify Objects for Exporting Data

Description of "Figure Export Wizard: Specify Objects for Exporting Data"

By default, all data from the specified table or tables is exported; however, if you
want to limit the data to be exported, you can specify one or more
"WHERE clauses" in the bottom part of this page.

7. Click Next.
8. On the Summary page, review the information; and if it is what you want,
click Finish. (Given what you specified, this causes the data in the REGIONS table
to be exported to the file C:\temp\export.xls.)

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
If you need to make any changes, go back to the appropriate page or pages and
make them, and then move forward to the Summary page again.

Importing Data from a Microsoft Excel File

Assume that you wanted to import the data that was exported in "Example: Exporting
Data to a Microsoft Excel File", into a new table that has the same column definitions as
the original (REGIONS) table.

For example, assume that you created a user named NICK following the instructions
in "Example: Creating a User". This user wants to take the exported data, add one row
in the Excel file, and import it into a new table that has the same column definitions as
the REGIONS table. (This example is trivial, and adding a row to the Excel file may not be
typical, but it is presented merely to illustrate some capabilities.)

To accomplish these goals, follow these steps:

1. In SQL Developer, if you have not already created a database connection


for NICK, create the connection.
2. Open the NICK connection.
3. In the SQL Worksheet for the NICK connection, type the following:
4. create table new_regions ( region_id number primary key, region_name varchar2(25));
5. Click the Run Script icon.

The Script Output pane shows that the NEW_REGIONS table has been created.

6. In the Connections navigator, expand the Tables node under the NICK connection.
You now see the NEW_REGIONS table.

If you do not see the NEW_REGIONS table, disconnect from NICK (right-click NICK in the
Connections navigator and select Disconnect) and connect again, and expand the
Tables node.

7. Using Microsoft Excel, open the file containing the exported data (for example,
c:\temp\export.xls), and optionally add one or more rows.

Figure shows the original file with one row added for the Antarctica region.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Figure : Microsoft Excel File with Exported Data (Modified)

Description of "Figure : Microsoft Excel File with Exported Data (Modified)"

8. Save and close the Microsoft Excel .xls file.


9. In SQL Developer, in the Connections navigator display for NICK, right-lick
the NEW_REGIONS table and select Import Data.
10. In the dialog box that is displayed, navigate to the c:\temp folder, select export.xls,
and click Open.
11. In the Data Import Wizard, accept all the defaults; click Next on each page until
Summary, and click Finish there. (For information about the options on any
wizard page, click the Help button.)

The data from the .xls file is loaded into the NEW_REGIONS table and is committed.

Backing Up and Recovering

Enabling ARCHIVELOG Mode for Media Failure Protection

This section describes how to turn on ARCHIVELOG mode so that your database is fully
protected not only against operating system and Oracle instance failure, but also
against media (disk) failure. The following topics are covered:

Viewing the Current ARCHIVELOG Mode Setting

To view the current ARCHIVELOG mode setting:

1. Using the SQL Command Line, log in to the database and connect as SYSDBA, as
described in "Logging In and Connecting to the Database as SYSDBA".
2. Enter the following command:
3. SELECT log_mode FROM v$database;

The LOG_MODE value will be either ARCHIVELOG (that is, on) or NOARCHIVELOG (that is,
off).

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Turning on ARCHIVELOG Mode

Turning on ARCHIVELOG mode is a one-time operation. After it is turned on, it remains on


until you turn it off. Restarting the database does not change the ARCHIVELOGmode
setting.

Note:
If you turn on ARCHIVELOG mode, you must perform regular backups of the database to avoid
completely filling the flash recovery area. A completely filled flash recovery area can lead to
database failure.

To turn on ARCHIVELOG mode:

1. Using the SQL Command Line, log in to the database and connect as SYSDBA, as
described in "Logging In and Connecting to the Database as SYSDBA".
2. At the SQL Command Line prompt, enter the following command:
SHUTDOWN IMMEDIATE

If the command is successful, it displays the following output.


Database closed.
Database dismounted.
ORACLE instance shut down.

3. At the SQL Command Line prompt, enter the following command:


STARTUP MOUNT

If the command is successful, it displays the following output. (System global


area sizes will vary depending on the amount of physical memory in your Oracle
Database XE host computer.)
ORACLE instance started.

Total System Global Area 803500032 bytes


Fixed Size 1386556 bytes
Variable Size 222300100 bytes
Database Buffers 574619648 bytes
Redo Buffers 5193728 bytes
Database mounted.

4. Enter the following command:


ALTER DATABASE ARCHIVELOG;

If the command is successful, it displays the following output:


Database altered.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
5. Enter the following command:
ALTER DATABASE OPEN;

If the command is successful, it displays the following output:


Database altered.

The database is now running with the new ARCHIVELOG mode setting.

6. 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;

Note:
To turn off ARCHIVELOG mode (that is, to set NOARCHIVELOG mode), follow the previous
steps 1 through 5, but enter the following command in Step 4:
ALTER DATABASE NOARCHIVELOG;

Caution:
When you change the ARCHIVELOG mode setting for your database, all of your existing backups
become unusable. You must immediately perform a backup after changing the ARCHIVELOG mode,
as described in "Backing Up the Database".

Backing Up the Database

Note:
If ARCHIVELOG mode is on, the script performs an online backup. The database is available during
the backup.

If ARCHIVELOG mode is off, the script performs an offline backup. The database is shut
down during the backup and restarted afterwards. Your applications are unavailable
during the backup.

To back up the database:

1. Do one of the following:


o On Windows: Log in to the Oracle Database XE host computer as a user
who is a member of the ORA_DBA user group. This is typically the user that
installed Oracle Database XE.
2. Do one of the following:

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
o On Windows: Click Start, point to Programs (or All Programs), point
to Oracle Database 11g Express Edition, and then select Backup
Database.

A console window opens so that you can interact with the backup script.

If running in ARCHIVELOG mode, the script displays the following output:


Doing online backup of the database.

If running in NOARCHIVELOG mode, the script displays the following output:


Warning: Log archiving (ARCHIVELOG mode) is currently disabled. If you restore the
database from this backup, any transactions that take place between this backup and the
next backup will be lost. It is recommended that you enable ARCHIVELOG mode before
proceeding so that all transactions can be recovered upon restore. See the section
'Enabling ARCHIVELOG Mode...' in the online help for instructions. Backup with log
archiving disabled will shut down and restart the database. Are you sure [Y/N]?

3. If prompted, enter y and press Enter to confirm the database shutdown and
begin the backup.

After the backup is complete, the script displays the following output:
Backup of the database succeeded.
Log file is at location
Press ENTER key to exit

where location is the location of the log file.

4. Press Enter to close the Backup Database window.

Restoring and Recovering the Database

You restore and recover the database with the supplied restore script. The instructions
in this section are based on the following assumptions:

• A software failure, media (disk) failure, or operator error caused the loss or
corruption of one or more database files, rendering the database unusable.
• In the flash recovery area, the backup sets and, if in ARCHIVELOG mode, archived
logs, are intact and available.
• If in ARCHIVELOG mode, the online redo logs are intact and available.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Note:

If they are not available, the database is restored to the point of the last transaction
included in an archived log.

• The Oracle Database XE host computer and operating system are operational.
• The Oracle Database XE installed software (binaries) are intact and operational.

In situations where not all of these assumptions are true, before proceeding with the
following steps to restore and recover the database, you may first have to complete one
or more of the following tasks: repair or replace computer hardware, reinstall operating
system software, or reinstall Oracle Database XE. After reinstalling Oracle Database XE,
if your flash recovery area was previously on a separate disk from your Oracle Database
XE installation and is still available, you must specify the location of the flash recovery
area so that the restore script can find the required files. See "Setting Flash Recovery
Area Location and Size" for instructions.

To restore the database:

1. Do one of the following:


o On Windows: Log in to the Oracle Database XE host computer as a user
who is a member of the ORA_DBA user group. This is typically the user that
installed Oracle Database XE.
o On Linux: Log in to the Oracle Database XE host computer as a user who
is a member of the dba user group. This is typically the oracle user.
2. Do one of the following:
o On Windows: Click Start, point to Programs (or All Programs), point
to Oracle Database 11g Express Edition, and then select Restore
Database.

A console window opens so that you can interact with the restore script. The
script displays the following output:
This operation will shut down and restore the database. Are you sure [Y/N]?

3. Enter y and press Enter to confirm the database restore.

The database is shut down, and the script runs RMAN to restore the database and,
if running in ARCHIVELOG mode, recover all changes since the last backup.

Note:

In some situations, such as when you run the Restore Database command in a new
Oracle Database XE installation before having backed up, the restore script may prompt
you for the location of the flash recovery area:

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
Enter the flash recovery area location:

If so prompted, enter the complete path to the location of the flash recovery
area. (The default location for each platform is listed in Table 6-2.) The restore
script then restores the database from the backup files in this location.

If the restore and recovery process is completed successfully, the database is


opened again. The script then displays the following output:
Restore of the database succeeded.
Log file is at location
Press any key to continue . . .

where location is the location of the log file.

If the restore and recovery process fails, messages describing the error are
displayed.
==================== ERROR =============================
Restore of the database Failed.
RMAN Error - See log for details
Log file is at location
==================== ERROR =============================

Refer to the log file for details on the cause of the error.

4. Press Enter to close the Restore Database window.

Recovering Dropped Tables

When you drop (delete) a table, the database does not immediately remove the space
associated with the table. Instead, the database renames the table and places it and
any dependent objects in a recycle bin, where, in case the table was dropped in error, it
can be recovered at a later time.

About the Recycle Bin

The recycle bin is a data dictionary table containing information about dropped
objects. Dropped objects and any dependent objects (such as indexes, constraints,
nested tables, and so on) are not removed and still occupy space until you purge them
from the recycle bin or until they are automatically purged by the database when
available space becomes low.

You can restore objects from the recycle bin, which is equivalent to "undropping"
them. When you restore an object, it is returned to the state that it was in before the
drop operation. When you restore a table, all of the table's dependent objects are also
automatically restored.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
You can use SQL Developer to view the contents of the recycle bin, restore dropped
objects, and purge objects from the recycle bin. To view, purge, or restore objects
owned by a particular user, you must log in as that user.

Note:
If you log in and connect as SYSDBA with the SQL Command Line (SQL*Plus), you can view,
restore, and purge objects owned by other users. See Oracle Database Administrator's
Guide for details.

Viewing Recycle Bin Contents

To view recycle bin contents:

1. In SQL Developer, open a database connection to the schema of interest.


2. In the Connections navigator, expand the connection and select the Recycle
Bin node.
3. (Optional) Click a table name to see its properties.

Restoring a Table from the Recycle Bin

Suppose you drop the JOB_HISTORY table in the HR schema, and then decide that you
want to recover it. You can recover (undrop) the table by restoring it from the recycle
bin.

To drop the JOB_HISTORY table and then restore it from the recycle bin:

1. In SQL Developer, connect to the HR user.

Note:

You must have previously unlocked the HR account and assigned it a password.
See "Altering Users" and "Locking and Unlocking User Accounts" for more information.

2. In the Connections navigator under HR, expand Tables.


3. Right-click JOB_HISTORY and select Drop.
4. In the Drop dialog box, click Apply.
5. In the Connections navigator, right-click Recycle Bin and select Refresh.

The JOB_HISTORY table is listed in the Recycle Bin. You can now proceed to restore
it ("undrop" it) or to purge it (delete it completely).

6. To restore the table, in the Recycle Bin, right-click JOB_HISTORY (and no other
objects), and select Flashback to Before Drop.

Dr. Abdul Khader Jilani Saudagar


Information Systems Department, Imam University
7. In the Flashback to Before Drop dialog box, for Flashback to Object
Name specify the desired name for the restored table: JOB_HISTORY
8. Click Apply.
9. To see JOB_HISTORY now listed among the tables, right-click the Tables node
and select Refresh.

Purging the Recycle Bin

When you drop objects, space is not freed until you purge the recycle bin, or until the
database automatically purges the recycle bin when it detects a low space condition.
You can purge objects from the recycle bin.

Purging an Object from the Recycle Bin

To purge an object from the recycle bin:

1. In SQL Developer, connect to the database user that owns the object.
2. In the Connections navigator under that connection, expand Recycle Bin.
3. Right-click object that you want to purge and select Purge.
4. In the Purge confirmation box, click Apply.

Dr. Abdul Khader Jilani Saudagar

You might also like