+ All Categories
Home > Documents > Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting...

Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting...

Date post: 17-Apr-2020
Category:
Upload: others
View: 9 times
Download: 0 times
Share this document with a friend
45
Tools for Oracle Databases Database Tutorials 2017 Andrei Dumitru / IT-DB
Transcript
Page 1: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Tools for Oracle Databases

Database Tutorials 2017

Andrei Dumitru / IT-DB

Page 2: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Oracle Account Management

Oracle SQL*Plus

Benthic Golden

Oracle SQL Developer

CERN Session Manager

Oracle Enterprise Manager

CERN Data Pump Tool

CERN DB Link Viewer

Oracle Tools on EOS

2

Page 3: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Oracle Accounts Management

Oracle database accounts are computing resources

Similar to your project account

Managed like other computing resources at CERN• https://resources.web.cern.ch/resources/Manage/Oracle/Default.aspx

Details in SNOW KB0000829: Account Management

for Oracle accounts• https://cern.service-now.com/service-portal/article.do?n=KB0000829

3

Page 4: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Oracle Accounts Naming Convention

Account for a project

• <projectname>_XXXXXX

• myproject_admin, myproject_user

Personal account

• do not use '_' (underscore) in the login name

• same name as your CERN account

4

Page 5: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Oracle Account Lifecycle

Request to be part of the e-group for that database

• for devdb11 – oracle-general-purpose-users

Wait for the approval to join the e-group (next day)

Once approved, request account on the desired database

A DBA will approve the request

You receive an email informing you the account is ready

Change the password

Ready to go

5

Page 6: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Demo

Request a new Oracle account

• https://resources.web.cern.ch

Account related actions

• Temporarily unlock

• Increase the quota

• Manage DADs (Database Access Descriptors)

• Change password, owner, description

• Delete6

Page 7: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

SQL*Plus

command line SQL and PL/SQL language interface

reporting tool

bundled with the Oracle Database Client and Server software

can be used interactively or from scripts

sqlplus is equivalent to:

• "sqlcmd" in Microsoft SQL Server

• "psql" in PostgreSQL

• "mysql" in MySQL

7

Page 8: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

When to use SQL*Plus?

When troubleshooting database connection

problems

• compatible with database, native tool

• „lightweight” - lower probability of additional software errors

• easy to use: need to know basic SQL commands

In shell scripts

Change expired password

sqlplus -S /nolog <<EOF > /tmp/list_of_employees.lst

connect myuser/$MY_PASSWD@db_service

set head off

set feedback off

select unique name from employees order by 1;

exit

EOF

8

Page 9: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

substitution variables (&)

external scripts (RUN or @)

SQL*Plus example features

SQL> insert into my_table(col1,col2) values (’&name’,&age);

Enter value for name: myname

Enter value for age:

repeating commands with changing input

values; very powerful feature in

conjunction with rlwrap (see following

slide)

SQL> run /users/scripts/myscript.sql

SQL> @/users/scripts/myscript

the command „run” or its alias: „@” enables

execution of SQL scripts stored on file system

9

Page 10: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

rlwrap - 'readline wrapper‘

Nice extension of SQL*Plus (on UNIX/Linux systems)

rlwrap runs the specified command, intercepting user input in order to

provide readline line editing, persistent history and completion

Ctrl-R

• search in command history

Usage:

• rlwrap sqlplus $@

10

Page 11: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Benthic Golden

Query and scripting tool for Oracle databases

Easy to use, lightweight

Free for CERN usage

Limitations

• Windows only

• Oracle Instant Client 32-bit required

• CERN license for version 5 only

11

Page 12: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Feature example

• Output formatting

12

Page 13: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Installation and configuration

Download directly from Benthic• http://www.benthicsoftware.com/downloads.html

Follow installation instructions

Use CERN license keys (on DFS)• \\cern.ch\dfs\Applications\Benthic\Benthic_keys_CERN.html

Version 5

13

Page 14: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Oracle SQL Developer

Free Oracle Database IDE/GUI

Works on Windows, MacOS, Linux (Java based)

Features

• manage and browse database objects

• execute, edit and debug SQL, PL/SQL statements and scripts

• Database design and data modelling

• ad hoc reporting

• third-party plugins to connect to non-Oracle databases

Download from Oracle website• http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html

14

Page 15: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

SQL Query Tuning

Design efficient

applications by anticipating

a query execution plan

(explain plan) – Explain Plan F10

Verify the real execution plan

running a query and

analysing the real execution

path – Autotrace F6

Explain

plan

Autotrace

15

Page 16: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

SQL Query Tuning

• Use the drop down

arrow next to the

Explain Plan button to

access cached plans

from v$sql_plan

16

Page 17: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

SQL Tuning Advisor

17

Use tuning advisor

to know

suggestions about

potential

improvements of

your queries

SQL Tuning

Advisor

Page 18: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Quickly format output

set sqlformat json

select * from customers;

set sqlformat csv

select * from customers;

-- back to normal

set sqlformat

select * from customers;

18

Page 19: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

SQL DeveloperNew DB

connection• Connection creation

19

Page 20: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

And much more…

• Develop

• Administer

• Model

• Migrate

20

Page 21: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

SQL DeveloperAdvantages

• Big development environment

• No need to install, simple unzip downloaded package and software is ready to use (JDK required)

• Portable – copy unzipped files on flash drive and you can use it on any PC

• You can connect in parallel to several different databases

WARNING: Easy to work by mistake on production instead of test/development database

