Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / Oracle selected docs / SQL reference.pdf
Скачиваний:
24
Добавлен:
12.05.2015
Размер:
11.92 Mб
Скачать

CREATE CONTEXT

CREATE CONTEXT

Purpose

Use the CREATE CONTEXT statement to:

Create a namespace for a context (a set of application-defined attributes that validates and secures an application) and

Associate the namespace with the externally created package that sets the context.

You can use the DBMS_SESSION.set_context procedure in your designated package to set or reset the attributes of the context.

See Also:

Oracle9i Database Concepts for a definition and discussion of contexts

Oracle9i Supplied PL/SQL Packages and Types Reference for information on the DBMS_SESSION.set_context procedure

Prerequisites

To create a context namespace, you must have CREATE ANY CONTEXT system privilege.

Syntax

create_context::=

OR

REPLACE

 

 

schema

.

CREATE

 

CONTEXT

namespace

USING

package

EXTERNALLY

INITIALIZED

GLOBALLY

ACCESSED GLOBALLY

;

13-12 Oracle9i SQL Reference

CREATE CONTEXT

Semantics

OR REPLACE

Specify OR REPLACE to redefine an existing context namespace using a different package.

namespace

Specify the name of the context namespace to create or modify. Context namespaces are always stored in the schema SYS.

schema

Specify the schema owning package. If you omit schema, Oracle uses the current schema.

package

Specify the PL/SQL package that sets or resets the context attributes under the namespace for a user session.

Note: To provide some design flexibility, Oracle does not verify the existence of the schema or the validity of the package at the time you create the context.

See Also: Oracle9i Supplied PL/SQL Packages and Types Reference for more information on setting the package

INITIALIZED Clause

The INITIALIZED clause lets you specify an entity other than Oracle that can initialize the context namespace.

EXTERNALLY EXTERNALLY indicates that the namespace can be initialized using an OCI interface when establishing a session.

See Also: Oracle Call Interface Programmer’s Guide for information on using OCI to establish a session

GLOBALLY GLOBALLY indicates that the namespace can be initialized by the LDAP directory when a global user connects to the database.

SQL Statements: CREATE CLUSTER to CREATE JAVA 13-13

CREATE CONTEXT

After the session is established, only the designated PL/SQL package can issue commands to write to any attributes inside the namespace.

See Also:

Oracle9i Application Developer’s Guide - Fundamentals for information on establishing globally initialized contexts

Oracle Internet Directory Administrator’s Guide for information on the connecting to the database through the LDAP directory

ACCESSED GLOBALLY

This clause indicates that any application context set in namespace is accessible throughout the entire instance. This setting lets multiple sessions share application attributes.

Examples

Creating an Application Context: Example This example uses the PL/SQL package emp_mgmt, created in "Creating a Package: Example" on page 14-55, which validates and secures the hr application. The following statement creates the context namespace hr_context and associates it with the package emp_mgmt:

CREATE CONTEXT hr_context USING emp_mgmt;

You can control data access based on this context using the SYS_CONTEXT function. For example, suppose your emp_mgmt package has defined an attribute new_ empno as a particular employee identifier. You can secure the base table employees by creating a view that restricts access based on the value of new_ empno, as follows:

CREATE VIEW hr_org_secure_view AS

SELECT * FROM employees

WHERE employee_id = SYS_CONTEXT(’hr_context’, ’new_empno’);

See Also: SYS_CONTEXT on page 6-156

13-14 Oracle9i SQL Reference

CREATE CONTROLFILE

CREATE CONTROLFILE

Caution: Oracle recommends that you perform a full backup of all files in the database before using this statement. For more information, see Oracle9i User-Managed Backup and Recovery Guide.

Purpose

Use the CREATE CONTROLFILE statement to re-create a control file in one of the following cases:

All copies of your existing control files have been lost through media failure.

You want to change the name of the database.

You want to change the maximum number of redo log file groups, redo log file members, archived redo log files, datafiles, or instances that can concurrently have the database mounted and open.

Note: If it is necessary to use the CREATE CONTROLFILE statement, do not include in the DATAFILE clause any datafiles in temporary or read-only tablespaces. You can add these types of files to the database later.

An alternative to the CREATE CONTROLFILE statement is ALTER DATABASE BACKUP CONTROLFILE TO TRACE, which generates a SQL script in the trace file to re-create the controlfile. If your database contains any read-only or temporary tablespaces, that SQL script will also contain all the necessary SQL statements to add those files back into the database.

See Also: "BACKUP CONTROLFILE Clause" of ALTER DATABASE on page 9-42 for information creating a script based on an existing database controlfile

When you issue a CREATE CONTROLFILE statement, Oracle creates a new control file based on the information you specify in the statement. If you omit any clauses, Oracle uses the default values rather than the values for the previous control file.

After successfully creating the control file, Oracle mounts the database in the mode

