D78846GC20 Ag
D78846GC20 Ag
D78846GC20 Ag
James L. Spiller This document contains proprietary information and is protected by copyright and
other intellectual property laws. You may copy and print this document solely for your
own use in an Oracle training course. The document may not be modified or altered
Technical Contributors in any way. Except where your use constitutes "fair use" under copyright law, you
and Reviewers may not use, share, download, upload, copy, print, display, perform, reproduce,
publish, license, post, transmit, or distribute this document in whole or in part without
Daryl Balaski the express authorization of Oracle.
Rainer Bien
The information contained in this document is subject to change without notice. If you
Maria Billings find any problems in the document, please report them in writing to: Oracle University,
500 Oracle Parkway, Redwood Shores, California 94065 USA. This document is not
Andy Fortunak warranted to be error-free.
Joel Goodman
Restricted Rights Notice
Daniela Hansell
Pat Huey If this documentation is delivered to the United States Government or anyone using
the documentation on behalf of the United States Government, the following notice is
Publishers
Veena Narasimhan
Jayanthy Keshavamurthy
Table of Contents
Practices for Lesson 1: Introduction ..............................................................................................................1-1
Practices for Lesson 1: Overview ...................................................................................................................1-2
Practices for Lesson 2: Exploring Oracle Database Architecture ...............................................................2-1
Practices for Lesson 2: Overview ...................................................................................................................2-2
Practice 2-1: Exploring the Oracle Database Architecture .............................................................................2-3
Practices for Lesson 3: Oracle Database Management Tools .....................................................................3-1
Practices for Lesson 3: Overview ...................................................................................................................3-2
Practice 3-1: Registering the orcl Database in Oracle Enterprise Manager Cloud Control ............................3-3
Practice 3-2: Creating an Administrative User ...............................................................................................3-7
Practice 3-3: Logging In to Oracle Enterprise Manger Database Express .....................................................3-10
Practices for Lesson 4: Managing the Database Instance ...........................................................................4-1
Practices for Lesson 4: Overview ...................................................................................................................4-2
In this practice, you review Oracle Database architecture concepts and answer questions to test
your knowledge of the lesson topics.
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
d. On the “Database Discovery: Search Criteria” page, use the Search icon to select your
host target on the Search Targets page. Click Next.
Tasks
1. If you are not logged in to Enterprise Manager Cloud Control, launch Enterprise Manager
Cloud Control and log in as the SYSMAN user.
2. On the top-right corner of the page, click Setup > Security > Administrators.
Tasks
1. It is good practice to create a user separate from SYS and SYSTEM to perform database
administration tasks. Each DBA in your organization should have his or her own privileged
account to aid in auditing. Create a privileged user named DBA1 and grant this user the
CONNECT, DBA, and SYSDBA roles by using a script named lab_03_03_01.sh. You will
examine this script later after discussing user security.
2. Invoke EM Express and log in as the DBA1 user. Which port number does this database
use? Because each database on the same machine must use a different port, you can
discover the port numbers being used by executing the following PL/SQL block.
DECLARE
port NUMBER;
Begin
port := dbms_xdb_config.gethttpport;
dbms_output.put_line('DB user port for EM
Express:'||to_char(PORT));
END;
a. In the Linux command window, set your environment to the orcl database by using
oraenv.
$ . oraenv
ORACLE_SID = [oracle] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1 is
/u01/app/oracle
$
Note: 5500 is the Enterprise Manager Database Express port in this database.
c. Click the Firefox Web Browser icon on the top toolbar to open your web browser as
the oracle user.
3a.
4. Using SQL*Plus, verify that you are not able to connect as the HR user to a database that
has been shut down.
Enter password:
ERROR:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3640
Additional information: 1371676159
Process ID: 0
Session ID: 0 Serial number: 0
Enter user-name:
d. Press Ctrl + D to exit the username prompt.
5. Use Cloud Control to restart the database instance.
a. In Cloud Control, navigate to the Startup/Shutdown page by selecting Oracle
Database > Control > Startup/Shutdown.
b. In Host Credentials, select Credential: Named. Select ORCL_HOST.
c. In Database Credentials, select Credential: Named. Select ORCL_SYS. Click OK.
d. On the Confirmation Page, click Advanced Options to see the modes and options
available for starting up, but do not change the startup options.
e. Click Cancel to return to the previous page. Click Yes.
f. The Startup/Shutdown:Activity Information is displayed. Wait for the next page.
The orcl home page appears.
Tasks
1. Invoke EM Express and log in as the DBA1 user.
a. Click the Firefox Web Browser icon on your desktop to open your web browser as the
oracle user.
b. Enter the following URL: http://localhost:5500/em.
c. In the Oracle Enterprise Manager Database Express login page, enter DBA1 as the
2. View the initialization parameters and set the JOB_QUEUE_PROCESSES parameter to 15.
What SQL statement is run to do this?
a. On the ORCL database home page, select Configuration > Initialization
Parameters.
f. Click OK on the Confirmation page, and then click OK on the Set Initialization
Parameter page.
g. Click OK on the Confirmation page.
h. Log out of EM Express.
Question: What is the significance of a check in the Dynamic column?
Answer: A “dynamic” parameter can be modified while the database is running.
Tasks
1. Set the JOB_QUEUE_PROCESSES initialization parameter to 1000 by using SQL*Plus.
a. In the Linux command window set your environment to the orcl database by using
oraenv.
$ . oraenv
ORACLE_SID = [oracle] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1 is
System altered.
3. Use the SHOW PARAMETER command to verify the settings for SGA_MAX_SIZE,
DB_CACHE_SIZE, and SHARED_POOL_SIZE.
SQL> show parameter sga_max_size
Tasks
1. In the alert log, view the phases that the database went through during startup. What are
they?
Use ADRCI to view the alert log. Select the option for the diag/rdbms/orcl/orcl
directory.
Note: The list of home directories may vary from what is shown in the code box below.
1: diag/rdbms/em12rep/em12rep
2: diag/rdbms/orcl/orcl
3: diag/tnslsnr/EDRSR32P1/listener
Q: to quit
Note: This opens the alert file using the vi editor by default
2. Scroll through the log and review the phases of the database during startup. Use the vi
search commands to find the appropriate lines. Your alert log may differ from what is shown
in this practice.
a. Enter G to move to bottom of the file.
b. Enter the string: ?Starting ORACLE instance? [CR] to search from the bottom
of the file to find the last time the instance was started. The following will be similar to
your alert log. Note: Case is significant in the search command.
2012-10-31 08:43:37.541000 +00:00
WARNING: failed to retrieve DB spfile location (unable to
communicate with CRSD/OHASD)
Starting ORACLE instance (normal)
CLI notifier numLatches:3 maxDescs:519
************************ Large Pages Information
*******************
Per process system memlock (soft) limit = 64 KB
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
1: diag/rdbms/em12rep/em12rep
2: diag/rdbms/orcl/orcl
3: diag/tnslsnr/EDRSR32P1/listener
Q: to quit
SQL>
If you receive any errors or warnings, resolve them.
c. At the SQL> prompt, enter the following command, and then exit from SQL*Plus:
SQL> select instance_name, host_name from v$instance;
INSTANCE_NAME HOST_NAME
------------- -------------------------------------------
orcl <assigned_hostname>
SQL> exit
Starting /u01/app/oracle/product/12.1.0/dbhome_1/bin/tnslsnr:
please wait...
Connecting to
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=EDRSR9P1)(PORT=1561)))
STATUS of the LISTENER
------------------------
Alias listener2
System altered.
SQL> exit
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=edRSr9p1.us.oracle.com
)(PORT=1561)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=edRSr9p1.us.oracle.com
)(PORT=5500))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "orcl" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this
service...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this
service...
The command completed successfully
SQL> exit
Connecting to
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=EDRSR9P1)(PORT=1561)))
The command completed successfully
7. Reset the LOCAL_LISTENER initialization parameter to the default value.
a. Log in to SQL*Plus as the DBA1 user with the AS SYSDBA option.
b. Execute the ALTER SYSTEM RESET LOCAL_LISTENER command to reset the
initialization parameter to the default value.
SQL> alter system reset local_listener scope=spfile;
System altered.
c. Shut down the database instance with the IMMEDIATE option.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
User created.
Grant succeeded.
SQL> exit
Disconnected …
$
2. Create a profile named HRPROFILE that allows only 15 minutes idle time.
Invoke Enterprise Manager Database Express. Log in as the DBA1 user with the SYSDBA
role. Then execute the following steps:
Step Window/Page Description Choices or Values
a. EM Express Select Security > Profiles
b. Profiles Select Create Profile.
c. Create Profile Dialog: New Profile Enter HRPROFILE in the Name field.
3. Set the RESOURCE_LIMIT initialization parameter to TRUE so that your profile limits are
enforced.
Step Window/Page Description Choices or Values
a. Select Configuration > Initialization
Parameters
b. Initialization Parameters Enter resource_limit in the Name field.
Grant succeeded.
Grant succeeded.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
User created.
Grant succeeded.
Grant succeeded.
Disconnected …
$
Note: The double ampersand && indicates to SQL*Plus to keep the value of this variable
and use the same value each time it sees this variable. If you had used a single ampersand
&, SQL*Plus would have prompted you to enter the value each time the substitution
variable occurred in the script.
4. Test the new users in SQL*Plus. Connect to the orcl database as the DHAMBY user. Use
oracle_4U as the new password. Select the row with EMPLOYEE_ID=197 from the
HR.EMPLOYEES table. Then attempt to delete it. You should get the “insufficient privileges”
error.
a. In a terminal window, enter:
$ . oraenv
ORACLE_SID = [oracle] ? orcl
…
$ sqlplus dhamby
Or, if you already have a SQL*Plus session started, use the CONNECT command. If
you reconnect as dhamby in SQL*Plus, the login and change-of-password session
look like this:
SQL> CONNECT dhamby
In either case, the next line will be a prompt for the password.
c. Select the salary for employee 197 from the HR.EMPLOYEES table.
SQL> SELECT salary FROM hr.employees WHERE EMPLOYEE_ID=197;
SALARY
----------
3000
d. Now attempt to delete the same row from the HR.EMPLOYEES table.
SQL> DELETE FROM hr.employees WHERE EMPLOYEE_ID=197;
DELETE FROM hr.employees WHERE EMPLOYEE_ID=197
*
ERROR at line 1:
ORA-01031: insufficient privileges
5. Repeat the test as the JGOODMAN user. Use oracle_4U as the new password. After
deleting the row, issue a rollback, so that you still have the original 107 rows.
a. Connect to the orcl database as the JGOODMAN user.
SQL> connect jgoodman
Enter password:
ERROR:
ORA-28001: the password has expired
Changing password for jgoodman
New password: *******
Retype new password: *******
Password changed
Connected.
SQL>
SALARY
----------
3000
1 row deleted.
Rollback complete.
COUNT(*)
----------
107
SQL>
Question: You did not grant the CREATE SESSION system privilege to any of the new
users, but they can all connect to the database. Why?
Answer: CREATE SESSION is one of the privileges of the CONNECT role.
6. Use SQL*Plus to connect to the orcl database as the RPANDYA user. Change the
password to oracle_4U. (You must change the password, because this is the first
connection as RPANDYA.) Leave RPANDYA connected during the next lesson or at the end
of the day. HRPROFILE specifies that users whose sessions are inactive for more than 15
minutes will automatically be logged out. Verify that the user was automatically logged out
by trying to select from the HR.EMPLOYEES table again.
SQL> SELECT salary FROM hr.employees WHERE EMPLOYEE_ID=197;
ERROR at line 1:
ORA-02396: exceeded maximum idle time, please connect again
In this practice, you examine existing storage structure information for your database.
Assumptions: The lab_03_03_01.sh script has already been executed to create a user
named DBA1 in the database. This user has SYSDBA privileges.
1. Launch Enterprise Manager Cloud Control and log in as ADMIN.
2. Navigate to the orcl Database Home page.
a. Navigate to your target database: Targets > Databases.
b. Select the Search List radio button at the top of the page.
c. On the Databases page, click orcl.
Answer: SH.CUSTOMERS_PK
SQL> exit
Connected to:
…
SQL> @lab_07_02_03.sql
c. Note that there is eventually an ORA-01653 error indicating that the table cannot be
extended. There is not enough space to accommodate all the rows to be inserted.
...
SQL> insert into x select * from x
2 /
SQL> commit
2 /
Commit complete.
SQL> quit
Disconnected …
Connected to:
...
PL/SQL procedure successfully completed.
Table created.
1 row created.
1 row created.
2 rows created.
4 rows created.
8 rows created.
16 rows created.
32 rows created.
64 rows created.
SQL> COMMIT;
Commit complete.
SQL> quit
c. Note that the same number of row inserts is attempted, but there is no error because of
the increased size of the tablespace.
Enter password:
Connected to:
…
Table dropped.
SQL> exit
Task
Access the orcl database as the SYS user (with the oracle_4U password, connect as
SYSDBA) and perform the necessary tasks through Enterprise Manager Cloud Control or
through SQL*Plus. All scripts for this practice are in the $LABS/P8 directory.
1. Using the DBMS_SERVER_ALERT.SET_THRESHOLD procedure, reset the database-wide
threshold values for the Tablespace Space Usage metric. Connect to a SQL*Plus session
and execute the following procedure:
SQL>
2. From your SQL*Plus session, check the database-wide threshold values for the Tablespace
Space Usage metric by using the following command (output formatted for clarity):
SQL> SELECT warning_value,critical_value
2 FROM dba_thresholds
3 WHERE metrics_name='Tablespace Space Usage'
4 AND object_name IS NULL;
WARNING_VALUE CRITICAL_VALUE
------------- --------------
85 97
SQL>
Tablespace created.
SQL>
4. In Enterprise Manager Cloud Control, navigate to the orcl database home page. Then
Select Administration > Storage > Tablespaces.
5. Select the New radio button. Enter SYS in the Username field, oracle_4U in the Password
field, and choose SYSDBA in the Role field. Then click Login.
7. Return to your SQL*Plus session and check the new threshold values for the TBSALERT
tablespace. In your SQL*Plus session, enter (output formatted):
SQL> select warning_value,critical_value
2 from dba_thresholds
3 where metrics_name='Tablespace Space Usage' and
4 object_name='TBSALERT';
WARNING_VALUE CRITICAL_VALUE
------------- --------------
55 70
SQL>
8. In your SQL*Plus session, query the REASON and RESOLUTION columns from
DBA_ALERT_HISTORY for the TBSALERT tablespace. Exit from SQL*Plus.
SQL> select reason, resolution
2 from dba_alert_history
REASON RESOLUT
-------------------------------------------------------- -------
Threshold is updated on metrics "Tablespace Space Usage" cleared
SQL> EXIT
Disconnected …
$
9. Review and execute the $LABS/P8/seg_advsr_setup.sh script that creates and
populates new tables in the TBSALERT tablespace.
$ cd $LABS/P8
$ cat seg_advsr_setup.sh
BEGIN
FOR i in 1..10 LOOP
insert into employees1 select * from employees1;
insert into employees2 select * from employees2;
insert into employees3 select * from employees3;
insert into employees4 select * from employees4;
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
SQL> Connected.
SQL>
System altered.
SQL> Disconnected …
$
10. Check the fullness level of the TBSALERT tablespace by using Enterprise Manager Cloud
Control or SQL*Plus. The current level should be around 60 percent. Wait a few minutes
and check that the warning level is reached for the TBSALERT tablespace. (If you are too
fast and receive errors, just use your browser’s Refresh button, or select your destination
again.)
a. While you are logged in to SQL*Plus as the SYS user, enter:
$ sqlplus / as sysdba
…
Connected to:
…
SQL> select sum(bytes) *100 /125829120
2 from dba_extents
3 where tablespace_name='TBSALERT';
SUM(BYTES)*100/125829120
------------------------
60
SQL>
Note: You created the tablespace with 120 MB (125829120 bytes) of space
REASON
--------------------------------------------------------------
Tablespace [TBSALERT] is [60 percent] full
SQL>
Note: If your result is “no rows selected,” wait a little longer and repeat the query.
c. In Enterprise Manager Cloud Control, return to the Tablespaces page.
d. On the Tablespaces page, see Allocated Space Used (%).
11. In your SQL*Plus session, execute the inserts below to add more data to TBSALERT. Wait
a few moments and view the critical level through a query in SQL*Plus and Enterprise
Manager Cloud Control. Verify that TBSALERT fullness is around 75 percent.
a. Execute the following commands:
SQL> insert into employees4 select * from employees4;
SQL> commit;
Commit complete.
SQL> commit;
Commit complete.
SQL>
SUM(BYTES)*100/125829120
------------------------
75
SQL>
c. Check the outstanding alerts. You may need to wait a few minutes.
REASON MESSAGE_LEVEL
-------------------------------------------- -------------
SQL>
d. In Enterprise Manager Cloud Control, navigate to the Administration > Storage >
Tablespaces page, and review Allocated Space Used (%).
e. Navigate to Oracle Database > Home and check the list of incidents and problems in
the Incidents and Problems section.
Or navigate to Oracle Database > Monitoring > Incident Manager and click Events
without incidents. You should see the new alert.
It will take several minutes for the change in status to take effect.
Note: You should now see a red flag instead of the yellow one. Check “All open incidents” if
you do not see the event in “Events without incidents.”
Commit complete.
SQL> commit;
Commit complete.
SQL> commit;
Commit complete.
SQL> exit
SQL> Disconnected …
l. You can see that there are three recommendations for the TBSALERT tablespace. Click
the 3 in the Recommendations column.
14. Wait a few minutes and check that there are no outstanding alerts for the TBSALERT
tablespace. Navigate to the Oracle Database > Monitoring > Incident Manager > Events
without incidents.
d. This takes you to the Status History: Tablespace Space Used (%). Select “Last 24
hours” from the View Data drop-down list. Note that your display may vary somewhat
from what is shown in the screenshot.
no rows selected
SQL> EXIT
Disconnected …
$
$ cat seg_advsr_cleanup.sh
#!/bin/sh
# For training only, execute as oracle OS user
$ ./seg_advsr_cleanup.sh
SQL> Connected.
SQL>
System altered.
Database mounted.
Database opened.
SQL>
Tablespace dropped.
SQL>
$
Question: Looking at the preceding Undo Retention Auto-Tuning graph, could this system
support flashback above and beyond the current longest running query?
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Make note of the recommended undo tablespace size. Note: Your recommended size
might be different from what is shown here.
3. Go back to the Automatic Undo Management page to see the results of the changes that
you just made. You see that the undo retention time has increased to support the 48 hours
requirement. Your undo tablespace size has also increased based on the changes that you
made to the size of the data file for the undo tablespace.
Connected to:
…
SQL> show user
USER is "NGREENBERG"
SQL> update hr.employees set phone_number='650.555.1212'
2> where employee_id = 110;
1 row updated.
SQL>
c. Leave this session connected in the state that it is currently. Do not exit at this time.
2. In a separate terminal window, attempt to update the same row in a separate session by
executing the SQL statement shown below. Do not worry if the session seems to “hang”—
this is the condition that you are trying to create.
a. Open a second terminal window. Log in to SQL*Plus as the SMAVRIS user with the
password oracle_4U.
$ sqlplus smavris
…
Enter password:
…
b. Notice that this session appears to be hung. Leave this session as is and move on to
the next step.
3. Using EM Express, navigate to the Current Findings tab of the Performance Hub page and
determine which session is causing the locking conflict.
a. In EM Express, select Performance > Performance Hub. Then click the Current
ADDM Findings tab. In the Findings section, click the detail finding “Unresolved hangs
or session wait chains.”
Note: You will resolve the blocking session in Enterprise Manager Cloud Control in
subsequent steps. However, note that you could execute the following statement as
SYSDBA to kill the session:
ALTER SYSTEM KILL SESSION (38,45678);
You could also issue the following command as an OS sys administrator to stop the OS
process associated with the blocking session.
$ kill 26623
4. Using Cloud Control, find the details of the blocking session.
a. Log in to Cloud Control as the admin user with the password oracle_4U. Then
navigate to the orcl home page.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
c. Under the Application heading, click the hash value link for Current SQL or Previous
SQL.
6. Resolve the conflict in favor of the user who complained, by killing the blocking session.
a. Click Performance > Blocking Sessions.
b. Select the NGREENBERG session, and then click Kill Session.
e. Click Return.
f. Click Yes.
g. On the Blocking Sessions page, the listing is gone, and an information message
appears saying that session nnn has been killed.
1 row updated.
SQL> ROLLBACK;
Rollback complete.
SQL> exit
8. Try issuing a SQL select statement in the NGREENBERG session. What do you see?
SQL> SELECT sysdate from dual;
SELECT sysdate from dual
*
ERROR at line 1:
ORA-03135: connection lost contact
Process ID: 26623
Session ID: 38 Serial number: 45678
SQL>
Answer: The session has been disconnected. There could be other errors such as:
− ORA-12571: TNS:packet writer failure
− ORA-03114: not connected to ORACLE
9. Close all open SQL sessions by entering exit, and then close the terminal windows.
Tasks
1. Shut down all Oracle processes of all instances.
a. Shut down the listener.
$ . oraenv
[ORACLE_SID = [orcl] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1 is
/u01/app/oracle
Connecting to
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ed.us.oracle.com)(PORT
=1521)))
The command completed successfully
b. Shut down all instances.
$ pgrep –lf pmon
6871 ora_pmon_em12rep
28985 ora_pmon_orcl
$
1) Shut down the orcl instance.
$ sqlplus / as sysdba
…
Connected to:
…
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> EXIT
Disconnected …
$ sqlplus / as sysdba
…
Connected to:
…
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> EXIT
Disconnected …
$
3) Verify that all instances are down.
$ pgrep -lf pmon
$
2. Enable the unified auditing feature.
$ cd $ORACLE_HOME/rdbms/lib
$ make -f ins_rdbms.mk uniaud_on ioracle
/usr/bin/ar d
/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/lib/libknlopt.a
kzanang.o
/usr/bin/ar cr
/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/lib/libknlopt.a
/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/lib/kzaiang.o
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
- Linking Oracle
rm -f /u01/app/oracle/product/12.1.0/dbhome_1/rdbms/lib/oracle
/u01/app/oracle/product/12.1.0/dbhome_1/bin/orald -o
/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/lib/oracle -m64 -z
noexecstack -
…
mv /u01/app/oracle/product/12.1.0/dbhome_1/rdbms/lib/oracle
/u01/app/oracle/product/12.1.0/dbhome_1/bin/oracle
chmod 6751 /u01/app/oracle/product/12.1.0/dbhome_1/bin/oracle
$
3. Restart the processes.
Starting /u01/app/oracle/product/12.1.0/dbhome_1/bin/tnslsnr:
please wait...
Connecting to
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=edp1.us.oracle.com)(PO
RT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0
- Production
Start Date 13-OCT-2014 13:16:20
Uptime 0 days 0 hr. 0 min. 0 sec
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=edp1.us.oracle.com)(PO
RT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
$ sqlplus / as sysdba
…
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 503316480 bytes
Fixed Size 2926080 bytes
Variable Size 268438016 bytes
Database Buffers 226492416 bytes
Redo Buffers 5459968 bytes
Database mounted.
Database opened.
VALUE
--------------------------------------------------------------
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
SQL> EXIT
e. Start the OMS. Note that this command can take 10 minutes or so to complete.
$ /u01/app/oracle/product/middleware/oms/bin/emctl start oms
Oracle Enterprise Manager Cloud Control 12c Release 4
Copyright (c) 1996, 2014 Oracle Corporation. All rights
reserved.
Starting Oracle Management Server...
Starting WebTier...
WebTier Successfully Started
Oracle Management Server Successfully Started
Oracle Management Server is Up
$
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Assumptions
Unified auditing has been enabled in the orcl database. Preferred SYSDBA credentials have
been set.
Tasks
1. Create a database user to be the administrator of the audit settings and policies. Name this
user AUDMGR with the password oracle_4U, and assign the AUDIT_ADMIN role to this
Assumptions
The AUDMGR user has been created. Several users with DML privileges on HR.JOBS have been
created.
Tasks
1. Invoke SQL*Plus and connect to the orcl database as the AUDMGR user. Create a policy
named JOBS_AUDIT_UPD that audits all auditable statements for the HR.JOBS table.
Audit succeeded.
3. View information about the audit policy.
SQL> column POLICY_NAME format A20
SQL> column USER_NAME format A20
SQL> SELECT policy_name, enabled_opt,
2> user_name, success, failure
3> FROM audit_unified_enabled_policies;
SQL>
4. Test the audit policy by connecting as a user that has privileges to update rows in the
HR.JOBS table.
a. Connect as the DHAMBY user and update MAX_SALARY of the President to $50000.
SQL> connect DHAMBY
Enter password:
Connected.
SQL> desc hr.jobs
Name Null? Type
--------------------------- -------- -------------------------
JOB_ID NOT NULL VARCHAR2(10)
JOB_TITLE NOT NULL VARCHAR2(35)
MIN_SALARY NUMBER(6)
MAX_SALARY NUMBER(6)
1 row updated.
b. Connect as the AUDMGR user and view the audit trail records for this change.
Note: Your output may vary from what is shown depending on how many times you
have logged on and logged off as the DHAMBY user. For this practice, you are
interested in the row for the JOBS_AUDIT_UPD policy.
$ sqlplus audmgr
Enter password:
SQL> col unified_audit_policies format a25
SQL> col action_name format a10
SQL> col object_schema format a10
SQL> col object_name format a10
SQL>
2. Review the fast recovery area configuration and change the size to 8 GB.
a. In Enterprise Manager Database Express, select Configuration > Initialization
Parameters.
g. Optionally, click Show SQL, review the statement, and click OK.
3. Check how many members each redo log group has. Ensure that there are at least two
redo log members in each group. One set of members should be stored in the fast recovery
area.
a. Click Storage > Redo Log Groups.
c. Select one of your redo log groups and click “Add Member…” to add another member
to the Redo Log Group.
h. Repeat steps c, d, and e to add another member to the other two redo log groups. After
repeating these steps, you should have two members in each redo log group.
SQL>
Database altered.
SQL>
f. Open the database.
SQL> ALTER DATABASE OPEN;
Database altered.
SQL>
System altered.
SQL> ALTER SYSTEM SET
log_archive_dest_2='LOCATION=/u01/app/oracle/oradata/orcl/archiv
e_dir2' SCOPE=both;
System altered.
SQL>
c. Perform a few log switches. Verify that archive logs are created in both destinations by
querying V$ARCHIVED_LOG. Exit from SQL*Plus.
SQL> ALTER SYSTEM SWITCH LOGFILE;
System altered.
System altered.
System altered.
NAME
--------------------------------------------------------------
6 rows selected.
SQL> EXIT
Assumptions
Practices for lesson 13 have been successfully completed.
Tasks
1. Launch Enterprise Manager Cloud Control and log in as the ADMIN user.
2. Navigate to the orcl database home page.
3. Select Administration > Storage > Control Files.
Database altered.
SQL> exit
8. Navigate to the /u01/app/oracle/diag/rdbms/orcl/orcl/trace directory and view
the end of the alert log to verify the creation of the trace files and the names of the files.
$ cd /u01/app/oracle/diag/rdbms/orcl/orcl/trace
[trace]$ tail alert_orcl.log
Wed Oct 15 12:43:15 2014
ALTER DATABASE BACKUP CONTROLFILE TO TRACE
Wed Oct 15 12:43:15 2014
Backup controlfile written to trace file
/u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_21975.trc
Completed: ALTER DATABASE BACKUP CONTROLFILE TO TRACE
Wed Oct 15 12:47:30 2014
alter database backup controlfile to trace
Wed Oct 15 12:47:30 2014
Tasks
1. Return to the orcl database home page in Enterprise Manager Cloud Control.
2. Select Availability > Backup & Recovery > Backup Settings.
Tasks
1. In Enterprise Manager Cloud Control, select Availability > Backup & Recovery >
Schedule Backup.
3. In the Backup Type section, select Full Backup and “Use as the base of an incremental
backup strategy.”
4. In the Backup Mode section, select Online Backup.
Tasks
1. Log in to SQL*Plus as the HR user and query the REGIONS table.
$ sqlplus hr
Enter password:
SQL> SELECT * FROM regions;
REGION_ID REGION_NAME
Java created.
Procedure created.
PL/SQL procedure successfully completed.
…
Grant succeeded.
SQL>
SQL>
6. Use Enterprise Manager Cloud Control to troubleshoot the error and recover the data file.
a. Launch Enterprise Manager Cloud Control and log in as the ADMIN user.
b. Navigate to the orcl database home page.
c. Log in with your saved database credentials.
d. Expand Oracle Database. Select Monitoring > Incident Manager. Note that there is
a critical error listed, indicating a data failure.
j. Review the RMAN script that will be used to restore the file and perform recovery. Click
Continue.
m. On the Job Run page, verify that the status is “Succeeded.” Then return to the orcl
database home page.
REGION_ID REGION_NAME
---------- -------------------------
1 Europe
2 Americas
3 Asia
4 Middle East and Africa
SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release
12.1.0.1.0 - 64bit Production
p. Select “Clear and do not send e-mail or page notifications.” Click OK to confirm.
q. Return to the orcl database home page.
Grant succeeded.
Grant succeeded.
SQL> exit
$
COUNT(*)
----------
107
SQL> exit
$
User altered.
SQL> exit
$
c. Optionally, view the product_descriptions.dat file to learn more about its
structure before going further. This file is in the $LABS/P16 directory.
$ cd $LABS/P16
$ cat product_descriptions.dat
4001,ENG,Door,Outdoor
4002,FRE,Porte,Porte exterieure
4003,SPA,Puerta,Puerta exterior
4004,GER,Tur,Auberliche Tur
5001,ENG,Shutter,Outdoor shutter
5002,FRE,Volet,Volet exterieur
5003,SPA,Obturador,Obturador exterior
5004,GER,Fenster, Fensterladen
$
Table PRODUCT_DESCRIPTIONS:
8 Rows successfully loaded.
--------------------------------------------------------------
SQL*Loader-579: switching to direct path for the load
Table PRODUCT_DESCRIPTIONS:
8 Rows successfully loaded.
8 rows selected.
SQL> exit
$
2. As the OE user, load data into the INVENTORIES table by using SQL*Loader command
line. The lab_16_02_02.dat data file contains rows of data for the PRODUCT_ON_HAND
table. The lab_16_02_02.ctl file is the control file for this load.
Optionally, view the lab_16_02_02.dat and lab_16_02_02.ctl files to learn more
about their structure before going further.
a. Open a terminal window and navigate to the $LABS/P16 directory.
b. Ensure that your environment is configured for the orcl database by running oraenv.
$ . oraenv
ORACLE_SID = [orcl] ? orcl
The Oracle base for
ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1 is
/u01/app/oracle
$
c. Enter the following SQL*Loader command (in continuation, without pressing Enter
before reaching the end of the command.
$ sqlldr userid=oe/oracle_4U control=lab_16_02_02.ctl
log=lab_16_02_02.log data=lab_16_02_02.dat
Table OE.INVENTORIES:
0 Rows successfully loaded.
Table OE.INVENTORIES:
0 Rows successfully loaded.
51 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
Table OE.INVENTORIES:
83 Rows successfully loaded.
Table OE.INVENTORIES:
83 Rows successfully loaded.
0 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
83 rows selected.
SQL> EXIT
$
Commit complete.
83 rows deleted.
Commit complete.
set echo on
exit;
END
$ ./lab_17_01_01.sh
…
Connected to:
…
SQL> SQL> SQL> SQL> drop tablespace TBSSPC including contents
and datafiles
*
ERROR at line 1:
ORA-00959: tablespace 'TBSSPC' does not exist
SQL> SQL> 2 3 4 5 6
Tablespace created.
. $LABS/set_db.sh
set echo on
exit;
END
$
$ ./lab_17_01_02.sh
…
Connected to:
…
SQL> SQL> SQL> SQL> drop user spct cascade
*
ERROR at line 1:
ORA-01918: user 'SPCT' does not exist
SQL> SQL> 2 3
User created.
SQL> SQL>
Grant succeeded.
$
3. The test workload that is provided runs only a few minutes. In order to get meaningful data,
the time between Automatic Workload Repository (AWR) snapshots should be reduced.
Use the DBMS_ADVISOR package to set the database activity time to 30 minutes. The test
script, running as the SPCT user, drops and creates the SPCT table and gathers statistics
for this table. It also creates a snapshot in AWR. Execute the lab_17_01_03.sh script to
perform these tasks. In a terminal window, enter:
$ cat lab_17_01_03.sh
…
cd $LABS/P17
set echo on
exec
dbms_advisor.set_default_task_parameter('ADDM','DB_ACTIVITY_MIN'
,30);
connect spct/oracle_4U
exec DBMS_STATS.GATHER_TABLE_STATS(-
ownname=>'SPCT', tabname=>'SPCT',-
estimate_percent=>DBMS_STATS.AUTO_SAMPLE_SIZE);
exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT();
exit;
EOF
$ ./lab_17_01_03.sh
…
Connected to:
…
SQL> SQL> SQL> SQL>
PL/SQL procedure successfully completed.
SQL>
Table created.
SQL> SQL>
PL/SQL procedure successfully completed.
$
4. Run the workload script. This creates an activity to be analyzed. Execute the
lab_17_01_04.sh script to perform these tasks. DO NOT wait for the script to finish
continue to the next step.
$ ./lab_17_01_04.sh
5. Watch the activity in the Active Session Graph on the Cloud Control Performance Home
page until the script completes.
Step Window/Page Description Choices or Values
a. Cloud Control Login
User: ADMIN
Password: oracle_4U
b. Summary Navigate to the orcl database home page.
c. orcl database home Click Performance > Performance Home.
d. Database Login Credentials: Select Preferred.
Preferred Credential Name: SYSDBA
Database Credentials
Click Login.
e. Database Instance: orcl Verify that the refresh rate is set to Real Time:
15 Second Refresh
Watch the Average Active Session graph
until It has peaked and returned to the
previous low level.
This is your activity to be analyzed. By looking at the graph, you can determine that this
instance is suffering from concurrency problems.
SQL> SQL>
Tablespace dropped.
SQL> SQL>
Table created.
SQL> SQL>
PL/SQL procedure successfully completed.
$
9. Execute your workload again. (Use the lab_17_01_04.sh script.) DO NOT wait for the
script to complete continue to next task.
$ ./lab_17_01_04.sh
SQL> SQL>
Tablespace dropped.
SQL> SQL>
Tablespace dropped.
Table altered.
2. You get calls from HR application users saying that a particular query is taking longer than
normal to execute. The query is in the lab_18_01_02.sql script. To run this file, enter
the following in SQL*Plus:
SQL> CONNECT hr
Password: oracle_4U <<<Password does not appear on screen
Connected.
SQL> !cat lab_18_01_02.sql
-- Oracle Database 12c: Administration Workshop
-- Oracle Server Technologies - Curriculum Development
--
-- ***Training purposes only***
-- ***Not appropriate for production use***
--
SQL> @lab_18_01_02.sql
SQL>
3. Using Cloud Control, locate the HR session in which the above statement was just
executed, and view the execution plan for that statement.
Step Window/Page Description Choices or Values
a. Cloud Control Navigate to the orcl database target.
SQL>
b. You notice that the output lists six indexes, all on the EMPLOYEES table. This is a
problem you need to fix.
6. You decide to use Cloud Control to reorganize all the indexes in the HR schema that are
marked as UNUSABLE.
Step Window/Page Description Choices or Values
a. View Index: HR.EMP_EMP_ID_PK Select Reorganize in the Actions menu.
Click Go.
b. Reorganize Objects: Objects Click Add.
Repeat the tasks listed in step 3 to view the execution plan for the query. Now the icon
indicates the use of an index. Select the Tabular radio button. Note that the plan now uses
an index unique scan.
This script takes about 20 minutes to complete. So, run it in a separate terminal window
and continue with this practice exercise while it runs. Remember to set your environment
appropriately by using oraenv in the new terminal window before connecting to SQL*Plus.
Note: Because this script generates a fairly heavy load in terms of CPU and disk I/O, you
may notice that response time is slower.
$ sqlplus DBA1/oracle_4U@orcl as sysdba
SQL> @lab_18_01_09.sql
SID is 261
Question 1: In the Average Active Sessions graph, which are the two main categories
that active sessions are waiting for?
Answer: In this example, it looks like Configuration issues and User I/O are quite high.
CPU is also showing high wait activity. Your results may differ from what is shown here.
Note: The graph you see may vary from the screenshot.
Tasks
1. Log in to SQL*Plus for the orcl instance as the DBA1 user with the oracle_4U password
and make a copy of your server parameter file (SPFILE).
SQL>
2. Still connected as the DBA1 user in SQL*Plus, set the following parameters to the given
value in your SPFILE only! Use the amm_parameters.sql file located in your
$LABS/P18 directory to set the parameters.
parallel_execution_message_size = 36864
parallel_max_servers = 200
parallel_adaptive_multi_user = FALSE
processes = 200
sga_target = 0
pga_aggregate_target = 0
memory_target = 624M
SQL> @amm_parameters
System altered.
System altered.
System altered.
System altered.
System altered.
SQL>
SQL>
SQL> create tablespace tbssga datafile
'/u01/app/oracle/oradata/tbssga01.dbf' size 20m;
Tablespace created.
SQL>
SQL> create temporary tablespace mytemp tempfile
'/u01/app/oracle/oradata/myemp01.dbf' size 40m reuse;
SQL>
SQL> drop user amm cascade;
drop user amm cascade
*
ERROR at line 1:
ORA-01918: user 'AMM' does not exist
SQL>
SQL> create user amm
2 identified by "oracle_4U"
3 default tablespace tbssga
4 temporary tablespace mytemp;
User created.
SQL>
SQL> grant connect,resource,dba to amm;
Grant succeeded.
SQL>
8 rows selected.
8 rows selected.
SQL> pause Press [Enter] to continue...
Press [Enter] to continue...
SQL>
4. Log in as the AMM user with the oracle_4U password. Execute the amm_setup2.sql
script to re-create the TABSGA table and insert rows.
SQL> connect amm
Enter password: oracle_4U <<< not displayed
Connected.
SQL> @amm_setup2.sql
SQL>
…
SQL> drop table tabsga purge;
drop table tabsga purge
*
ERROR at line 1:
ORA-00942: table or view does not exist
Table created.
SQL>
SQL> begin
2 for i in 1..100000 loop
3 insert into tabsga values (i, i);
4 end loop;
SQL> commit;
Commit complete.
Table altered.
SQL>
SQL> create or replace procedure testpga( psize number ) as
2 begin
3 declare
4 TYPE nAllotment_tabtyp IS TABLE OF char(2048) INDEX BY
BINARY_INTEGER;
5 myarray nAllotment_tabtyp;
6 begin
7 for i in 1..psize loop
8 myarray(i) := to_char(i);
9 end loop;
Procedure created.
COMP CS US
-------------------- ---------- ----------
shared pool 150994944 0
large pool 88080384 0
java pool 4194304 0
streams pool 4194304 0
SGA Target 390070272 0
DEFAULT buffer cache 121634816 4194304
36 rows selected.
SQL> pause Press [Enter] to exit the script...
Press [Enter] to exit the script...
7. Remain connected as the AMM user in your SQL*Plus session and execute the following
query. Immediately after that, determine the component sizes and resized operations. You
can use the amm_query1.sql script for that purpose. What do you observe?
a. Execute the amm_query1.sql script. You can see that the large pool has a much
bigger size, whereas the buffer cache is smaller. This memory transfer was
automatically done by the system.
SQL> @amm_query1.sql
SQL> select /*+ PARALLEL(s 24) */ count(*) from (select /*+
parallel(s 24) */ a from tabsga s group by a);
SQL>
SQL> column COMP format a20
SQL>
SQL> select substr(COMPONENT, 0, 20) COMP, CURRENT_SIZE CS,
USER_SPECIFIED_SIZE US from v$memory_dynamic_components where
CURRENT_SIZE!=0;
COMP CS US
--------------------- ---------- ----------
8 rows selected.
SQL>
SQL> select substr(COMPONENT, 0, 20) COMP, FINAL_SIZE,
OPER_TYPE, OPER_MODE, status from v$memory_resize_ops order by
START_TIME;
72 rows selected.
SQL>
8. Repeat the query by using the amm_query2.sql script. What do you observe?
Possible Answer: The same trend continues.
SQL> @amm_query2.sql
SQL> select /*+ PARALLEL(s 25) */ count(*) from (select /*+
parallel(s 25) */ * from tabsga s group by a);
COUNT(*)
----------
100000
SQL>
SQL> column COMP format a12
SQL>
SQL> select substr(COMPONENT, 0, 10) COMP, CURRENT_SIZE CS,
USER_SPECIFIED_SIZE US from v$memory_dynamic_components where
CURRENT_SIZE!=0;
COMP CS US
-------------------- ---------- ----------
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
8 rows selected.
SQL>
SQL> select substr(COMPONENT, 0, 10) COMP, FINAL_SIZE,
9. Still connected as the AMM user in your SQL*Plus session, execute the amm_query3.sql
script. Immediately afterward, determine the memory component sizes and the list of resize
operations. What do you observe?
Possible Answer: The same action of growing and shrinking the memory components
Alternative Answer: The memory grows and shrinks until the memory allocation meets the
needs of the database activity, and then remains nearly constant.
SQL> @amm_query3.sql
SQL> exec testpga(500000);
SQL>
SQL> column COMP format a12
SQL>
SQL> select substr(COMPONENT, 0, 10) COMP, CURRENT_SIZE CS,
USER_SPECIFIED_SIZE US from v$memory_dynamic_components where
CURRENT_SIZE!=0;
COMP CS US
-------------------- ---------- ----------
shared pool 159383552 0
large pool 4194304 0
java pool 4194304 0
streams pool 4194304 0
SGA Target 377487360 0
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
10. In Enterprise Manager Cloud Control, look at the memory variations that happened during
this practice. What do you observe?
Step Window/Page Description Choices or Values
a. Cloud Control Log in to Enterprise Manager Cloud Control
and navigate to the orcl Database home
page.
b. orcl Database home Click Performance > Advisors Home >
Memory Advisors.
c. Memory Advisors Scroll down and examine the two graphs.
SQL>
Tablespace dropped.
SQL>
Tablespace dropped.
SQL>
Database altered.
SQL> Disconnected …
Tasks
In your database there are several running applications. You want to monitor the resources that
are being used by each application. Create a service configuration for each application or
application function that uses your database.
In this practice, you create the following configuration in the orcl database:
Service Name Usage Response Time (sec)–
Warning/Critical
SERV1 Client service 0.4, 1.0
SQL> EXEC
DBMS_SERVICE.CREATE_SERVICE('SERV1','SERV1.example.com')
SQL> exit
2. After you have created your service, try connecting to your database by using your service
name.
$ sqlplus system@serv1
NAME NETWORK_NAME
-------------------- ------------------------------
SYS$BACKGROUND
SYS$USERS
SERV1 SERV1.example.com
orclXDB orclXDB
orcl orcl
(ADDRESS=(PROTOCOL=tcp)(HOST=edp1.us.oracle.com)(PORT=13016))
Service "orcl" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this
service...
Handler(s):
"DEDICATED" established:34 refused:0 state:ready
LOCAL SERVER
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this
service...
Handler(s):
"D000" established:0 refused:0 current:0 max:1022
state:ready
DISPATCHER <machine: EDP1, pid: 10116>
(ADDRESS=(PROTOCOL=tcp)(HOST=edp1.us.oracle.com)(PORT=39588))
The command completed successfully
SQL>
Note: The SERV1 service is NOT listed in the listener services, but it is listed in the
DBA_SERVICES view. The orcl and orclXDB services are registered with the listener
because the orcl service is included in the SERVICE_NAMES initialization parameter.
Question: How would you make sure that you can connect by using your service?
Answer: You must start your service on your instance.
Connecting to
(DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
Services Summary...
Service "SERV1.example.com" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this
service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
Service "em12rep" has 1 instance(s).
Instance "em12rep", status READY, has 1 handler(s) for this
service...
Handler(s):
"DEDICATED" established:713 refused:0 state:ready
LOCAL SERVER
Service "em12repXDB" has 1 instance(s).
Instance "em12rep", status READY, has 1 handler(s) for this
service...
Handler(s):
"D000" established:0 refused:0 current:0 max:1022
state:ready
DISPATCHER <machine: EDP1, pid: 18745>
(ADDRESS=(PROTOCOL=tcp)(HOST=edp1.us.oracle.com)(PORT=13016))
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Connected.
SQL> exit
4. Create a workload for the SERV1 service. You will create a user for this activity and start a
workload.
a. Execute the sv1_load.sh script as SYSDBA. This script creates a new SV_USER
user.
$ cd $LABS/P18
$ ./sv1_load.sh
SQL> SQL> 2 3
User created.
SQL> SQL>
Grant succeeded.
$
5. After the execution starts, access the Top Consumers page from the Performance tabbed
page in Cloud Control, and determine the amount of resources SERV1 is using. Also, check
the statistics on your service with V$SERVICE_STATS from a SQL*Plus session, connected
as SYSDBA.
Step Window/Page Description Choices or Values
a. Cloud Control Log in to Enterprise Manager Cloud Control
and navigate to the orcl Database home
page.
b. orcl Database In the Performance section, view the Services
tab.
SQL> exit
7. Clean up from this practice by running the sv1_cleanup.sh script in the $LABS/P18
directory.
$ cd $LABS/P18
$ ./sv1_cleanup.sh
Assumptions
ADMIN Super Administrator user has been created in Enterprise Manager Cloud Control.
DBA1 user with SYSDBA privileges has been created in orcl database.
Tasks
1. In Cloud Control, Configure the Automatic SQL Tuning Task to Implement SQL Profiles
Automatically.
#!/bin/bash
# For training only - execute as oracle OS user
--
-- Drop any profiles on AST queries
--
declare
cursor prof_names is
select name from dba_sql_profiles where sql_text like
'%AST%';
begin
for prof_rec in prof_names loop
dbms_sqltune.drop_sql_profile(prof_rec.name);
end loop;
end;
/
EOF!
$
$ ./ast_setup.sh
SQL>
User created.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
SQL> SQL>
System altered.
SQL> SQL>
$
3. Execute the ast_workload_stream.sh script. This script executes a query that is not
correctly optimized multiple times. The query in question uses hints that force the optimizer
to pick a suboptimal execution plan. The script executes for approximately 60 seconds.
$ ./ast_workload_stream.sh
exec dbms_workload_repository.create_snapshot;
--
-- Open the corresponding maintenance window, but with other
clients disabled
--
alter system set "_enable_automatic_maintenance"=1 SCOPE=MEMORY
exec dbms_auto_task_admin.disable( -
'auto space advisor', null, :window);
--
-- Close the maintenance window when sqltune is done
--
exec dbms_lock.sleep(60);
declare
running number;
begin
loop
select count(*)
into running
from dba_advisor_executions
where task_name = 'SYS_AUTO_SQL_TUNING_TASK' and
status = 'EXECUTING';
if (running = 0) then
exit;
end if;
dbms_lock.sleep(60);
end loop;
dbms_scheduler.close_window(:window);
end;
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
-- Re-enable the other guys so they look like they are enabled
in EM.
-- Still they will be disabled because we have set the
underscore.
--
exec dbms_auto_task_admin.enable( -
'auto optimizer stats collection', null, :window);
EOF!
date
$ ./ast_run.sh
Mon Oct 20 09:08:24 UTC 2014
…
Connected to:
…
SQL>
WINDOW
-------------------------------------------------------------
MONDAY_WINDOW
SQL> >
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
SQL> SQL>
PL/SQL procedure successfully completed.
SQL> SQL> 2 3 4 5 6 7 8 9 10 11 12
SQL> 2
System altered.
SQL> SQL>
Mon Oct 20 09:14:30 UTC 2014
$
Some of your output, such as the WINDOW, may look different.
5. Execute the ast_workload_stream.sh script again. What do you observe?
You should see that the execution time for ast_workload_stream.sh is much faster
than the original execution. This is probably due to the fact that Automatic SQL Tuning
implemented a profile for your statement automatically.
$ ./ast_workload_stream.sh
Mon Oct 20 10:10:16 UTC 2014
Mon Oct 20 10:10:36 UTC 2014
$
6. Log in as the AST user and force the creation of an AWR snapshot.
$ sqlplus ast
Enter password: oracle_4U <<< not displayed
SQL> exec dbms_workload_repository.create_snapshot;
PL/SQL procedure successfully completed.
d. Look at the graphs on the Automatic SQL Tuning Result Summary page. (If you do not
see any graphs, return to step 5, execute the work load twice, and then continue with
step 6 and 7.)
e. Focus on understanding the pie chart and the bar graph next to it. You should be able
to get a sense of the general findings, as well as the number of SQL profiles
implemented by the task.
f. In the Summary Time Period section, Click View Report to see a detailed SQL-level
report.
q. Click the Statistics tab to take a look at the execution history for this SQL.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
t. Which of the two executed first? Which one executed more quickly?
The hash value 4005616876 in the example executed first, and the second hash value
executed more quickly.
u. Select All in the Plan Hash Values. This shows the improved plan and the original in
the same graph. The bar graph for the second run with the SQL Profile applied may be
so small as to be almost invisible.
8. Generate a text report for more in-depth information. From the command line, execute the
ast_task_report.sh script. What do you observe?
a. Notice the first queries that fetch the execution name and object number from the
advisor schema, followed by the final query that gets the text report. In the text report,
look for the section about the SQL profile finding and peruse the Validation Results
section. This shows you the execution statistics observed during test-execute and
allows you to get a better sense of the profile’s quality. You can also use the
report_auto_tuning_task API to get reports that span multiple executions of the
task.
$ cat ast_task_report.sh
#!/bin/bash
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
--
-- Check the execution names
--
alter session set nls_date_format = 'MM/DD/YYYY HH24:MI:SS';
begin
select max(execution_name) keep (dense_rank last order by
execution_start)
into :last_exec
from dba_advisor_executions
where task_name = 'SYS_AUTO_SQL_TUNING_TASK';
end;
/
print :last_exec
--
-- Find the object ID for query AST with sql_id by9m5m597zh19
--
variable obj_id number;
begin
select object_id
into :obj_id
from dba_advisor_objects
where task_name = 'SYS_AUTO_SQL_TUNING_TASK' and
execution_name = :last_exec and
type = 'SQL' and
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
print :obj_id
--
-- Get a text report to drill down on this one query
--
set pagesize 0
select dbms_sqltune.report_auto_tuning_task(
:last_exec, :last_exec, 'TEXT', 'TYPICAL', 'ALL', :obj_id)
EOF!
$ ./ast_task_report.sh
SQL*Plus: Release 12.1.0.2.0 Production on Mon Oct 20 10:34:13
2014
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 -
64bit Production
With the Partitioning, OLAP, Advanced Analytics, Real
Application Testing
and Unified Auditing options
SQL> SQL> 2 3 4
EXECUTION_NAME
----------------------------------------------------------------
----------------
STATUS EXECUTION_START
----------- -------------------
EXEC_708
COMPLETED 10/20/2014 09:08:32
SQL> SQL>
LAST_EXEC
----------------------------------------------------------------
----------------
EXEC_708
SQL> SQL>
OBJ_ID
----------
4
----------------------------------------------------------------
---------------
Object ID : 4
Schema Name: AST
SQL ID : by9m5m597zh19
SQL Text : select /*+ USE_NL(s c) FULL(s) FULL(c) AST */
c.cust_id,
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
----------------------------------------------------------------
---------------
FINDINGS SECTION (1 finding)
----------------------------------------------------------------
---------------
Validation results
------------------
The SQL profile was tested by executing both its plan and the
original plan
and measuring their respective execution statistics. A plan
may have been
only partially executed if the other could be run to
completion in less time.
Notes
-----
1. Statistics for the original plan were averaged over 3
executions.
2. Statistics for the SQL profile plan were averaged over 10
executions.
----------------------------------------------------------------
----------------
-------------------
| Id | Operation | Name | Rows | Bytes | Cost
(%CPU)| Time
| Pstart| Pstop |
----------------------------------------------------------------
----------------
-------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 939
(1)| 00:00:0
1 | | |
| 1 | HASH GROUP BY | | 1 | 13 | 939
(1)| 00:00:0
1 | | |
| 2 | NESTED LOOPS | | 1 | 13 | 938
(1)| 00:00:0
1 | | |
|* 3 | TABLE ACCESS FULL | CUSTOMERS | 1 | 5 | 423
(1)| 00:00:0
1 | | |
----------------------------------------------------------------
----------------
-----------------------------------------------
| Id | Operation | Name |
Rows |
Bytes | Cost (%CPU)| Time | Pstart| Pstop |
----------------------------------------------------------------
----------------
-----------------------------------------------
| 0 | SELECT STATEMENT | |
1 |
13 | 56 (2)| 00:00:01 | | |
| 1 | HASH GROUP BY |
| 1 |
13 | 56 (2)| 00:00:01 | | |
| 2 | NESTED LOOPS |
| 1 |
13 | 55 (0)| 00:00:01 | | |
| 3 | PARTITION RANGE ALL |
| 1 |
8 | 55 (0)| 00:00:01 | 1 | 28 |
| 4 | TABLE ACCESS BY LOCAL INDEX ROWID BATCHED| SALES
| 1 |
8 | 55 (0)| 00:00:01 | 1 | 28 |
6 - access("S"."CUST_ID"<2)
filter("S"."CUST_ID"<2)
7 - access("S"."CUST_ID"="C"."CUST_ID")
filter("C"."CUST_ID"<2)
----------------------------------------------------------------
---------------
d. Click the Configure button. On the Automated Maintenance Tasks Configuration page,
you can disable individual clients and change which windows they run in.
e. Disable the Automatic SQL Tuning client entirely and click Show SQL.
l. Optionally, click Show SQL, review the commands and then click Return.
m. Click Apply to enable Automatic SQL Tuning. You should receive a success message.
n. Navigate to the Automatic SQL Tuning Settings page. If you are on the Automated
Maintenance Tasks Configuration page, click the Configure button for Automatic SQL
Tuning.
o. On the Automatic SQL Tuning Settings page, select No beside the “Automatic
Implementation of SQL Profiles” field, and click Show SQL.
Assumptions
Users SH, OE, and PM are unlocked and the password for each is set to oracle_4U.
Task
In this practice, you create an APPUSER consumer group and assign it to the default
DEFAULT_PLAN resource plan. Then you map a few Oracle users and your major OS user to
3. There are two ways to assign users to consumer groups: The user can be assigned to one
or more groups explicitly and an initial group defined, or the user can be mapped into an
initial group based on one or more of the rules in the Consumer Group Mappings. Configure
Consumer Group Mappings so that the HR Oracle user belongs to the APPUSER consumer
group and the SCOTT user to the LOW_GROUP consumer group. For the SCOTT user,
SQL>
c. Execute the $LABS/P20/assign_scott_lowgroup.sql script to assign the SCOTT
user to the LOW_GROUP consumer group.
SQL>
4. Return to Enterprise Manager Cloud Control to verify the additions you made in step 3.
a. Click Administration > Resource Manager.
b. Click Consumer Group Mappings.
c. HR and SCOTT now appear in the list.
7. Test the consumer group mappings. Start two SQL*Plus sessions: the first with the
system/oracle_4U@orcl connect string and the second with the scott/tiger@orcl
connect string.
Connected.
SECOND>
g. In your FIRST SQL*Plus session, enter “/” to execute the previous SQL statement
again.
FIRST>/
FIRST>
Question: To which consumer group does the PM user belong?Answer: PM is in the
APPUSER consumer group.
h. In the SECOND terminal window, connect as the OE user with the oracle_4U
password:
SECOND> connect oe@orcl
Enter password: oracle_4U <<< not displayed
Connected.
SECOND>
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
FIRST> exit
f. To reconfigure or undo all consumer group mappings, review and execute the
rsc_cleanup.sh script from the $LABS/P20 directory:
$ cd $LABS/P20
$ cat rsc_cleanup.sh
#!/bin/bash
# Oracle Database 12c: Administration Workshop
# Oracle Server Technologies - Curriculum Development
#
# ***Training purposes only***
# ***Not appropriate for production use***
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
BEGIN
dbms_resource_manager_privs.revoke_switch_consumer_group(
revokee_name => 'PM',
BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.set_consumer_group_mapping(
dbms_resource_manager.oracle_user,
'HR',
NULL
);
dbms_resource_manager.set_consumer_group_mapping(
BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.delete_consumer_group('APPUSER');
dbms_resource_manager.delete_consumer_group('LOW_GROUP');
dbms_resource_manager.submit_pending_area();
END;
exit
EOF
$ ./rsc_cleanup.sh
$
g. Log out of Enterprise Manager Cloud Control.
Task
In this practice, you use Enterprise Manager Cloud Control to create Scheduler objects in the
ORCL database instance and automate tasks.
1. Create a simple job that runs a SQL script by using Enterprise Manager Cloud Control.
a. Log in to Enterprise Manager Cloud Control and navigate to the orcl database home
page.
b. Expand Administration. Select Oracle Scheduler > Jobs.
Grant succeeded.
SQL> EXIT
SQL>
b. In your SQL*Plus session, enter:
SQL> BEGIN
DBMS_SCHEDULER.CREATE_SCHEDULE (
schedule_name => 'SESS_UPDATE_SCHED',
start_date => SYSTIMESTAMP,
repeat_interval => 'FREQ=SECONDLY;INTERVAL=3',
SQL>
c. In Enterprise Manager Cloud Control, navigate to Administration > Oracle Scheduler
> Schedules.
d. Verify that the SESS_UPDATE_SCHED schedule has been created. (You may have to
refresh the page for the Schedule to appear.)
SNAP_TIME
--------------------------------------------------------------
NUM_SESSIONS
------------
...
21-OCT-14 01.27.04.790310 PM
58
21-OCT-14 01.27.08.887697 PM
58
21-OCT-14 01.27.12.986016 PM
58
SNAP_TIME
----------------------------------------------------------------
NUM_SESSIONS
------------
21-OCT-14 01.27.17.093735 PM
58
SNAP_TIME
--------------------------------------------------------------
NUM_SESSIONS
------------
...
21-OCT-14 01.32.43.076946 PM
58
21-OCT-14 01.32.47.180994 PM
58
21-OCT-14 01.35.50.726790 PM
57
SNAP_TIME
----------------------------------------------------------------
NUM_SESSIONS
------------
21-OCT-14 01.38.50.751317 PM
57
k. In your SQL*Plus session, as the HR user, delete the SESSION_HISTORY table, and
then exit the session. Enter:
SQL> DROP TABLE session_history PURGE;
SQL> EXIT
$
Task
In this optional practice, you create and run a lightweight scheduler job. View the metadata for a
lightweight scheduler job. Navigate to your $LABS/P21 directory.
1. Create a job template for the lightweight job. The template must be a PL/SQL procedure or
a PL/SQL block. Run the cr_test_log.sql script to create the TEST_LOG table. Then
run prog_1.sql. The prog_1.sql script in the $LABS/P21 directory creates a job
template.
Note: The job template has a subset of the attributes of a scheduler program. Most of the
SQL> @cr_test_log.sql
SQL> -- cleanup previous runs
SQL> -- you will see an error the first time this script is run
SQL> drop table system.test_log;
drop table system.test_log
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
SQL> -- create a table to hold timing information
SQL>
SQL> create table system.test_log
2 (job_type VARCHAR2(10),
3 timemark VARCHAR2(10),
4 act_time TIMESTAMP with TIME ZONE)
5 /
Table created.
SQL> BEGIN
2 DBMS_SCHEDULER.CREATE_PROGRAM(
3 program_name=>'"SYSTEM"."PROG_1"'
4 ,program_action=>'DECLARE
5 time_now DATE;
6 BEGIN
7 INSERT INTO test_log
VALUES(''LWT'',''DONE'',SYSTIMESTAMP);
8 END;'
9 , program_type=>'PLSQL_BLOCK'
10 , number_of_arguments=>0,
11 comments=>'Insert a timestamp into the test_log'
12 ,enabled=>TRUE);
13 END;
14 /
SQL>
2. Create a lightweight job by using the PL/SQL API. The job will run the my_prog template
daily with an interval of 2, starting immediately.
SQL>
SQL> DECLARE
2 jobname VARCHAR2(30);
3 BEGIN
4 -- Create the Job
5 jobname := 'my_lwt_job';
6 sys.dbms_scheduler.create_job(
7 job_name => '"SYSTEM"."MY_LWT_JOB"',
8 program_name => '"SYSTEM"."PROG_1"',
9 job_class => '"DEFAULT_JOB_CLASS"',
10 job_style => 'LIGHTWEIGHT',
11 repeat_interval => 'FREQ=DAILY;INTERVAL=2',
12 comments => 'Lightweight job',
13 enabled => TRUE);
14 END;
15 /
SQL>
SQL>
4. Access the Enterprise Manager Cloud Control Scheduler Jobs page, find the MY_LWT_JOB
b. View the history of MY_LWT_JOB. Click the Job Name to view the job attributes.
b. On the Confirmation page, select “Drop the job and stop any running instance.”
Click Yes.
Tasks
In this practice, use Enterprise Manager Cloud Control to view Scheduler components. Click
Show SQL regularly to review all statements that are new to you.
Log in as the DBA1 user (with oracle_4U password, connect as SYSDBA). Perform the
necessary tasks either through Enterprise Manager Cloud Control or through SQL*Plus. All
scripts for this practice are in the $LABS/P21 directory.
1. Log in to the orcl database target as the DBA1 user with the oracle_4U password.
2. To view the Scheduler jobs, navigate to Administration > Oracle Scheduler > Jobs. Are
Question 1: Which resource consumer group is associated with the job class?
Answer: ORA$AT_JCURG_OS is associated with ORA$AUTOTASK.