ALTER DATABASE

Open an existing database, and /or modify associated files.

Syntax:

   ALTER DATABASE database_name options

Options:

open/mount options:
   MOUNT
   MOUNT STANDBY DATABASE
   MOUNT CLONE DATABASE
   MOUNT PARALLEL
   CONVERT
   OPEN [READ ONLY]
   OPEN [READ WRITE] [RESETLOGS|NORESETLOGS] [UPGRADE|DOWNGRADE]
   ACTIVATE [PHYSICAL | LOGICAL] STANDBY DATABASE [FINISH APPLY]
   [NATIONAL] CHARACTER SET char_set

archivelog options:
   ARCHIVELOG
   NOARCHIVELOG

backup and recovery options:
   BEGIN BACKUP
   BACKUP CONTROLFILE TO 'filename' [REUSE]
   BACKUP CONTROLFILE TO TRACE [RESETLOGS] [AS 'filename' [REUSE]]
   CREATE STANDBY CONTROLFILE AS 'filename' [REUSE]
   RECOVER recover_clause
   RECOVER MANAGED STANDBY standby_recover_clause
   END BACKUP

Datafile options:
   CREATE DATAFILE 'filename' [,'filename'...] AS filespec [,'filespec'...]
   CREATE DATAFILE filenunber [,filenunber...] AS filespec [,'filespec'...]
   DATAFILE 'filename' ONLINE
   DATAFILE 'filename' OFFLINE [FOR DROP]
   DATAFILE 'filename' RESIZE int K | M
   DATAFILE 'filename' AUTOEXTEND OFF
   DATAFILE 'filename' AUTOEXTEND ON [NEXT int K | M] [MAXSIZE int K | M | UNLIMITED]
   DATAFILE 'filename' END BACKUP
   RENAME FILE 'data_file_name' TO 'data_file_name'

   TEMPFILE 'filename' ONLINE
   TEMPFILE 'filename' OFFLINE
   TEMPFILE 'filename' DROP [INCLUDING DATAFILES]
   TEMPFILE 'filename' RESIZE int K | M
   TEMPFILE 'filename' AUTOEXTEND OFF
   TEMPFILE 'filename' AUTOEXTEND ON [NEXT int K | M] [MAXSIZE int K | M | UNLIMITED]

redo log options:
   ADD LOGFILE [THREAD int] [GROUP int] filespec
   ADD LOGFILE MEMBER 'filename' [REUSE] TO GROUP int
   ADD LOGFILE MEMBER 'filename' [REUSE] TO 'filename'
   DROP LOGFILE GROUP int
   DROP LOGFILE ('filename')
   DROP LOGFILE MEMBER 'filename'
   RENAME FILE 'redolog_file_name' TO 'redolog_file_name'
   CLEAR [UNARCHIVED] LOGFILE GROUP int [UNRECOVERABLE DATAFILE]
   CLEAR [UNARCHIVED] LOGFILE ('filename') [UNRECOVERABLE DATAFILE]

Parallel server options:
   CREATE STANDBY CONTROLFILE AS 'filename' [REUSE]
   SET DBLOW = 'text'
   SET DBHIGH = 'text'
   SET DBMAC = ON | OFF
   ENABLE [PUBLIC] THREAD int
   DISABLE THREAD int

Backwards compatibility options:
   RENAME GLOBAL_NAME TO database [domain]
   RESET COMPATIBILITY

Any option above that includes a 'filename' can be extended to cover multiple files using the syntax: ('filename1', 'filename2')

'filename' [offline] DROP will only work on a tablespace consisting of a single datafile, for a tablespace comprising multiple datafiles you can only drop a datafile by dropping the entire tablespace.

Some of the commands above can only be used when the database is in a particular state:

MOUNT, CONVERT - Require that the db is Not Mounted.
ARCHIVELOG, NOARCHIVLOG, RECOVER - Require that the db is Mounted but not open (must be mount exclusive - not mount parallel).
ENABLE, DISABLE, RENAME GLOBAL_NAME, RESET, SET - Require that the db is Open.

All other options will work with the db mounted, open or closed as long as none of the files involved are 'in use'

database_name is defined when the database is created - it is normally set to the same as the database SID.

Examples

Resize datafile:

SQL> ALTER DATABASE DATAFILE 'F:\oradata\live\Mydb02.ora' RESIZE 500m;

Take datafile offline:

SQL> ALTER DATABASE DATAFILE 'F:\oradata\live\Mydb02.ora' OFFLINE;
Database altered.

Take datafile online, when doing this, file recovery is needed to update the timestamp in the offline datafile header.:

SQL> ALTER DATABASE DATAFILE 'F:\oradata\live\Mydb02.ora' ONLINE;
 ALTER DATABASE DATAFILE 'F:\oradata\live\Mydb02.ora' ONLINE
 *
 ERROR at line 1:
 ORA-01113: file 16 needs media recovery
 ORA-01110: data file 16: 'F:\ORADATA\LIVE\Mydb02.ORA'
SQL> RECOVER DATAFILE 'F:\oradata\live\Mydb02.ora';
 Media recovery complete.
SQL> ALTER DATABASE DATAFILE 'F:\oradata\live\Mydb02.ora' ONLINE;
Database altered

Change the database character set to UTF8, this must be done with no users connected (restricted session)

SQL> SHUTDOWN IMMEDIATE;   -- or NORMAL
    <do a full backup>
SQL> STARTUP MOUNT;
SQL> ALTER SYSTEM ENABLE RESTRICED SESSION;
SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
SQL> ALTER DATABASE OPEN;
SQL> ALTER DATABASE CHARACTER SET UTF8;
SQL> SHUTDOWN IMMEDIATE;   -- or NORMAL
SQL> STARTUP;

"You know, the very powerful and the very stupid have one thing in common, they don't alter their views to fit the facts, they alter the facts to fit the views, which can be uncomfortable, if you happen to be one of the facts that needs altering" ~ Doctor Who

Related Oracle Commands:

DATABASE - CREATE DATABASE
RECOVER
SHUTDOWN
STARTUP
ALTER TABLESPACE
ALTER SYSTEM

Related Views:

 GLOBAL_NAME  DBA_DATA_FILES  V$CONTROLFILE  V$DATABASE  V$DATAFILE  V$LOG  V$LOGFILE


 
Copyright © 1999-2024 SS64.com
Some rights reserved