Wednesday, 29 April 2015

Command Line: sqlcl startup shutdown of pdb and non pdb databases (Should even work from a Mac - pure Java)

Tested against release 16th April 2015 drop.

Startup and shutdown of pluggable and non pluggable datbases.

bash-4.1$ ./sql sys@_non_pluggable__

SQLcl: Release 4.1.0 Release Candidate on

Copyright (c) 1982, 2015, Oracle.  All rights reserved.


Connected to an Idle instance, startup command available.
SQL> startup
Started up
Database Mounted
Database Open

Total System Global Area   12345 bytes    
Fixed Size                    54321 bytes    
Variable Size               12345 bytes    
Database Buffers            54321 bytes    
Redo Buffers                 12345 bytes    
SQL> shutdown
Instance stopped
Database closed.
Database dismounted.
Database shutdown.
SQL> connect sys@__pluggable__ as sysdba
Connected

SQL> shutdown
Pluggable database closed
SQL> startup
Pluggable database opened
SQL>

One point to remember - configure your listener for remote (or 127.0.0.1 loopback) startup/shutdown if you are not using thick/bequeath Oracle client 'C' code, so the listener can find the database when the database is down.

listener.ora entry:

SID_LIST_LISTENER =
 (SID_LIST=
  (SID_DESC=
   (GLOBAL_DBNAME=THEDATABASE)
   (ORACLE_HOME=THE_ORACLE_HOME)
   (SID_NAME=THEDATABASE)
  )
 )

Should even work from a Mac - pure Java..

NET Command - persistently store network details with tab completion

Example using tab completion: (need to be in sql for tab complete to work e.g. ./sql /nolog)

SQL> net unique=localhost:1521/mysid;
SQL> net list
unique
SQL> net list unique
unique
------
localhost:1521/mysid
SQL> connect username/password@uni__TAB_FOR_COMPLETION__
SQL> connect username/password@unique

tab completion works for net shortcuts and tnsnames.ora details.

Behind the scenes net is very similar to the alias command.

**************************************************************
If anyone has useful alias command uses or wanted extensions
to alias command I would be interested to know. 
(Jeff Smith is the Product Manager if you want to go through official channels).
**************************************************************

Turloch

The Net help page:

>help net
NET
------

Command line only - not for sqldeveloper.

NET is a command which allows you to save a network details and assign it a shortcut command.
"net" - print a list of net short cuts
"net list " - list the contents of the short cut
"net name=localhost:1521/XE;" simple net command
"net drop name" - delete the short cut called name

net is single line terminated by newline
net ..=.. is terminated by ';'
net on its own gives a list of existing short cuts.

controlled by
set net on|off|readonly - default ON
   readonly means only do try to enter a net shortcut on successful connect command
set noverwrite on|off|warn - default WARN
   net overwrite: warn prints a warning if an override would otherwise happen.


Monday, 9 March 2015

Data Pump Wizard enhancement

If the master table is kept (now the default) SQL Developer 4.1 (EA1 and above) can find the log file name.

Steps - launch export/import as usual then:

1/Go to dbaview -> Data Pump -> export (or import) jobs

2/Pick a job that is 'Not Running'

3/LOG FILES output shows the Log file from the server.


Issues:
Log file viewer contains a few extra lines at the top.
State (schema/job id) is not cleared if you change connection.
Requires UTL_FILE

Tuesday, 3 February 2015

Introducing LDAPCON Helper feature for LDAP (for thin), in Jan30 release:

Either
1/By environmental variable, or
2/sdsql /nolog
then
set LDAPCON jdbc:oracle:thin:@ldap://ldapmachine.us.oracle.com:389/#ENTRY#,cn=OracleContext,dc=ie,dc=lcom
(the above is one line from set to lcom)

For example by bash environmental variable:
>set LDAPCON=jdbc:oracle:thin:@ldap://ldapmachine.us.oracle.com:389/#ENTRY#,cn=OracleContext,dc=ie,dc=lcom
(the above is one line from set to lcom)

>sdsql "sys/__the_password__@THEADDRESS" as sysdba
connects via: jdbc:oracle:thin:@ldap://ldapmachine.us.oracle.com:389/THEADDRESS,cn=OracleContext,dc=ie,dc=lcom

ldap.ora for sqlplus will contain:
Machine:ldapmachine.us.oracle.com port:389
and
context:cn=OracleContext,dc=ie,dc=lcom

I have not automated the removal of this information from ldap.ora

LDAP for thick:
As sqlplus configure via ldap.ora and sqlnet.ora

Note the file to kick off the command line product has been through a few iterations, seems to be currently sql (or sql.bat)

Tuesday, 6 January 2015

Alias command - a little like shell alias

SQL> help alias
ALIAS
------

Not a sqlplus command.

alias
alias name=select :one from dual;
SQL> alias fred=select :one from dual;
SQL> fred 1
Command=fred
:ONE
--------------------------------
1

SQL> alias db= begin dbms_output.put_line('hi'); end;
2  /
SQL> db
Command=db
anonymous block completed
hi

alias is single line terminated by newline
alias ..=.. is terminated by ';'
alias ..=begin or ..=declare is terminated by newline/
alias on its own gives a list of existing aliases.