SQL Statements: CREATE CLUSTER to CREATE JAVA 13-15

CREATE CONTROLFILE

specified by the initialization parameter CLUSTER_DATABASE. You then must perform media recovery before opening the database. It is recommended that you then shut down the instance and take a full backup of all files in the database.

See Also: Oracle9i User-Managed Backup and Recovery Guide

Prerequisites

To create a control file, you must have the SYSDBA system privilege.

The database must not be mounted by any instance. Oracle leaves the database mounted in EXCLUSIVE state after successful creation of the control file. If you are using Oracle with Real Application Clusters, the DBA must then shut down and remount the database in SHARED mode (which is the default if the value of the CLUSTER_DATABASE initialization parameter is TRUE) before other instances can start up.

If the REMOTE_LOGIN_PASSWORDFILE initialization parameter is set to EXCLUSIVE, Oracle returns an error when you attempt to re-create the control file. To avoid this message, either set the parameter to SHARED, or re-create your password file before re-creating the control file.

See Also: Oracle9i Database Reference for more information about the REMOTE_LOGIN_PASSWORDFILE parameter

13-16 Oracle9i SQL Reference

CREATE CONTROLFILE

Syntax

create_controlfile::=

 

 

 

 

REUSE

SET

 

 

CREATE

CONTROLFILE

 

 

DATABASE

database

 

 

 

 

 

 

 

,

logfile_clause

 

 

RESETL0GS

DATAFILE

datafile_tempfile_spec

 

 

 

 

NORESETL0GS

 

 

 

MAXLOGFILES

integer

 

 

 

MAXLOGMEMBERS

 

integer

 

 

 

MAXLOGHISTORY

 

integer

 

 

 

MAXDATAFILES

 

integer

 

 

 

MAXINSTANCES

 

integer

 

 

 

 

ARCHIVELOG

 

 

 

 

 

 

NOARCHIVELOG

 

 

 

 

FORCE

LOGGING

character_set_clause

 

 

 

 

 

 

 

 

;

(datafile_tempfile_spec::= on page 7-39—part of file_specification syntax)

logfile_clause ::=

,

GROUP integer

LOGFILE

redo_log_file_spec

(redo_log_file_spec::= on page 7-40—part of file_specification syntax)

character_set_clause::=

CHARACTER SET character_set

SQL Statements: CREATE CLUSTER to CREATE JAVA 13-17

CREATE CONTROLFILE

Semantics

REUSE

Specify REUSE to indicate that existing control files identified by the initialization parameter CONTROL_FILES can be reused, thus ignoring and overwriting any information they may currently contain. If you omit this clause and any of these control files already exists, Oracle returns an error.

DATABASE Clause

Specify the name of the database. The value of this parameter must be the existing database name established by the previous CREATE DATABASE statement or

CREATE CONTROLFILE statement.

SET DATABASE Clause

Use SET DATABASE to change the name of the database. The name of a database can be as long as eight bytes.

logfile_clause

Use the logfile_clause to specify the redo log files for your database. You must list all members of all redo log file groups.

GROUP integer Specify the logfile group number. If you specify GROUP values, Oracle verifies these values with the GROUP values when the database was last open.

If you omit this clause, Oracle creates logfiles using system default values. In addition, if either the DB_CREATE_ONLINE_LOG_DEST_n or DB_CREATE_FILE_ DEST initialization parameter (or both) has been set, and if you have specified RESETLOGS, then Oracle creates two logs in the default logfile destination specified in the DB_CREATE_ONLINE_LOG_DEST_n parameter, and if it is not set, then in the

DB_CREATE_FILE_DEST parameter.

See Also: file_specification on page 7-39 for a full description of this clause

RESETLOGS Specify RESETLOGS if you want Oracle to ignore the contents of the files listed in the LOGFILE clause. These files do not have to exist. Each redo_log_ file_spec in the LOGFILE clause must specify the SIZE parameter. Oracle assigns all online redo log file groups to thread 1 and enables this thread for public

13-18 Oracle9i SQL Reference

CREATE CONTROLFILE

use by any instance. After using this clause, you must open the database using the

RESETLOGS clause of the ALTER DATABASE statement.

NORESETLOGS Specify NORESETLOGS if you want Oracle to use all files in the LOGFILE clause as they were when the database was last open. These files must exist and must be the current online redo log files rather than restored backups. Oracle reassigns the redo log file groups to the threads to which they were previously assigned and reenables the threads as they were previously enabled.

DATAFILE Clause

Specify the datafiles of the database. You must list all datafiles. These files must all exist, although they may be restored backups that require media recovery. See the syntax description in file_specification on page 7-39.

Note: You should list only datafiles in this clause, not temporary datafiles (tempfiles). Please refer to Oracle9i User-Managed Backup and Recovery Guide for more information on handling tempfiles.

Restriction on DATAFILE You cannot specify the autoextend_clause of data_ file_spec in this DATAFILE clause.

