databases/oracle
Contents
About
Installation
Two administrative user accounts are automatically created when Oracle Database is installed:
SYS (default password: CHANGE_ON_INSTALL)
SYSTEM (default password: MANAGER)
Filesystem layout
Logs are stored in the directory diag
sql*plus
Connecting to the Database with SQL*Plus
- Do not enter the password on the cli, use a prompt. (stored in history, visible in process table, …).
- Prepare environment
The PATH should include $ORACLE_HOME/bin.
On Linux you can store it in your .profile or .bashrc for a permanent configuration or specify it manually before you connect.
- On Windows the environment is stored in the registry below
HKEY_LOCAL_MACHINE\SOFTWARE\oracle.
- Can be overridden on the shell.
- Windows CMD
Windows PowerShell
- Can be overridden on the shell.
/nolog prevents immediate connection to a database.
- Syntax
CONNECT statement
1 CONN[ECT] [logon] [AS {SYSOPER | SYSDBA}]where logon is
1 {username | /}[@connect_identifier] [edition={edition_name | DATABASE_DEFAULT}]Single / means external authentication (e.g. OS auth).
username refers to a valid database user name.
connect_identifier may
- be a "Oracle Net connect identifier" aka "net service name" for a remote connection.
- If omitted, sqlplus tries a local connection.
Typically resolved via tnsnames.ora, but may also be other ways.
use easy connect syntax
"host[:port][/service_name][:server][/instance_name]"- IPv6 addresses must be enclosed with square brackets.
Leads to far for now. Please see:
Oracle Database Net Services Administrator's Guide
- be a "Oracle Net connect identifier" aka "net service name" for a remote connection.
edition may be a specific edition_name or just the DATABASE_DEFAULT
The user must have the USE privilege on the edition.
Formatting output
Defaults
List online redo logs
Fast Recovery Area (FRA)
- aka recovery area
- Configured in database via
DB_RECOVERY_FILE_DEST_SIZE specifies (in bytes) the hard limit on the total space to be used by target database recovery files created in the fast recovery area.
DB_RECOVERY_FILE_DEST specifies the default location for the fast recovery area.
- The fast recovery area contains multiplexed copies of current control files and online redo logs, as well as archived redo logs, flashback logs, and RMAN backups.
Show current FRA configuration
Connect with sqlplus AS SYSDBA
Show FRA usage
Connect with sqlplus AS SYSDBA
Check flashback state
- Flashback online redo logs are usually stored in FRA.
Use the view
1 select FLASHBACK_ON FROM V$DATABASE;
Archive log mode and archive logs
Use the view
Show archived redo log destination
Manage a database and its instances
A database goes through the following phases when it proceeds from a shutdown state to an open database state:
NOMOUNT
- Instance started without mounting database.
- The instance is started, but is not yet associated with a database.
MOUNT
- Database mounted
- The instance is started and is associated with a database by reading its control file (see "Overview of Control Files").
- The database is closed to users.
OPEN
- Database open
- The instance is started and is associated with an open database.
- The data contained in the data files is accessible to authorized users.
Connect via sqlplus as sysdba and select one of the following states
A transition between the states can be achieved with
In read only mode the data file and redo log files are not touched.
An instance cannot open a previously opened and closed database again. The instance must be shutdown and a new instance opened.
There are several possibilities to shutdown the instance
The possible SHUTDOWN statements are: * SHUTDOWN ABORT
- This mode is intended for emergency situations, such as when no other form of shutdown is successful.
- This mode of shutdown is the fastest.
- However, a subsequent open of this database may take substantially longer because instance recovery must be performed to make the data files consistent.
- Note:
Because SHUTDOWN ABORT does not checkpoint the open data files, instance recovery is necessary before the database can reopen. The other shutdown modes do not require instance recovery before the database can reopen.
* SHUTDOWN IMMEDIATE
- This mode is typically the fastest next to SHUTDOWN ABORT.
- Oracle Database terminates any executing SQL statements and disconnects users. Active transactions are terminated and uncommitted changes are rolled back.
* SHUTDOWN TRANSACTIONAL
- This mode prevents users from starting new transactions, but waits for all current transactions to complete before shutting down.
- This mode can take a significant amount of time depending on the nature of the current transactions.
* SHUTDOWN NORMAL
- This is the default mode of shutdown.
- The database waits for all connected users to disconnect before shutting down.
Useful queries
Table analysis
rman
Recovery Manager (RMAN) is an Oracle Database client that performs backup and recovery tasks on your databases and automates administration of your backup strategies. It greatly simplifies backing up, restoring, and recovering database files.
Oracle Database Backup and Recovery User's Guide 11g Release 2 (11.2)
rman supports no (dashed) cli options like -h
Connecting to a database with rman
- Connection is made similar to sqlplus.
Please see
#Connecting to the Database with SQL*PlusTakes an additional keyword TARGET in front of the rman target database.
- Requires SYSDBA privileges.
The AS SYSDBA keywords are implied and cannot be explicitly specified.
Connect as user sys via cli
1 rman target sys/
Connect as user sys via a CONNECT statement
Show the default RMAN configuration
Connect to the target
1 SHOW ALL;
LIST BACKUP
Connect with sqlplus AS SYSDBA
Show a summary
1 LIST BACKUP SUMMARY;
Show a detailed list
1 LIST BACKUP;
Show a list of expired backups
1 LIST EXPIRED BACKUP;
List archive logs
1 LIST ARCHIVELOG ALL;
CROSSCHECK
Use the CROSSCHECK command to synchronize the physical reality of backups and copies with their logical records in the RMAN repository.
Connect with sqlplus AS SYSDBA
DELETE EXPIRED
After the update with #CROSSCHECK the expired backups may be deleted.
1 DELETE EXPIRED BACKUP;