database tutorials 2017 tools for oracle databases · when to use sql*plus? when troubleshooting...
TRANSCRIPT
Tools for Oracle Databases
Database Tutorials 2017
Andrei Dumitru / IT-DB
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
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
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
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
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
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
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
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
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
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
Feature example
• Output formatting
12
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
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
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
SQL Query Tuning
• Use the drop down
arrow next to the
Explain Plan button to
access cached plans
from v$sql_plan
16
SQL Tuning Advisor
17
Use tuning advisor
to know
suggestions about
potential
improvements of
your queries
SQL Tuning
Advisor
Quickly format output
set sqlformat json
select * from customers;
set sqlformat csv
select * from customers;
-- back to normal
set sqlformat
select * from customers;
18
SQL DeveloperNew DB
connection• Connection creation
19
And much more…
• Develop
• Administer
• Model
• Migrate
20
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
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
Login
• Integrated with CERN SSO
• Database login:
- credentials of a database
account
23
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
SM – database credentials used (cont.)
„All Sessions” = „My Sessions” + sessions to which I have privileges
Logged as
SM_PRESENT@TEST
Search your session
25
SM – terminate session
Mark session…
…and just do it!
26
Session details
Execution planExecution plan
SQL details
27
SQL details
Go to SQL details
28
E-groups in SM
Check your
privileges
29
E-groups in SM
30
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
Oracle Enterprise Manager
Available at oem.cern.ch
Deep look at the database performance
• Performance Home
• Top Activity
• ASH Analytics
• SQL Monitoring
32
OEM – Top Activity
33
OEM – Active Session History Load Map
34
OEM – SQL Monitoring
35
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
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
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
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
CERN DB Link Viewer
40
tnsnames.ora on EOS
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
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
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