Oracle DBA LAB Manual
Oracle DBA LAB Manual
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
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.)
SQL> EXIT
• 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.
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
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.
The NORMAL clause of the SQL*Plus SHUTDOWN command is optional because this is the
default shutdown method
The next startup of the database will not require any instance recovery procedures.
• 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.
• No new connections are allowed, nor are new transactions allowed to be started,
after the statement is issued.
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.
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.
• 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.
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> STARTUP
SQL> SHUTDOWN IMMEDIATE
SQL> EXIT
On Windows: Click Start, point to Programs (or All Programs), point to Oracle Database
11g Express Edition, and then select Run SQL Command Line.
CONNECT username/password
To start the SQL Command Line from a terminal session or command window and
connect locally:
SQLPLUS /NOLOG
CONNECT username/password
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]
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
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:
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
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.
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.
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.
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:
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.)
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
User Created
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.
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.
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.
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.
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.
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.
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.
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.)
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.
LSNRCTL STATUS
If the listener is not started, the command displays the following error messages:
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...
LSNRCTL STOP
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.
LSNRCTL START
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:
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
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:
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\
Note that the line indicated in bold may or may not be present in the file.
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...
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:
SQLPLUS /NOLOG
CONNECT SYSTEM/password
where password is the SYSTEM password that you set upon installation (Windows)
or configuration (Linux) of Oracle Database XE.
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);
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.
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
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.
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);
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.
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 .
11 rows selected.
You can dynamically change the size of the Database Buffer Cache with the ALTER
SYSTEM command like the one shown here:
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.
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.
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.
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.
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.
If you notice that space remaining is becoming low, you can attempt to free some
space by doing the following:
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.
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.
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.
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.
Oracle Database Express Edition (Oracle Database XE) stores database backups, online
redo log files, and archived redo log files in the flash recovery area.
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;
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;
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:
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.
To kill a session:
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).
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.
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.
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.
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.
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.
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.
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).
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).
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.
2. Accept the default values for the Source/Destination page options, except as
follows:
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.
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.
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:
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.
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).
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.
2. Accept the default values for the Source/Destination page options, except as
follows:
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.
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.)
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.)
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.
The data from the .xls file is loaded into the NEW_REGIONS table and is committed.
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:
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).
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.
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
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".
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.
A console window opens so that you can interact with the backup script.
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
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.
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.
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]?
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:
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 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.
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.
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.
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.
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:
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.
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.
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.
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.