Vous êtes sur la page 1sur 18

TAREAS PREVIAS A LAS

PRCTICAS CON ORACLE


SPATIAL
Oracle 12c y Pre 12c, Single-Tenant y No Container
Descripcin breve
El presente documento describe las tareas necesarias para poder llevar a cabo las prcticas con
Oracle Spatial, el documento se desarroll en idioma Ingls

MTI Francisco Javier Rojas Durn


francisco.javier.rojas@gmail.com

Table of Contents
Reviews of this document ............................................................................................................... 1
Previous tasks to perform before start practicing with Oracle Spatial Training material .................. 2
1.

Change in the .bash_profile * ................................................................................................. 2

2.

Creating an after startup trigger (Only if you have a Multi-Tenant Container DB)* .............. 2
Steps ............................................................................................................................................ 3

3.

Configuring DB parameters, (this applies to Container and Non-Container DB)* .................. 3

This is the expected output: ............................................................................................................ 4


4. Create additional database tablespaces (applies to Container and Non-Container DB)
Mandatory ...................................................................................................................................... 4
Option A. Using a Single-Tenant instance: .................................................................................. 5
Option B . Using a Non-container Single Instance (Pre-12c): ...................................................... 5
5.

Create the Oracle database users and grant appropriate privileges. Mandatory .................. 5

6.

Connecting to the instance with student user ........................................................................ 6

7.

Configuring Services to allow external connections to the Pluggable DB............................... 7


Steps ............................................................................................................................................ 8

Reviews of this document


Version
1.0

Author
MTI Francisco Javier Rojas Durn

Date
April 2nd 2016

MTI FRANCISCO JAVIER ROJAS DURN

Previous tasks to perform before start practicing with Oracle Spatial


Training material
Important:
This guide is intended to be use with either Oracle 12c Multitenant environment or Oracle Pre-12c
Non-Container (also works with 11gR1 R2).
Most of the tasks are optional, however those ones that are optional are marked with an (*) , the
ones that are mandatory were tagged with the legend Mandatory.
Please follow the order of this task, skip the optional ones as needed.

1. Change in the .bash_profile *


In order to use SecureShell client we need to introduce the support of DELETE key into the
bash_profile, therefore at the end of the file we must add the following:
stty erase ^H
This should be bash_profile after this change:
# Oracle Settings
export TMP=/tmp
export TMPDIR=$TMP
export
export
export
export
export

ORACLE_HOSTNAME=db.oracledemo.com
ORACLE_UNQNAME=cdborcl
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/12.1.0.2/db_1
ORACLE_SID=cdborcl

export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
stty erase ^H

2. Creating an after startup trigger (Only if you have a Multi-Tenant Container DB)*
In a CDB environment, the default behavior when a CDB is started is that all user-defined PDBs are
in MOUNTED state i.e. closed. The only way to change this behavior is by using an AFTER STARTUP
trigger on the database.

In this exercise, you will create AFTER STARTUP trigger to open all PDBs of a CDB. The AFTER
MTI FRANCISCO JAVIER ROJAS DURN

STARTUP trigger is a database event trigger, which means that the user creating the trigger should
have ADMINISTER DATABASE TRIGGER system privilege. The trigger will only fire after the startup
event on the database.

Steps
1. Connect to the Root container of CDBORCL as a SYSDBA user.
. oraenv
[Enter cdborcl at the prompt]
sqlplus / as SYSDBA

2. Create a trigger in CDBORCL to open all PDBs automatically after starting up


CDBORCL.
CREATE OR REPLACE TRIGGER
AFTER_STARTUP AFTER STARTUP ON
DATABASE
BEGIN
EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL
OPEN'; END AFTER_STARTUP;
/
SHOW ERRORS;

3. Restart the database CDBORCL.


SHUTDOWN
IMMEDIATE;
STARTUP;

4. Observe that the PDBs are in READ WRITE open mode.


SELECT CON_ID, NAME, OPEN_MODE FROM V$PDBS;

3. Configuring DB parameters, (this applies to Container and Non-Container DB)*


1. Modify the DB_CACHE_SIZE database initialization parameter to be at least 75 MB.
Notice that this parameter will apply either to the Container and all the PDBs.
a. sqlplus system/Manager1;
b. SHOW PARAMETER db_cache_size
2. If the db_cache size is less than 75M (megabytes) type:
a.
b.
c.
d.
e.

ALTER SYSTEM SET db_cache_size=75M scope=spfile;


shutdown;
startup;
SHOW PARAMETER db_cache_size
exit

MTI FRANCISCO JAVIER ROJAS DURN

This is the expected output:

4. Create additional database tablespaces (applies to Container and Non-Container


DB) Mandatory
In SQL*Plus, assuming you are connected as system user, run the following statements:
In Multi-Tenant Container instance:
ALTER SESSION SET CONTAINER=PDBORCL;
Be sure your current container is PDBORCL
COLUMN NAME FORMAT A8;
SELECT NAME, CON_ID, DBID, CON_UID, GUID
FROM V$CONTAINERS ORDER BY CON_ID;
This is the expected output:

MTI FRANCISCO JAVIER ROJAS DURN

Option A. Using a Single-Tenant instance:


create tablespace student datafile
'/u01/app/oracle/oradata/cdborcl/pdborcl/student.dbf' size 150M;
create tablespace indx_tblspc datafile
'/u01/app/oracle/oradata/cdborcl/pdborcl/indx_tblspc.dbf' size
150M;
create tablespace work_indx_tblspc datafile
'/u01/app/oracle/oradata/cdborcl/pdborcl/work_indx_tblspc.dbf'
size 100M;