MAXLOGFILES Clause

Specify the maximum number of online redo log file groups that can ever be created for the database. Oracle uses this value to determine how much space in the control file to allocate for the names of redo log files. The default and maximum values depend on your operating system. The value that you specify should not be less than the greatest GROUP value for any redo log file group.

MAXLOGMEMBERS Clause

Specify the maximum number of members, or identical copies, for a redo log file group. Oracle uses this value to determine how much space in the control file to allocate for the names of redo log files. The minimum value is 1. The maximum and default values depend on your operating system.

MAXLOGHISTORY Clause

This parameter is useful only if you are using Oracle in ARCHIVELOG mode with Real Application Clusters. Specify the maximum number of archived redo log file groups for automatic media recovery of Real Application Clusters. Oracle uses this value to determine how much space in the control file to allocate for the names of

SQL Statements: CREATE CLUSTER to CREATE JAVA 13-19

CREATE CONTROLFILE

archived redo log files. The minimum value is 0. The default value is a multiple of the MAXINSTANCES value and depends on your operating system. The maximum value is limited only by the maximum size of the control file.

MAXDATAFILES Clause

Specify the initial sizing of the datafiles section of the control file at CREATE DATABASE or CREATE CONTROLFILE time. An attempt to add a file whose number is greater than MAXDATAFILES, but less than or equal to DB_FILES, causes the control file to expand automatically so that the datafiles section can accommodate more files.

The number of datafiles accessible to your instance is also limited by the initialization parameter DB_FILES.

MAXINSTANCES Clause

Specify the maximum number of instances that can simultaneously have the database mounted and open. This value takes precedence over the value of the initialization parameter INSTANCES. The minimum value is 1. The maximum and default values depend on your operating system.

ARCHIVELOG | NOARCHIVELOG

Specify ARCHIVELOG to archive the contents of redo log files before reusing them. This clause prepares for the possibility of media recovery as well as instance or system failure recovery.

If you omit both the ARCHIVELOG clause and NOARCHIVELOG clause, Oracle chooses NOARCHIVELOG mode by default. After creating the control file, you can change between ARCHIVELOG mode and NOARCHIVELOG mode with the ALTER DATABASE statement.

FORCE LOGGING

Use this clause to put the database into FORCE LOGGING mode after control file creation. When the database is in this mode, Oracle logs all changes in the database except changes to temporary tablespaces and temporary segments. This setting takes precedence over and is independent of any NOLOGGING or FORCE LOGGING settings you specify for individual tablespaces and any NOLOGGING settings you specify for individual database objects. If you omit this clause, the database will not be in FORCE LOGGING mode after the controlfile is created.

13-20 Oracle9i SQL Reference

CREATE CONTROLFILE

Note: FORCE LOGGING mode can have performance effects. Please refer to Oracle9i Database Administrator’s Guide for information on when to use this setting.

character_set_clause

If you specify a character set, Oracle reconstructs character set information in the control file. In case media recovery of the database is required, this information will be available before the database is open, so that tablespace names can be correctly interpreted during recovery. This clause is required only if you are using a character set other than the default US7ASCII. Oracle prints the current database character set to the "alert" log in $ORACLE_HOME/log during startup.

If you are re-creating your control file and you are using Recovery Manager for tablespace recovery, and if you specify a different character set from the one stored in the data dictionary, then tablespace recovery will not succeed. (However, at database open, the control file character set will be updated with the correct character set from the data dictionary.)

Note: You cannot modify the character set of the database with this clause.

See Also: Oracle9i Recovery Manager User’s Guide for more information on tablespace recovery

Example

Creating a Controlfile: Example This statement re-creates a control file. In this statement, database demo was created with the WE8DEC character set. The example uses the word path where you would normally insert the path on your system to the appropriate Oracle directories.

STARTUP NOMOUNT

CREATE CONTROLFILE REUSE DATABASE "demo" NORESETLOGS NOARCHIVELOG MAXLOGFILES 32

MAXLOGMEMBERS 2

MAXDATAFILES 32

MAXINSTANCES 1

SQL Statements: CREATE CLUSTER to CREATE JAVA 13-21

CREATE CONTROLFILE

MAXLOGHISTORY 449 LOGFILE

GROUP 1 ’/path/oracle/dbs/t_log1.f’ SIZE 500K, GROUP 2 ’/path/oracle/dbs/t_log2.f’ SIZE 500K

# STANDBY LOGFILE DATAFILE

’/path/oracle/dbs/t_db1.f’, ’/path/oracle/dbs/dbu19i.dbf’, ’/path/oracle/dbs/tbs_11.f’, ’/path/oracle/dbs/smundo.dbf’, ’/path/oracle/dbs/demo.dbf’

CHARACTER SET WE8DEC

;

13-22 Oracle9i SQL Reference

Соседние файлы в папке Oracle selected docs