SQL>REM loaded on demand and saved on exit (sdsql only). WARNING - two sessions - last to exit will overwrite.
SQL>REM show current aliases
SQL> alias
locks
tables
SQL> alias mysql=select 'mysql' from dual;
SQL> mysql
Command=mysql
'MYSQL'
-------
mysql

SQL> set serveroutput on
SQL> alias myplsql=begin
  2  dbms_output.put_line('some output');
  3  end;
  4  /
SQL> myplsql
Command=myplsql
anonymous block completed
some output
SQL>REM plsql (given above - note abusing / a little - call it 'executing a plsql alias assignment command'), q string or bind
SQL>REM q string:(Complex option 1: for use by the 1% of use cases with multiple commands)
SQL> alias mysql=q'[select 'mysql' from
  2  dual]';
SQL> mysql
Command=mysql
'MYSQL'
-------
mysql
SQL>REM bind: (Complex option 2: for use by the 0.1% of use cases that require preprocessing of alias text or other 'maximum' flexibility)
SQL> variable bind clob;
SQL> begin :bind:='select ''frombind'' from dual'; end;
  2  /
anonymous block completed
SQL> alias mysql=:bind;
SQL> mysql
Command=mysql
'FROMBIND'
----------
frombind
SQL>REM using bind: 
SQL>  alias mysql2=select :vv from dual;
SQL> mysql2 'hello vv'
Command=mysql2
:VV
--------------------------------
hello vv
SQL> REM You can use existing or prompted for substitution variables - arguments are all (new) binds
SQL> REM obvious usecase capture sql from a live job, run unchanged as an alias using the argument to bind facility. 
SQL> REM running from a clob bind variable opens up lots of possibilities 1/ download a script from a database and run it 2/ run without accessing the file system 3/dynamically change (preprocess) the bind value (equivalent of #ifdef, or changing strings) before creating the alias.

EDIT1: Warning around infrequent higher flexibility use cases.
EDIT2: The bind arguments are assumed to be varchar2 (as opposed to numeric or date for example)
- automatic type conversion done by the sql layer
- use TO_DATE(:thevarchar,'the_date_mask') if you prefer explicit conversion.

Tuesday, 10 September 2013

Rough notes on Proxy connections

Oracle® Database Security Guide
12c Release 1 (12.1)
E17607-19
Creating Proxy User Accounts and Authorizing Users to Connect Through Them
http://docs.oracle.com/cd/E16655_01/network.121/e17607/authentication.htm#DBSEG99851

I just want to document in 'Connections with Proxy Authentication' that there are two ways of doing proxy users a single session way and a double session way It looks like people will in future go for the simpler single session way.

There are two ways of doing proxy logins:
where p1 is proxy user and c1 is proxy client:

(Mapping over from the doc link: p1=appuser, c1=preston)
1/single session method (if no 2nd password or distinguished name required)
on main connection popup
user: p1[c1]
password: p1

2/Two session method
Main Connection popup
user: p1
password p1

popup connection authentication
-proxy client is correct - was (2009) labeled proxy user which is the name for p1[

proxy client: c1
none or password or distinguished name

password:
(
To create proxy client with password authentication:
CREATE USER c1 IDENTIFIED BY ;
ALTER USER c1 GRANT CONNECT THROUGH p1 AUTHENTICATED USING PASSWORD;
GRANT create session TO c1;

)

TODO - cover Distinguished Name authentication

Monday, 22 July 2013

User check on sqldeveloper (worksheet) issue

1/provide a full reproducible testcase so a bug can be logged and the issue can be worked in Oracle using the source code. Not sure about 4.0EA but if it happens with production SQLDeveloper and production database - you can go through official Oracle support.
2/Do not install SQLDeveloper 4.0 EA1 on top of another SQLDeveloper installation
3/Use latest Java7
4/Are you using multibyte characters? (Chinese or Japanese being the most widely used in support calls)
5/Try as a operating system different user In case your preferences are corrupt. (you can move your existing preferences out of the way - but using another user seems to avoid any support/user error possibilities.)
6/Try with SQLDeveloper 3.2.2
7/Try with SQLPLUS
8/debugging logging: Most serious java issues cause a message to the screen ('Java Stack Trace') if you start sqldeveloper from ide/sqldeveloper/bin from the command line There is also View->log->Logging Pane - which probably gives too much information [This blog has an introduction to tracing http://totierne.blogspot.co.uk/2013/02/introduction-to-tracing.html entry for the more adventurous - there is lots of information but the important bit is you can see exactly what is being sent to and from the database.]
9/Try the query as run statement, run script, try count (*), try a subset of columns, try to_char() the columns so the data transformation is mostly done in the Oracle Database
10/Are you using thick(i.e.OCI) or thin jdbc connection type? What driver are you using? What database are you using(try 'show jdbc' worksheet command) Is tools-->preferences->database->advanced->Use OCI/Thick driver checked
11/If trying with sys - try as another user.
12/When installing run as the installing user once so the JDK version can be put in the configuration file.
13/Useful SQLPLUS emulation features:
set echo on
set verify on
show jdbc
spool