Tools for Oracle Oracle Tutorials 2013 Przemyslaw Radowiecki CERN IT-DB
Plan Oracle SQL*Plus installation & configuration usage examples Golden Benthic Oracle SQL Developer CERN Session Manager 23/04/2013 Tools for Oracle related work 2
SQL*Plus command line SQL and PL/SQL language interface reporting tool shiped with the Oracle Database Client and Server software can be used interactively or driven from scripts sqlplus is equivalent to: "sqlcmd" in Microsoft SQL Server "psql" in PostgreSQL "mysql" in MySQL 23/04/2013 Tools for Oracle related work 3
When SQL*Plus? When troubleshooting database connection problems compatible with database: same manufacturer thin : lower probability of additional software level errors easy to use: need to know basic SQL commands In shell scripts Expired password change [ ] sqlplus -S /nolog <<EOF > /tmp/list_of_bases.lst connect myuser/$sm_pswd@db_service set head off set feedback off select unique base_name from bases_table order by 1; exit EOF [ ] 23/04/2013 Tools for Oracle related work 4
SQL*Plus example features substitution variables (&) SQL> insert into my_table(col1,col2) values ( &name,&age); Enter value for name:pradowie Enter value for age: repeating commands with changing input values; very powerful feature in conjuction with rlwrap (see following slide) external scripts (RUN or @) the command run or its alias: @ enables execution of SQL scripts stored on file system SQL> run /users/pradowie/myscript.sql SQL> @/users/pradowie/myscript 23/04/2013 Tools for Oracle related work 5
rlwrap 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 $@ 23/04/2013 Tools for Oracle related work 6
Benthic - Golden Easy to use, lightweight Free for CERN usage Limitations Windows only Oracle Instant Client 32-bit required CERN license for version 5 only 23/04/2013 Tools for Oracle related work 7
Feature example Output formatting 23/04/2013 Tools for Oracle related work 8
Installation and configuration Indicate oci.dll file from Oracle Instant Client 32-bit Find oci.dll To indicate oci.dll 23/04/2013 Tools for Oracle related work 9
Installation and configuration Download directly from Benthic http://www.benthicsoftware.com/downloads.html Follow installation instructions Input CERN license keys \\cern.ch\dfs\applications\benthic Benthic_keys_CERN.html Version 5 23/04/2013 Tools for Oracle related work 10
SQL Developer Oracle SQL Developer is a free graphical tool for database development. You can browse database objects, run SQL statements and SQL scripts, edit and debug PL/SQL statements. Free download from Oracle website: http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html can connect to any Oracle Database version 9.2.0.1 and later and runs on Windows, Linux, and Mac OSX 23/04/2013 Tools for Oracle related work 11
GUI 23/04/2013 Tools for Oracle related work 12
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 23/04/2013 Tools for Oracle related work 13
SQL tuning SQL Tuning Advisor Use tuning advisor to know suggestions about potential improvements of your queries 23/04/2013 Tools for Oracle related work 14
SQL Developer Connection creation New DB connection 23/04/2013 Tools for Oracle related work 15
And much more Develop Administer Model Migrate 23/04/2013 Tools for Oracle related work 16
SQL Developer Advantages Big development environment No need to install, simple unzip downloaded package and software is ready to use CONDITION: JDK is installed 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: start takes time*, sometimes slow Needs JDK (JRE not enough) Changed Java version can influence usability of SQL Developer For some time, the tool did not want to run on PC at all * For one of reasons of slow start see workaround in ANNEX A at the end of the presentation 23/04/2013 Tools for Oracle related work 17
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/ 23/04/2013 Tools for Oracle related work 18
Login Integrated with CERN SSO Two ways of database login: - credentials of a database account - e-groups 23/04/2013 Tools for Oracle related work 19
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 23/04/2013 Tools for Oracle related work 20
SM database credentials used (cont.) All Sessions = My Sessions + sessions to which I have privileges Search your session Logged as SM_PRESENT@TEST 23/04/2013 Tools for Oracle related work 21
SM terminate session Mark session and just do it! 23/04/2013 Tools for Oracle related work 22
Session details SQL details Execution plan Execution plan 23/04/2013 Tools for Oracle related work 23
SQL details Go to SQL details 23/04/2013 Tools for Oracle related work 24
E-groups in SM Check your privileges 23/04/2013 Tools for Oracle related work 25
E-groups in SM 23/04/2013 Tools for Oracle related work 26
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) to request new e-group registration Provide list of pairs (in CSV format): database name, account name test,sm_present Test,sm_present_dev dbdev11,appli_account Manage the list of your e-group members Remember about security implications! 23/04/2013 Tools for Oracle related work 27
Sources http://www.orafaq.com/wiki/sql*plus_faq http://www.oracle.com/technetwork/developer-tools/sql-developer/overview/index.html 23/04/2013 Tools for Oracle related work 28
ANNEX A SQL Developer long start and long connection creation using TNS SQL Developer parses all files named tnsnames* and recursively the directory pointed by TNS_ADMIN environment variable Make local copy of tnsnames.ora file Go to: Tools -> Preferences -> Database -> Advanced Remeber to refresh your local tnsnames.ora copy when you can t connect your database! Your local copy of tnsnames.ora 23/04/2013 Tools for Oracle related work 29