Useful shortcuts for vi editor

Showing posts with label 12c. Show all posts
Showing posts with label 12c. Show all posts

Thursday, 10 November 2016

How to get AWR report as html file?

Generate Snapshots
SQL> EXEC DBMS_WORKLOAD_REPOSITORY.create_snapshot;
-> Run this SQL as twice (at the begin and at the end)

Get Automatic Workload Repository (AWR) as HTML format
Login -> Targets -> Databases -> Click Database -> Performance -> AWR -> AWR Report -> Select By Snapshot -> Click Generate Report -> Click Save to File -> Done :)

How to add target manually in 12c EM ?

Prepare the 12c EM server
# vi /etc/hosts
10.10.10.10 alperdb.com
-> remote machine (agent) IP and hostname

Prepare the environment (at new host)

# useradd grid12 -g dba
# vi /etc/hosts
10.10.10.2 grid12.com 
-> Current grid12 server machine IP and hostname

# vi /etc/sudoers
grid12 ALL=NOPASSWD: ALL
grid12 ALL=(ALL) ALL

# vi /etc/oraInst.loc
inventory_loc=/home/grid12/oraInventory
inst_group=dba

# passwd grid12
-> password: grid12

# sudo su - grid12
$ mkdir /home/grid12/oraInventory

Adding Host

Login -> Setup from top-right corner -> Add Target -> Add Target Manually -> Add Host -> Installation Base Directory: /home/grid12/agent -> Instance Directory field will be filled automatically -> 

Configure Agent

Login -> Setup from top-right corner -> Add Target -> Add Target Manually -> Select Add Targets Declaratively by Specifying Target Monitoring Properties -> Target Type: Database Instance, Monitoring Agent: 10.10.10.10:3872 -> Target Name: ALPERDB, Database System: ALPERDB, Oracle Home Path: echo $ORACLE_HOME, Port: 1521 -> Click Test Connection -> Submit -> Done! :)

Saturday, 11 October 2014

How to select top 10 records in Oracle 11g and 12c?

In 11g:

As you now that TOP keyword does not exist in 11g, but you can use rownum keyword to query top records.

For example, you want to see top 10 salary records based on employees:

Run that SQL in your editor's SQL window.

Wrong one;
SELECT *
FROM (
 SELECT employee_id, first_name, last_name, salary
 FROM employees
 )
WHERE rownum < 11
ORDER BY salary DESC;

* ORDER BY runs at last so that it should be in sub query.

Correct one;
SELECT *
FROM (
 SELECT employee_id, first_name, last_name, salary
 FROM employees
 ORDER BY salary DESC
 )
WHERE rownum < 11;


In 12c:
With 12c, you may use special syntax to see top records that is "FETCH" syntax.

SELECT employee_id, first_name, last_name, salary
FROM employees
ORDER BY salary DESC
FETCH FIRST 10 ROWS ONLY;

Also, you may disregard first 5 records inside 10 records.

SELECT employee_id, first_name, last_name, salary

FROM employees
ORDER BY salary DESC
OFFSET 5 ROWS 
FETCH NEXT 5 ROWS ONLY;

That's all. Bye :)