Oracle DBA Commands
Oracle DBA Commands
This appendix describes the Server Manager DBA commands available in line mode.
These commands can also be used in a SQL Worksheet, although some of these
commands behave differently when used in a worksheet.
DBA Commands
The DBA commands described in this appendix are:
@ (at symbol)
ARCHIVE LOG
CONNECT
DESCRIBE
DISCONNECT
EXECUTE
EXIT
PRINT
RECOVER
REMARK
SET
SHOW
SHUTDOWN
SPOOL
STARTUP
VARIABLE
Note:
@ (at symbol)
Purpose
You must have previously created the script and stored it as an operating system file.
Syntax
@ command ::=
where:
scriptname
The name of an operating system file that contains a script of statements recognized
by Server Manager.
Line Mode Behavior
If you omit the scriptname argument, you for are prompted for the script name.
Usage Notes
This command enables you to run scripts of statements. To insert Comments in the
script, use the REMARK command described in REMARK on page -17 . To spool the
output, use the SPOOL command before running or within the script. The SPOOL
command is described in SPOOL on page -30.
Do not use the @ command alone within a script unless you specify the full path
name of the script.
To run other scripts from within a script, you can use the @@ command. In the
original script include the line @@second_scriptname to run another script
called second_scriptname. The @@ command indicates that the second script is in the
same directory as the original script.
Additional Information: For information about the standard file selection dialog box
for your system, see your operating system-specific documentation.
ARCHIVE LOG
Purpose
Start or stop automatic archiving of online redo log files, manually (explicitly) archive
specified redo log files, or display information about redo log files.
Note:
This command applies only to the current instance. To specify archiving for a
different instance or for all instances in a Parallel Server, use the SQL command
ALTER SYSTEM.
Prerequisites
where:
LIST
Requests a display that shows the range of redo log files to be archived, the current
log file group's sequence number, and the current archive destination (specified by
either the optional command text or by the initialization parameter
LOG_ARCHIVE_DEST).
If you are using both ARCHIVELOG mode and automatic archiving, the display
might appear like:
Database log mode Archive Mode
Automatic archival Enabled
Archive destination DISK9:ARCH
Oldest online log sequence 30
Next log sequence to archive 33
Current log sequence 33
Because the log sequence number of the current log group and the next log group to
archive are the same, automatic archival has archived all log groups up to the current
one.
If you are using ARCHIVELOG but have disabled automatic archiving, the last three
lines might look like:
Oldest online log sequence 30
Next log sequence to archive 30
Current log sequence 33
If you are using NOARCHIVELOG mode, the "next log sequence to archive" line is
suppressed.
The log sequence increments every time LGWR begins to write to another redo log
file group; it does not indicate the number of logs being used. Every time an online
redo log file group is reused, the contents are assigned a new log sequence number.
STOP
Disables automatic archival. If the instance is still in ARCHIVELOG mode and all
redo log file groups fill, database operation is suspended until a redo log file is
archived (for example, until you enter the command ARCHIVE LOG NEXT or
ARCHIVE LOG ALL).
START
Enables automatic archiving. Starts the background process ARCH, which performs
automatic archiving as required. If ARCH is started and a filename is supplied, the
filename becomes the new default archive destination.
Manually archives the next online redo log file group that has been filled but not yet
archived.
ALL
Manually archives all filled, but not yet archived, online log file groups.
integer
Causes archival of the online redo log file group with log sequence number n. You
can specify any redo log file group that is still online. An error occurs if the log file
cannot be found online or the sequence number is not valid. This option can be used
to re-archive a log file group.
`destination'
If not specified in the command line, the archive destination is derived from the
initialization parameter LOG_ARCHIVE_DEST. The command ARCHIVE LOG
START 'destination' causes the specified device or directory to become the new
default archive destination for all future automatic or manual archives. A destination
specified with any other option is a temporary destination that is in effect only for the
current (manual) archive. It does not change the default archive destination for
subsequent automatic archives.
If an online redo log file group fills and none are available for reuse, database
operation is suspended. The condition can be resolved by archiving a log file group.
Examples
Starts up the archiver process and begins automatic archiving, using the archive
destination specified in LOG_ARCHIVE_DEST.
ARCHIVE LOG STOP
Archives the log file group with the sequence number 1001 to the destination
specified. 'TEMP' specifies the prefix of the filename on the destination device; the
remainder of the filename is dependent on the initialization parameter
LOG_ARCHIVE_FORMAT, which specifies the filename format for archived redo
log files.
CONNECT
Purpose
where:
username
Any valid Oracle username for the current database. It can be a null string. If neither
username nor INTERNAL is specified, you are prompted for a username and
password.
password
The password corresponding to the specified username. Password can be a null string.
instance-path
The AS clause allows privileged connections by users who have been granted
SYSOPER or SYSDBA system privileges, if using a password file, or their operating
system equivalents, if using OS authentication.
/
Uses operating system authentication.
INTERNAL
Connects as username SYS via keyword INTERNAL. Should be used rarely and only
by the DBA for certain maintenance purposes; requires operating system privileges.
CONNECT INTERNAL is supported for backwards compatibility only.
Line Mode Behavior
If you omit the password, you are prompted for one. If you omit both
the username and password, you are prompted for both.
SQL Worksheet Behavior
If you omit the username argument, the Connect dialog box displays.
Usage Notes
If only the Oracle username is specified, the password is requested using the prompt
"Password:". The entered password is not echoed.
You can specify an instance path for a remote instance when connecting. If you
attempt a connection to a remote instance, authentication occurs on the remote node,
so you must have the appropriate privileges on the remote node.
The server to which you are connecting must have a password file.
You must be granted the SYSOPER or SYSDBA system privilege.
You must connect using a username and password.
For information about creating a password file, see the Oracle7 Server Concepts and
the Oracle7 Server Administrator's Guide, or Secure ConnectionConnecting as
SYSOPER or SYSDBA over a Local
To connect to Oracle as a privileged user over a local or a secure connection, you
must satisfy either of the following sets of conditions:
You can connect using a password file, provided you meet the criteria outlined
above.
If the server is not using a password file, or you have not been granted
SYSOPER or SYSDBA and are therefore not in the password file, your
operating system name must be authenticated by the operating system for a
privileged connection. This form of authentication is system-specific.
Connecting as INTERNAL
Using Server Manager you can connect as INTERNAL to a release 7.0 database.
CONNECT INTERNAL is supported for backwards compatibility only. For
information on how to use CONNECT INTERNAL, refer to your Oracle7 Server
Administrator's Guide.
DESCRIBE
Purpose
where:
name
If you do not specify an object type, Server Manager attempts to determine the object
type. For the statement
DESCRIBE emp
Server Manager describes the table or view if a table or view with the name EMP
exists. If no table or view with that name exists in the user's schema, Server Manager
will search for a PL/SQL function, procedure, or package with that name and describe
it.
The shorthand DESC is now equivalent to the command DESCRIBE. This means that
DESC has been added to the list of Server Manager reserved words. If you have a
database object named DESC, you need to place quotes around the name to show that
it is an object name. For example:
INSERT INTO 'DESC' VALUES('onetwothree', 123); )
Note:
Some versions of PL/SQL allow the user to describe a package by giving the package
name, and some versions require the user to specify an object in the package to
describe. Server Manager supports package description for those versions of PL/SQL
which support this functionality.
Example
A command like
DESCRIBE scott.addemp
The use of the object type is no longer required. If you do not specify an object type,
Server Manager attempts to determine the object type. For the statement
DESCRIBE emp
Server Manager describes the table or view if a table or view with the name EMP
exists.
If no table or view with that name exists in the user's schema, Server Manager
searches for a PL/SQL function, procedure, or package with that name and describes
it. For the statement
DESCRIBE payroll.emp
Server Manager looks for a table or view in schema PAYROLL with the name EMP.
This allows you to specify the type of the object you want to describe.
Server Manager now has the capability to describe both functions and procedures
contained in packages. Previously only functions and procedures not contained in
packages could be described.
Note:
Some versions of PL/SQL allow the user to describe a package by giving the package
name, and some versions require the user to specify an object in the package to
describe. Server Manager supports package description for those versions of PL/SQL
which support this functionality.
DISCONNECT
Purpose
Usage Notes
Upon disconnection, line mode reverts to the current default host machine after
closing all open cursors and committing any uncommitted transactions.
Example
DISCONNECT
EXECUTE
Purpose
Usage Notes
You can execute only one line of PL/SQL code with the EXECUTE command. If you
wish to execute a PL/SQL block with many lines, you must use the format:
BEGIN
[PL/SQL BLOCK]
END;
You can reference any command line mode bind variables in PL/SQL statements by
preceding the variable name with a colon. The example below illustrates the use of
bind variables with the VARIABLE, EXECUTE, and PRINT commands.
Example
EXIT
Purpose
None.
Syntax
The EXIT command leaves line mode unconditionally, commits the current
transaction, and returns to the operating system prompt.
SQL Worksheet Behavior
The EXIT command commits the current transaction and closes the worksheet.
Example
EXIT
PRINT
Purpose
None.
Syntax
where:
variable
Bind variables referenced with the print command do not need to be preceded by a
colon. You can use the PRINT command to display variables defined only in the
current line mode session. The SET CHARWIDTH and SET NUMWIDTH
commands can affect the display of the PRINT command.
PRINT balance
BALANCE
----------
4687.24
SET CHARWIDTH 10
PRINT ename
ENAME
----------
SCOTT
RECOVER
Purpose
Performs media recovery on one or more tablespaces, one or more datafiles, or the
entire database.
Prerequisites
Specifies that a backup of the control file is being used instead of the current control
file.
TABLESPACE tablespace
Specifies recovering a particular datafile. You can specify any number of datafiles.
UNTIL CANCEL
Specifies an incomplete, time-based recovery. Use single quotes, and use the
following format:
'YYYY-MM-DD:HH24:MI:SS'.
PARALLEL
DEGREE specifies the number of recovery processes used to apply redo entries to
datafiles on each instance. An integer specified for DEGREE overrides the
initialization parameter RECOVERY_PARALLELISM.
DEGREE DEFAULT indicates that twice the number of datafiles being recovered is
the number of recovery processes to use.
INSTANCES specifies the number of instances to use for parallel recovery. The
number of recovery processes specified with DEGREE is used on each instance, thus
the total number of recovery processes is the integer specified with DEGREE
multiplied by the integer specified with INSTANCES. INSTANCES is only pertinent
for the Oracle Parallel Server.
INSTANCES DEFAULT or not including the INSTANCES keyword causes has
operating system-specific consequences. Consult your Oracle operating system
documentation for a description of the default behavior of the INSTANCES
DEFAULT specification.
NOPARALLEL
To perform media recovery on an entire database (all tablespaces), the database must
be mounted EXCLUSIVE and closed.
To perform media recovery on a tablespace, the database must be mounted and open,
and the tablespace must be offline.
To perform media recovery on a datafile, the database can remain open and mounted
with the damaged datafiles offline (unless the file is part of the SYSTEM tablespace).
Before using the RECOVER command you must have restored good copies of the
damaged datafile(s) from a previous backup. Be sure you can access all archived and
online redo log files dating back to when that backup was made.
When another log file is required during recovery, a prompt suggests the names of
files that are needed. The name is derived from the values specified in the
initialization parameters LOG_ARCHIVE_DEST and LOG_ARCHIVE_FORMAT.
You should restore copies of the archived redo log files needed for recovery to the
destination specified in LOG_ARCHIVE_DEST, if necessary. You can override the
initialization parameters by setting the LOGSOURCE variable.
During recovery you can accept the suggested log name by hitting return, cancel
recovery by entering CANCEL instead of a log name, or enter AUTO for automatic
file selection without further prompting.
If you have enabled autorecovery (that is, SET AUTORECOVERY ON), recovery
proceeds without prompting you with filenames. Status messages are displayed when
each log file is applied.
For more information on recovery and the RECOVER command, see the Oracle7
Server Administrator's Guide.
Examples
RECOVER DATABASE
RECOVER DATABASE UNTIL TIME 30-AUG-90:04:32:00
RECOVER TABLESPACE ts_one, ts_two
RECOVER DATAFILE 'data1.db'
REMARK
Purpose
None.
Syntax
Usage Notes
Primarily for batch use of line mode. The Comment is ignored by line mode and by
Oracle. REMARK can be shortened to REM.
REM must be the first non-blank character string in the line.
Examples
REMARKs are recognized by SQL*Plus, as well as by line mode. They are used to
put Comments between SQL statements, while SQL Comments (/*...*/) are used to
place comments within statements.
SET
Purpose
None.
Syntax
OFF, the default option, requires that you enter the filenames manually or accept the
suggested default filename given.
CHARWIDTH integer
Sets the column display width for CHAR data. If entered with no argument, returns
the setting to the default. The default is 80; the range of values is operating system-
specific.
COMPATIBILITY
Sets compatibility mode to V6, V7, or NATIVE. The compatibility mode setting
affects the specification of character columns, integrity constraints, and rollback
segment storage parameters. NATIVE matches the version of the database.
and specified constraints are disabled by default. For V7 mode, table constraints are
specified with Oracle7 syntax:
Sets the column display width for DATE data. If entered with no argument, the setting
returns to the default. The default is 9; the range of values is operating system-
specific.
ECHO
ON enables echoing of commands entered from command files. OFF, the default,
disables echoing of commands.
FETCHROWS integer
Limits the number of rows returned by a query. Useful with ordered queries for
finding the "top ten" items in a category, for example. Also used with unordered
queries to find the "first n" records that satisfy a given criteria. integer must be in the
range 1-999,999.
Changes the default instance for your session to the specified instance path. Does not
connect to a database. The default instance is used for commands when no instance is
specified.
Any commands preceding the first use of SET INSTANCE communicate with the
default instance.
To reset the instance to the default value for your operating system, you can either
enter SET INSTANCE with no instance-name or SET INSTANCE LOCAL. See your
operating system-specific Oracle documentation for a description of how to set the
initial default instance.
This command may only be issued when SQL*Net is running. You can use any valid
SQL*Net connect string as the specified instance path. See your operating system-
specific Oracle documentation for a complete description of how your operating
system specifies SQL*Net connect strings. The maximum length of the instance path
is 64 characters.
LOGSOURCE pathname
Specifies the location from which archive logs are retrieved during recovery. The
default value is set by the LOG_ARCHIVE_DEST initialization parameter. Issuing
the SET LOGSOURCE command without a pathname restores the default location.
LONGWIDTH integer
Sets the column display width for LONG data. If entered with no argument, the
setting returns to the default. The default is 80; the range of values is operating
system-specific.
MAXDATA integer
Sets the maximum data size. Indicates the maximum data that can be received in a
single fetch during a SELECT statement. The default is 20480 bytes (20K). The
maximum is operating system-specific.
NUMWIDTH integer
Sets the column display width for NUMBER data. If entered with no argument, the
setting returns to the default. The default is 10; the range of values is operating
system-specific.
RETRIES
integer | INFINITE
Sets the number of tries that are attempted when the RETRY option is used with the
STARTUP command (see STARTUP on page -31 ). INFINITE, the default, specifies
an infinite number of retries.
SERVEROUTPUT
ON enables debugging output from stored procedures that use DBMS_OUTPUT PUT
and PUT_LINE commands. OFF disables output.
You can specify the size in bytes of the message buffer using the syntax SIZE n. That
is the total number of bytes of all messages sent that can be accumulated at one time.
The minimum is 2,000 bytes. If the buffer fills before calls to the get-message routines
make room for additional message bytes, an error is returned to the message-sending
program.
STOPONERROR
ON, the default, enables terminal output for SQL commands. OFF disables terminal
output. Useful for preventing output to terminal when spooling output to files. Note
that nothing appears on the terminal until SET TERMOUT ON is used.
TIMING
ON displays parse, execute, and fetch times (CPU and elapsed) for each SQL
statement executed. OFF, the default, does not display timing information.
Examples
Either of the following commands can be used to revert to the initial default host:
SET INSTANCE
SET INSTANCE LOCAL
SHOW
Purpose
None.
Syntax
Shows the current status (ON/OFF) and the application registration text.
CHARWIDTH
The SET CHARWIDTH command can be used to expand or truncate the display from
the SHOW ERRORS command.
FETCHROWS
Shows the numerical limit set for the number of rows returned by a query.
INSTANCE
Shows the connect string for the default instance. SHOW INSTANCE returns the
value LOCAL if you have not used SET INSTANCE or if you have used the LOCAL
option of the SET INSTANCE command.
LOGSOURCE
Shows the current setting for archive log location. Displays DEFAULT if the default
setting is in effect, as specified by the LOG_ARCHIVE_DEST initialization
parameter.
LONGWIDTH
Displays the current values for one or more initialization parameters. You can use a
string after the command to see a subset of parameters whose names include that
string. For example, if you enter:
SHOW PARAMETERS COUNT
The SHOW PARAMETERS command, without any string following the command,
displays all initialization parameters.
RETRIES
Displays the number of retries that will be attempted when restarting an instance in
parallel mode. (See RETRY on page -34 . It is an option in "STARTUP". )
SERVEROUTPUT
If spooling is enabled, displays the name of the output spool file. Otherwise, displays
OFF.
STOPONERROR
Displays whether or not errors encountered during execution of command files should
stop execution of the file.
TERMOUT
Shows whether or not the parse, execute, and fetch times (CPU and elapsed) for each
SQL statement executed are shown.
Usage Notes
SHOW TIMING
SHOW ALL
SHOW SGA
SHUTDOWN
Purpose
Shut down a currently running Oracle instance, optionally closing and dismounting a
database.
Prerequisites
where:
ABORT
Proceeds with the fastest possible shutdown. Does not wait for calls to complete or
users to disconnect. Does not close or dismount the database, but does shut down the
instance. Requires instance recovery on next startup. You must use this option if a
background process terminates abnormally.
IMMEDIATE
Does not wait for current calls to complete, prohibits further connects, and closes and
dismounts the database. Finally, shuts down the instance. Does not wait for connected
users to disconnect. Does not require instance recovery on next startup.
NORMAL
Waits for currently connected users to disconnect from the database, prohibits further
connects, and closes and dismounts the database. Finally, shuts down the instance.
Does not require instance recovery on next startup. NORMAL is the
default option.
Attention:
In Server Manager, you can have several separate connections open at any time in
multiple windows. If you have any connections open, remember to close them before
performing a shutdown in normal mode. Otherwise, the shutdown will not complete.
Example
SHUTDOWN
Database closed.
Database dismounted.
Oracle instance shut down.
SPOOL
Purpose
None.
Syntax
where:
filename
Any valid name for a spool file. If not specified, the file type or file extension is LOG.
If a file by the specified name exists, an error is generated.
OFF
If you do not specify a file, Server Manager prompts you for a filename.
STARTUP
Purpose
Start an Oracle instance with several options, including mounting and opening a
database.
Prerequisites
where:
FORCE
Shuts down the current Oracle instance (if it is running) with SHUTDOWN mode
ABORT, before restarting it. If the current instance is running and FORCE is not
specified, an error results. FORCE is useful while debugging and under abnormal
circumstances. It should not normally be used.
RESTRICT
Only allows Oracle users with the RESTRICTED SESSION system privilege to
connect to the database. Later, you can use the ALTER SYSTEM command to disable
the restricted session feature.
PFILE=filename
Causes the specified parameter file to be used while starting up the instance.
MOUNT
Causes the database not to be mounted upon instance startup. Cannot be used with
SHARED, EXCLUSIVE, PARALLEL, MOUNT, or OPEN.
RECOVER
Specifies that media recovery should be performed, if necessary, before starting the
instance. STARTUP RECOVER has the same effect as issuing the RECOVER
DATABASE command and starting an instance. Only complete recovery is possible
with the RECOVER option.
If recovery fails using the RECOVER option, the database remains mounted and
closed.
database
The name of the database to mount or open. If no database name is specified, the
database name is taken from the initialization parameter DB_NAME.
EXCLUSIVE
Signifies that the database can only be mounted and opened by the current instance (it
cannot be opened simultaneously by multiple instances). Cannot be used with
SHARED, PARALLEL, or NOMOUNT. If no mounting option is specified,
EXCLUSIVE is assigned by default.
PARALLEL
Specifies that opening the database should be attempted every five seconds if the
instance is busy being recovered by another instance. When an instance is being
recovered by another instance, the down instance cannot open the database until
recovery is complete. If the database cannot be opened for any other reason, RETRY
does not attempt to open the database again. This option is only available for instances
operating in PARALLEL mode. The number of times RETRY attempts to start the
database can be set with the SET RETRIES command (refer to "SET" for the
option, RETRIES integer | INFINITE on page -23 ).
Examples
To start an instance using the standard parameter file, mount the default database in
exclusive mode, and open the database, enter:
STARTUP
or enter:
STARTUP OPEN databasename EXCLUSIVE
To start an instance using the standard parameter file, mount the default database in
parallel mode, and open the database, enter:
STARTUP PARALLEL
STARTUP OPEN databasename PARALLEL
To restart an instance that went down in parallel mode and may not yet have been
recovered by other instances, use the RETRY option:
STARTUP PARALLEL RETRY
To start an instance using the parameter file TESTPARM without mounting the
database, enter:
STARTUP PFILE=testparm NOMOUNT
To shut down a particular database, immediately restart and open it in parallel mode,
allow access only to database administrators, and use the parameter file
MYINIT.ORA. enter:
STARTUP OPEN databasename PFILE=myinit.ora FORCE SHARED RESTRICT
To start up an instance and mount but not open a database, you can use the following
sequence of commands (the system's response is also shown):
CONNECT INTERNAL
Connected.
STARTUP NOMOUNT
Oracle instance started.
At this point, you could run a maintenance command and then open the database, as
shown in the following commands:
ALTER DATABASE ARCHIVELOG;
Statement processed.
VARIABLE
Purpose
Declare a bind variable for use in the current session with the EXECUTE or PRINT
command, or for use with a PL/SQL block.
Prerequisites
None.
Syntax
where:
name
The datatype of the bind variable. The valid datatypes are NUMBER, CHAR, and
VARCHAR2. You can specify a length from 1 to 255 for CHAR, and from 1 to 2,000
for VARCHAR2. If you do not specify a length, CHAR and VARCHAR2 default to
the current setting of CHARWIDTH.
Usage Notes
Bind variables defined with the VARIABLE command exist until the end of the
session. Variables defined in your session cannot be accessed or changed by a
different session.
Warning:
CHAR variables are fixed length, padded with blanks. VARCHAR2 variables are
variable length. You must use CHAR when passing a character variable to a PL/SQL
procedure that defines a CHAR parameter. Otherwise, a conversion error results. A
PL/SQL procedure that expects a VARCHAR2 variable, on the other hand, will
automatically convert a CHAR parameter to the proper form. (In general, it is a good
idea to avoid the use of CHAR variables in PL/SQL procedures unless blank-padding
is an absolute requirement.)
Note:
In V6 compatibility mode, a CHAR variable is variable length, rather than fixed.
Examples
This appendix lists the differences between Oracle7 SQL*DBA and Server Manager
DBA commands.
DESCRIBE Lists information about the Lists the definition of the procedure
for PL/SQL procedure argument in a tabular argument
form
PRINT a A A
----------
---------- 10 1 row 10 The variable name is not space padded:
selected. "A"
The variable name is Also, no feedback is listed.
space padded:
"A ".
SHOW VARIABLES SHOW Shows all defined Unsupported: Use the PRINT command
VAR variables with no arguments
SET ARRAYSIZE Changes the size of No longer used: Server Manager automatically
each chooses optimum fetch size.
fetch call
Executing a SQL script from the >sqldba @script.sql >svrmgrl command = @script.sql
operating system command line
Entering a Server Manager Unsupported Type a backslash (\) at the end of each
command spanning multiple line to indicate continuation.
lines
SVRMGR> connect \
2> myrdb/password
SVRMGR> select *
2> from emp
3> where ename = 'A\
4> BCDEF';
Aborting a command Hit <Return> twice Enter a period (.) by itself on a line. This
or procedure applies to Server Manager l
Enter a period (.) by Line Mode only.
itself on a line.
SVRMGR> delete from emp
2> .
SVRMGR>