INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User...

25
INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003 all rights reserved.

Transcript of INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User...

Page 1: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

INTRODUCTION TO ORACLE

Lynnwood BrownPresident System Managers LLC

Database Creation & End User Management – Lecture 3

Copyright System Managers LLC 2003 all rights reserved.

Page 2: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

MANUAL DATABASE CREATION

• Define the administrative user

• Place the administrative user in the DBA group (UNIX) or the ORA_DBA group (NT/2000)

• Windows NT/2000 service OracleService<SID> must be created using the ORADIM utility which will create the Oracle service and modify the server's registry

Copyright System Managers LLC 2003 all rights reserved.

Page 3: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

MANUAL DATABASE CREATIONCreating the Instance

C:\> ORADIM -NEW  -SID  <YOUR_SID>  -INTPWD  <password>  -STARTMODE <mode>-PFILE  <pfile>

• <YOUR_SID> - Database SID

• <password> - Password for database administrative user

• <mode> - Startup mode for the services, either AUTO or MANUAL

• <pfile> - Path and name of the INIT<sid>.ORA file

Page 4: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

MANUAL DATABASE CREATION

Deleting the Instance

C:\> ORADIM  -DELETE  -SRVC  <service_name>

NOTE: SERVICE_NAME = SID

            For Oracle 8.1 and 9.x ORADIM ERRORS ARE IN THE

DIRECTORY:

<ORACLE_HOME> \DATABASE\ORADIM.LOG

Copyright System Managers LLC 2003 all rights reserved.

Page 5: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

MANUAL DATABASE CREATIONStarting The Instance

• Ensure that the environmental variables have been set and the services have been started (NT/2000).

• Log into SQL*PLUS as the system user with administrative privileges

C:\> sqlplus “system/manager as sysdba”

SQL> startup nomount – Start the Oracle instance but do not mount or open the database. On UNIX this starts the Oracle processes and allocates the SGA

         Other startup options include MOUNT and EXCLUSIVE

Page 6: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

MANUAL DATABASE CREATION

Creating The Database

• Must have at least one tablespace (SYSTEM)

• One or more data files is specified for the SYSTEM tablespace

• Must have at least one log group or two log files

Copyright System Managers LLC 2003 all rights reserved.

Page 7: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

MANUAL DATABASE CREATION

Creating The Database 8i

SQL > create database test logfile group 1 (‘c:\oradata\test\redo01.log',

‘c:\oradata\test\redo02.log') size 5M, group 2 (‘c:\oradata\test\redo03.log', ‘c:\oradata\test\redo04.log') size 5Mmaxlogfiles 9datafile ‘c:\oradata\test\system01.dbf' size 150Mmaxdatafiles 255maxinstances 1noarchivelogcharacter set WE8ISO8859P1/

Copyright System Managers LLC 2003 all rights reserved.

Page 8: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

MANUAL DATABASE CREATIONCreating The Database

catalog.sql - Script that creates the basic Oracle Data Dictionary objects

catproc.sql - Script that creates the Oracle Data Dictionary objects for procedural option (PL/SQL)

Create Additional Tablespaces (TEMP, INDEX, DATA)

create tablespace DATAdatafile ‘c:\oradata\test\data01.dbf' size 50M reuse default storage (initial

1M next 1Mminextents 1 maxextents unlimited pctincrease 0)

Page 9: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

MANUAL DATABASE CREATION

Creating The Database (Rollback Segments) 8i

create tablespace RBS datafile 'd:\oradata\test\rbs01.dbf' size 50M reuse default storage (initial 1M next 1M

minextents 2 maxextents unlimited pctincrease 0)/

create rollback segment RBS01 storage (initial 1M next 1M minextents 2 maxextents unlimited) tablespace RBS

/

alter rollback segment RBS01 online/

Copyright System Managers LLC 2003 all rights reserved.

Page 10: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

MANUAL DATABASE CREATION

Creating The Database 9i