Disadvantages

• Heavy: can take some time to start

• Needs JDK (JRE not enough)

21

Page 22: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Session Manager

• CERN in-house development

• Main features:• WEB application

• Browse database connections

• Check sessions & SQL details

• Terminate (kill) sessions

Session Manager works on existing database connections

http://session-manager.web.cern.ch/

22

Page 23: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Login

• Integrated with CERN SSO

• Database login:

- credentials of a database

account

23

Page 24: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

SM – database credentials used„My Sessions” shows an report with some details about sessions connected to database user, whose credentials were used to log in

• (below: logged in to TEST database as SM_PRESENT, so SM_PRESENT’s sessions are displayed)

Logged as

SM_PRESENT@TEST

SM_PRESENT’s

sessions

24

Page 25: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

SM – database credentials used (cont.)

„All Sessions” = „My Sessions” + sessions to which I have privileges

Logged as

SM_PRESENT@TEST

Search your session

25

Page 26: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

SM – terminate session

Mark session…

…and just do it!

26

Page 27: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Session details

Execution planExecution plan

SQL details

27

Page 28: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

SQL details

Go to SQL details

28

Page 29: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

E-groups in SM

Check your

privileges

29

Page 30: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

E-groups in SM

30

Page 31: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

E-group definitionCreate your e-group

• Follow the naming convention: session-manager-<your distinct string>

session-manager-our-application-developers

session-manager-our-application-admins

Contact IT-DB (SNOW ticket) to request new e-group registration

• Provide list of pairs (in CSV format): database name, db account name

test,qa_test_user

test,super_dev_user

devdb11,project_account

Manage the list of your e-group members

• Remember about security implications!

31

Page 32: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Oracle Enterprise Manager

Available at oem.cern.ch

Deep look at the database performance

• Performance Home

• Top Activity

• ASH Analytics

• SQL Monitoring

32

Page 33: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

OEM – Top Activity

33

Page 34: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

OEM – Active Session History Load Map

34

Page 35: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

OEM – SQL Monitoring

35

Page 36: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

How to access oem.cern.ch ?

Authentication and authorization based on e-groups

• create an e-group for database developers

• contact IT-DB

No OEM access for “shared” databases

• like general development databases – devdb11

36

Page 37: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

CERN Data Pump ToolAutomatic solution for copying content of a database schema from one database system to another

• available to CERN Oracle database users

• implemented as an PL/SQL package

• data filtering (include/exclude schema objects)

• some limitations

Detailed description• https://twiki.cern.ch/twiki/bin/view/DB/CERNDB_DPUSER

SNOW KB0001169 How can I copy the content of an Oracle schema on one database to another schema on a different database?

• https://cern.service-now.com/service-portal/article.do?n=KB0001169

37

Page 38: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

CERN Data Pump Tool - Limitations

Tables with LONG data type are not supported (skipped)!

• each skipped table is signalled in the log by an ORA-31679 error

Only one schema per call can be copied

Schema with the same name has to exists on target database (no name remapping is possible).

If destination schema not empty, the previous content will be removed

38

Page 39: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

CERN DB Link ViewerCan be accessed at cern.ch/dblink-viewer

Application that enables you to inspect database links

Color CodeRed Line - TNS alias is invalid or account is missing on target databaseBlue Line - Target database account is locked or has expired passwordBlack Line - Link could not be checked: target database not accessibleGrey Line - Link status has not been updated for three or more daysGreen Line - Everything good

Background ColorRed background - Link might be using an outdated passwordOrange background - Host descriptor is not a TNS aliasBlue background - Link points to the same database

39

Page 40: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

CERN DB Link Viewer

40

Page 41: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

tnsnames.ora on EOS

Page 42: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Current Installations

• Oracle full database clients available in AFS now• /afs/cern.ch/project/oracle

• TNS Names

• /afs/cern.ch/project/oracle/admin/tnsnames.ora

• Several releases available - linux64 / linux32

• Different from standard Oracle Instant Client

• full contains all the client tools: tnsping, expdp, impdp,

sqlldr

Details in SNOW KB0001167: Oracle deployment from the AFS tree at CERN

42

Page 43: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

On EOS now

• Same approach but only Linux 64bits available• /eos/project/o/oracle/public

• TNS Names• /eos/project/o/oracle/public/admin/tnsnames.ora

• Copy of SQL*Developer up to date available for

clients to pick it up

• Can be used as of today

Details about tnsnames.ora in SNOW KB0001211: Oracle database connect string definitions (tnsnames file)

43

Page 44: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Quick test#on lxplus - for sh like shells (bash,sh,zsh)

export ORACLE_CERN=/eos/project/o/oracle/public

. $ORACLE_CERN/script/profile_oracle.sh

#on lxplus - for csh like (csh, tcsh)

setenv ORACLE_CERN /eos/project/o/oracle/public

source $ORACLE_CERN/script/cshrc_oracle.csh

tnsping devdb12

tnsping devdb12

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 20-NOV-2017 04:01:17

Copyright (c) 1997, 2013, Oracle. All rights reserved.

Used parameter files:

/eos/project/o/oracle/public/admin/sqlnet.ora

Used TNSNAMES adapter to resolve the alias

Attempting to contact

OK (0 msec)

44

Page 45: Database Tutorials 2017 Tools for Oracle Databases · When to use SQL*Plus? When troubleshooting database connection problems • compatible with database, native tool • „lightweight”

Recommended