Database Tutorials 2017 Tools for Oracle Databases 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 Delete 6
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
SQL*Plus example features substitution variables (&) SQL> insert into my_table(col1,col2) values ( &name,&age); Enter value for name: myname Enter value for age: external scripts (RUN or @) SQL> run /users/scripts/myscript.sql SQL> @/users/scripts/myscript repeating commands with changing input values; very powerful feature in conjunction with rlwrap (see following slide) 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 Explain plan Verify the real execution plan running a query and analysing the real execution path Autotrace F6 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 Use tuning advisor to know suggestions about potential improvements of your queries SQL Tuning Advisor 17
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 Developer Connection creation New DB connection 19
And much more Develop Administer Model Migrate 20
SQL Developer Advantages 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 Search your session Logged as SM_PRESENT@TEST 25
SM terminate session Mark session and just do it! 26
Session details SQL details Execution plan Execution plan 27
SQL details Go to SQL details 28
E-groups in SM Check your privileges 29
E-groups in SM 30
E-group definition Create 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 Tool Automatic 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/serviceportal/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 Viewer Can be accessed at cern.ch/dblink-viewer Application that enables you to inspect database links Color Code Red Line - TNS alias is invalid or account is missing on target database Blue Line - Target database account is locked or has expired password Black Line - Link could not be checked: target database not accessible Grey Line - Link status has not been updated for three or more days Green Line - Everything good Background Color Red background - Link might be using an outdated password Orange background - Host descriptor is not a TNS alias Blue 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