CREATE DATABASE testMAXLOGFILES 9 MAXINSTANCES 1 MAXDATAFILES 256 MAXLOGHISTORY 256 DATAFILE 'c:\test\system_01.dbf' SIZE 150MUNDO TABLESPACE "UNDOTBS" DATAFILE 'c:\test\undotbs_01.dbf' SIZE 150M AUTOEXTEND ON NEXT 5M MAXSIZE UNLIMITED CHARACTER SET WE8ISO8859P1LOGFILE GROUP 1 ('c:\test\redo1_01.dbf‘) SIZE 50M, GROUP 2 ('c:\test\redo1_02.dbf') SIZE 50M;

Page 11: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

MANUAL DATABASE CREATION

UNDO Tablespace

• New in Oracle 9i

• Replaces rollback segments

• RDBMS manages undo segments automatically:

• New init<SID>.ora parameters:

– UNDO_MANAGEMENT AUTO or Manual (use roll back segments)

– UNDO_TABLESPACE = <Undo tablespace name>

Page 12: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

MANUAL DATABASE CREATION

UNDO Tablespace (cont)

Creating an UNDO tablespace after the database has been created:

SQL> create undo tablespace UNDO_TS1 datafile ‘c:\oradata\undorbs1.dbf' size 100m;

SQL> alter system set undo_tablespace=undo_ts1;

Copyright System Managers LLC 2003 all rights reserved.

Page 13: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

MANUAL DATABASE CREATION

Creating And Enlarging Tablespaces

Automatically increase tablespace sizes using “AUTOEXTEND”

CREATE TABLESPACE DATA DATAFILE '/u01/oracle/rbdb1/users01.dbf' SIZE 300M REUSE AUTOEXTEND ON NEXT 5M MAXSIZE 1500M;

Add another data file if not using AUTOEXTEND

SQL > alter tablespace DATA add datafile '/u01/oracle/rbdb1/users02.dbf' size 20M;

Page 14: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

MANUAL DATABASE CREATION

Shutting Down the Database

Must be the administrative user:

SQL> shutdown normal            Other SHUTDOWN options include:

• IMMEDIATE – Allow transactions to complete and then log off all users

• ABORT – Log off all users (no grace period)

Page 15: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

END USER MANAGEMENT

• Create database users by using the CREATE/ALTER USER commands.

• Create database objects (tables, views, synonyms and indexes).

• Control database access/security by granting access privileges: grant update on emp to scott;

• Grant database access so that users can/cannot pass the privilege on to other users: grant update on emp to scott with admin option;

Copyright System Managers LLC 2003 all rights reserved.

Page 16: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

END USER MANAGEMENT

To create a user named SCOTT with password TIGER:

SQL > Create user scott identified by tiger

SQL > Default tablespace users

SQL > Temporary tablespace temp

SQL > Quota 15m on users;

Give SCOTT the privilege to connect to the database and create objects.

SQL > Grant connect, resource to scott;

Copyright System Managers LLC 2003 all rights reserved.

Page 17: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

END USER MANAGEMENT

End User Profiles – Resource Control

SQL > CREATE PROFILE new_userLIMIT sessions_per_user 10 connect_time 30 idle_time 10;

Altering User Access To Resources

SQL > ALTER USER <userID> IDENTIFIED BY <pw>profile new_user;

Page 18: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

END USER MANAGEMENT

• Create roles to automate the security/access process:

SQL > create role manager;SQL > grant update on emp to manager;SQL > grant manager to scott;

• Oracle has several pre-defined roles. One of the pre-defined roles is called DBA.

Copyright System Managers LLC 2003 all rights reserved.

Page 19: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

END USER MANAGEMENT

• How to determine the privileges a user or role has:

SQL > select grantee, privilege from sys.dba_sys_privs;

• How to determine which users are in which roles:

SQL > select grantee, granted_role from sys.dba_role_privs;

Page 20: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

OBJECT CREATION

Database objects include:

Tables – Used to store records (rows of data)

Views – Like a table but takes up no disk space. Is based on an underlying table.

Indexes – Use to speed retrieval of data from a table.

Synonyms – Used to reference objects owned by another user without having to reference the object owners name/schema.

Sequence – Used to generate a unique number

Database links – Used to access data in one database from another database.

Copyright System Managers LLC 2003 all rights reserved.

Page 21: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

OBJECT CREATION

Create Table:

Create table dept(deptno number,Creation date,Dname varchar2(10)Dloc varchar2(20);

Create View:

Create view DVIEW as select deptno, dname, dloc from dept;

Copyright System Managers LLC 2003 all rights reserved.

Page 22: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

OBJECT CREATION

Create Index:

Create index i_dept on dept(deptno);

Create Synonym:

Create public synonym dept on dept;

Create Sequence:

Create sequence dept_num start with 1 increment by 1;

Copyright System Managers LLC 2003 all rights reserved.

Page 23: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

OBJECT MANAGEMENT

System and Object Management

ALTER TABLE EMP ADD (COLx NUMBER(7,2)…..);

ALTER TABLE EMP MODIFY (COLx NUMBER(8,2));

ALTER SESSION <userID> IDENTIFIED BY <pw>;

ALTER SYSTEM SET LICENSE_MAX_SESSIONS/USERS

LICENSE_SYSTEMS_WARNINGS;

Copyright System Managers LLC 2003 all rights reserved.

Page 24: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

THE DATA DICTIONARY

SOME ORACLE DATA DICTIONARY TABLES/VIEWS FOR MANAGING END USERS:

Table/View Name Description DBA_USERS Names of all users of the databaseDBA_TABLES Names of all tables in the databaseDBA_INDEXES Names of all indexes in the databaseDBA_SYNONYMS Names of all indexes in the synonymsDBA_SEQUENCES Names of all sequences in the databaseDBA_VIEWS Names of all views in the database

There are many other tables/views in the Oracle data dictionary. Refer to the Oracle Administrators Guide for a complete list/description

Copyright System Managers LLC 2003 all rights reserved.

Page 25: INTRODUCTION TO ORACLE Lynnwood Brown President System Managers LLC Database Creation & End User Management – Lecture 3 Copyright System Managers LLC 2003.

THE DATA DICTIONARY

DATA DICTIONARY VIEWS ACCESSIBLE TO END USERS:

• DBA_<name> - End users must be granted the privilege to access the DBA views

• ALL_<name> - Objects that the end user has access to but did not create

• USER_<name> - Objects created by the end user

Copyright System Managers LLC 2003 all rights reserved.