Option B . Using a Non-container Single Instance (Pre-12c):

create tablespace student datafile 'student.dbf' size 150M;


create tablespace indx_tblspc datafile 'indx_tblspc.dbf' size
150M;
create tablespace work_indx_tblspc datafile 'work_indx_tblspc.dbf'
size 100M;

5. Create the Oracle database users and grant appropriate privileges. Mandatory
Assuming you are still logged in as system/Manager1 either in the Non-container single-instance
or into the Pluggable DB (PDBORCL)
In Single-Tenant Container instance:
ALTER SESSION SET CONTAINER=PDBORCL;
Be sure your current container is PDBORCL and also it is open:
SHOW CON_ID;
SHOW CON_NAME;
ALTER PLUGGABLE DATABASE OPEN;
Execute the following:

MTI FRANCISCO JAVIER ROJAS DURN

create user student identified by student default tablespace


student;
grant connect, resource to student;
alter user student quota unlimited on student;

This is the expected output:

6. Connecting to the instance with student user


After creating the user student , the only way to connect in a multi-tenant environment is through
EZCONNECT, since we havent created the SERVICE yet, we are able to connect as follows:

$sqlplus student/student@//[HOSTNAME|IP]:1521/pdborcl
This is the expected output:

MTI FRANCISCO JAVIER ROJAS DURN

7. Configuring Services to allow external connections to the Pluggable DB.


Mandatory.
When a PDB is created, a new default service for the PDB is created automatically, and has
the same name as the PDB. You cannot manage this service, and it should only be used for
administrative tasks.

Do not use this default PDB service for applications. Always use user-defined services for
applications because you can customize user-defined services to fit the requirements of your
applications.
MTI FRANCISCO JAVIER ROJAS DURN

You can create, modify, or remove a service with a PDB property in the following ways:
If the database is not being managed by Oracle Restart or Oracle Clusterware, then use
the DBMS_SERVICE package to create or remove a database service. This is the
method you will follow in this task.
Note: Each database service name must be unique in a CDB, and each database service
name must be unique within the scope of all the CDBs whose instances are reached through a
specific listener.

Steps
1. When you create a service using the DBMS_SERVICE package, the PDB property of the new
service is set to the current container. Therefore, login to the PDB that you want to
create/modify/delete the user-defined services before running the DBMS_SERVICE procedures.
If you run DBMS_SERVICE.CREATE_SERVICE in the root container then the service is associated
with the root.
Connect as SYS to PDBORCL with the SYSDBA role.
CONNECT SYS/Manager1@//127.0.0.1:1521/PDBORCL AS
SYSDBA;
SELECT CON_ID, NAME, OPEN_MODE FROM V$PDBS;
2. Create the service by the name PORCL using the DBMS_SERVICE.CREATE_SERVICE procedure.
EXEC DBMS_SERVICE.CREATE_SERVICE (SERVICE_NAME=>'PORCL',
NETWORK_NAME=>'PORCL');

3. Check to see if the newly created PORCL service shows up in V$SERVICES.


SELECT NAME FROM V$SERVICES;

At this point this is the expected output:

MTI FRANCISCO JAVIER ROJAS DURN

4. Start the newly created PORCL service using DBMS_SERVICE.START_SERVICE procedure.


Check if the newly created service is started using the V$SERVICES view, and also in the listener
services.
EXEC DBMS_SERVICE.START_SERVICE('PORCL');
SELECT NAME, PDB FROM V$SERVICES;
HOST lsnrctl services

5. Reconnect to PDBORCL using the PORCL service. Verify that you are reconnected back to
PDB PDBORCL.
CONNECT SYS/oracle@//127.0.0.1:1521/PORCL AS SYSDBA;
SELECT CON_ID, NAME, OPEN_MODE FROM V$PDBS;

6. Now connect with the student user:

MTI FRANCISCO JAVIER ROJAS DURN

sqlplus student/student@//127.0.0.1:1521/PORCL;

Once he have configured the SERVICE , we must configure clients to use this SERVICE.
In our VM we must run NETCA in order to create a SERVICE entry within TNSNAMES.ORA
In a terminal window logged with the user oracle , run the command NETCA.

MTI FRANCISCO JAVIER ROJAS DURN

1
0

Select Local Net Service Name Configuration


Please proceed with the next steps inside NETCA by choosing the same options as follows:

MTI FRANCISCO JAVIER ROJAS DURN

1
1

Pleas provide a SERVICE NAME for PDBORCL.

MTI FRANCISCO JAVIER ROJAS DURN

1
2

Please provide your hostname name or IP.

MTI FRANCISCO JAVIER ROJAS DURN

1
3

Click on Change Login in order to provide a different user/password.

MTI FRANCISCO JAVIER ROJAS DURN

1
4

MTI FRANCISCO JAVIER ROJAS DURN

1
5

Please write the short name of the SERVICE_NAME.

MTI FRANCISCO JAVIER ROJAS DURN

1
6

Now we should close NETCA window, and connect from SQLPLUS with the user student as shown
below:

From now we can connect to PDBORCL as if we were using a Pre-12c Non-Container DB.

MTI FRANCISCO JAVIER ROJAS DURN

1
7

Vous aimerez peut-être aussi