Quantcast
Channel: Donghua's Blog - DBAGlobe
Viewing all 604 articles
Browse latest View live

Use Certificate to secure the endpoint used for AlwaysOn Availability Group if local account used for SQL Server

$
0
0

 

image

Commands in SSOSQL1Commands in SSOSQL2

USE master

GO

CREATE MASTER KEY ENCRYPTION BY PASSWORD = '!QAZXSW#$%e';

GO

USE master;

GO

CREATE CERTIFICATE SSOSQL1_cert

WITH SUBJECT = 'SSOSQL1 certificate',

START_DATE = '20141031',

EXPIRY_DATE = '20241031';

GO

BACKUP CERTIFICATE SSOSQL1_cert TO FILE = 'C:\Backup\SSOSQL1_cert.cer';

GO

ALTER ENDPOINT [Hadr_endpoint] for database_mirroring( AUTHENTICATION = CERTIFICATE SSOSQL1_cert )

GO

USE master

GO

CREATE MASTER KEY ENCRYPTION BY PASSWORD = '!QAZXSW#$%e';

GO

USE master;

GO

CREATE CERTIFICATE SSOSQL2_cert

WITH SUBJECT = 'SSOSQL2 certificate',

START_DATE = '20141031',

EXPIRY_DATE = '20241031';

GO

BACKUP CERTIFICATE SSOSQL2_cert TO FILE = 'C:\Backup\SSOSQL2_cert.cer';

GO

ALTER ENDPOINT [Hadr_endpoint] for database_mirroring( AUTHENTICATION = CERTIFICATE SSOSQL2_cert )

GO

Copy SSOSQL1_cert.cer to Server SSOSQL2Copy SSOSQL2_cert.cer to Server SSOSQL1

USE master;

CREATE LOGIN [SSOSQL2_Login] WITH PASSWORD = '1Sample_Strong_Password!!#';

GO

CREATE USER [SSOSQL2_User] FOR LOGIN [SSOSQL2_Login];

GO

CREATE CERTIFICATE SSOSQL2_Cert

AUTHORIZATION SSOSQL2_User

FROM FILE = 'C:\backup\SSOSQL2_cert.cer'

GO

GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [SSOSQL2_Login];

GO

USE master;

CREATE LOGIN [SSOSQL1_Login] WITH PASSWORD = '1Sample_Strong_Password!!#';

GO

CREATE USER [SSOSQL1_User] FOR LOGIN [SSOSQL1_Login];

GO

CREATE CERTIFICATE SSOSQL1_Cert

AUTHORIZATION SSOSQL1_User

FROM FILE = 'C:\backup\SSOSQL1_cert.cer'

GO

GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [SSOSQL1_Login];

GO

Possible error message in the errorlog if certification not configured correctly:

Date 11/13/2014 8:43:50 AM

Log SQL Server (Current - 11/13/2014 8:26:00 AM)

Source Logon

Message

Database Mirroring login attempt failed with error: 'Connection handshake failed. There is no compatible authentication protocol. State 21.'. [CLIENT: 192.168.6.140]

Date 11/13/2014 8:43:53 AM

Log SQL Server (Current - 11/13/2014 8:26:00 AM)

Source Logon

Message

Database Mirroring login attempt failed with error: 'Connection handshake failed. The certificate used by the peer is invalid due to the following reason: Certificate not found. State 89.'. [CLIENT: 192.168.6.140]

 

Successful message:

Date 11/13/2014 8:49:47 AM

Log SQL Server (Current - 11/13/2014 8:26:00 AM)

Source spid25s

Message

A connection for availability group 'TestAG' from availability replica 'SSOSQL2' with id [20F90002-3F1A-440E-B8B1-BBDF23CAC3AC] to 'SSOSQL1' with id [DF75459C-A7C4-423A-92B8-DFE097ECAF06] has been successfully established. This is an informational message only. No user action is required.


Using DBCA to create CDB/PDB database in scripting manner

$
0
0

DBCA Script Generated by runInstaller:

/u01/app/oracle/product/12.1.0/dbhome_1/bin/dbca –silent -progress_only -createDatabase -templateName General_Purpose.dbc -createAsContainerDatabase true -pdbName pdb1 -numberOfPDBs 1 -sid cdborcl -gdbName cdborcl -emConfiguration DBEXPRESS -storageType FS -datafileDestination /u01/app/oracle/oradata -datafileJarLocation /u01/app/oracle/product/12.1.0/dbhome_1/assistants/dbca/templates -responseFile NO_VALUE -characterset WE8MSWIN1252 -obfuscatedPasswords false -sampleSchema true -automaticMemoryManagement true -totalMemory 1637 -maskPasswords false

Modified Version with “Silent” option:

/u01/app/oracle/product/12.1.0/dbhome_1/bin/dbca -silent -createDatabase -templateName General_Purpose.dbc -createAsContainerDatabase true -pdbName pdb1 -numberOfPDBs 1 -sid cdborcl -gdbName cdborcl -emConfiguration DBEXPRESS -storageType FS -datafileDestination /u01/app/oracle/oradata -datafileJarLocation /u01/app/oracle/product/12.1.0/dbhome_1/assistants/dbca/templates -responseFile NO_VALUE -characterset WE8MSWIN1252 -obfuscatedPasswords false -sampleSchema true -automaticMemoryManagement true -totalMemory 1637 -maskPasswords false

Output for Silent Option:

oracle@solaris:/u01/app/oracle/diag/rdbms/cdborcl/cdborcl/trace$
oracle@solaris:/u01/app/oracle/diag/rdbms/cdborcl/cdborcl/trace$ cd
oracle@solaris:~$ /u01/app/oracle/product/12.1.0/dbhome_1/bin/dbca -silent -createDatabase -templateName General_Purpose.dbc -createAsContainerDatabase true -pdbName pdb1 -numberOfPDBs 1 -sid cdborcl -gdbName cdborcl -emConfiguration DBEXPRESS -storageType FS -datafileDestination /u01/app/oracle/oradata -datafileJarLocation /u01/app/oracle/product/12.1.0/dbhome_1/assistants/dbca/templates -responseFile NO_VALUE -characterset WE8MSWIN1252 -obfuscatedPasswords false -sampleSchema true -automaticMemoryManagement true -totalMemory 1024 -maskPasswords false
Enter SYS user password:
password
Enter SYSTEM user password:
password
Enter PDBADMIN User Password:
password

Cleaning up failed steps
4% complete
Copying database files
5% complete
6% complete
12% complete
17% complete
22% complete
27% complete
30% complete
Creating and starting Oracle instance
32% complete
35% complete
36% complete
37% complete
41% complete
44% complete
45% complete
48% complete
Completing Database Creation
50% complete
53% complete
55% complete
63% complete
66% complete
74% complete
Creating Pluggable Databases
79% complete
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/cdborcl/cdborcl0.log" for further details.
oracle@solaris:~$

How many different type of wait event parameters in Oracle 12c (12.1.0.2)

$
0
0

SQL> select parameter1,count(*) from v$event_name group by parameter1 order by 2 desc;

PARAMETER1                                                         COUNT(*)
---------------------------------------------------------------- ----------
name|mode                                                               463
                                                                        456
type|mode                                                               200
address                                                                  50
file#                                                                    40
sleeptime/senderid                                                       40
cellhash#                                                                22
location                                                                 19
count                                                                    18
                                                                         17
driver id                                                                16
group                                                                    16
group#                                                                   14
Session ID                                                               13
2=>GoldenGate 1=>XStream 0=>Streams                                      12
session_id                                                                8
where                                                                     8
idn                                                                       7
sleep time                                                                7
function_id                                                               7
waittime                                                                  6
blkno                                                                     5
p1                                                                        5
filectx                                                                   5
handle address                                                            4
le                                                                        4
log#                                                                      4
file number                                                               4
block#                                                                    4
wait count                                                                4
retry count                                                               4
type                                                                      3
op                                                                        3
nalive                                                                    3
duration                                                                  3
object                                                                    3
files                                                                     3
cluinc                                                                    3
channel context                                                           3
msg ptr                                                                   3
clientid                                                                  3
requests                                                                  3
segment#                                                                  3
circuit#                                                                  2
msgop                                                                     2
buffer#                                                                   2
tsn                                                                       2
maximum attempts                                                          2
lmd/lms id                                                                2
object_id                                                                 2
Caller ID                                                                 2
dba                                                                       2
seghdr                                                                    2
waited                                                                    2
iowp id                                                                   2
pname                                                                     2
group_name1                                                               2
fileno                                                                    2
cache id                                                                  2
pid                                                                       2
wait for scn's hi 4 bytes                                                 2
channel handle                                                            2
Owner ID                                                                  2
copy latch #                                                              2
type|mode|where                                                           1
pool                                                                      1
undo seg#|slot#                                                           1
lock                                                                      1
hashid                                                                    1
action                                                                    1
File number                                                               1
Type                                                                      1
who am I                                                                  1
alive slaves                                                              1
send count                                                                1
index                                                                     1
event                                                                     1
table                                                                     1
undo segment#                                                             1
rootdba                                                                   1
end-point#                                                                1
kxfxsp debug wait: stalling for slave 0                                   1
component                                                                 1
ktelc_wait1s                                                              1
Slave ID                                                                  1
sleeptime                                                                 1
outstanding #aio                                                          1
wrap                                                                      1
blocks                                                                    1
operation count                                                           1
force SCN                                                                 1
succ                                                                      1
dismount force                                                            1
msg                                                                       1
by thread#                                                                1
dump                                                                      1
kxfxse debug wait: stalling for slave 0                                   1
delegation count                                                          1
timeout                                                                   1
FileOperation                                                             1
tape operation                                                            1
filename_hash                                                             1
object address                                                            1
netp id                                                                   1
dbwr#                                                                     1
xidusn                                                                    1
stage                                                                     1
function                                                                  1
process#                                                                  1
slave id                                                                  1
group_id                                                                  1
connection broker                                                         1
session#                                                                  1
defer segment index                                                       1
indicator                                                                 1
latch addr                                                                1
lwn_id                                                                    1
Instruction id                                                            1
branch#                                                                   1
session_num                                                               1
nservers                                                                  1
slowcellhash#                                                             1
kdcph_mai                                                                 1
from_process                                                              1
rolling mig                                                               1
domain id                                                                 1
caller instance number                                                    1
id                                                                        1
ts#                                                                       1
thread#                                                                   1
process number                                                            1
scans                                                                     1
tries                                                                     1
Broker Component                                                          1
test #                                                                    1
max operations                                                            1
component id                                                              1
retries                                                                   1
1=>MASTER 2=>SLAVE                                                        1
process_pid                                                               1
PURPOSE                                                                   1
pending_nd                                                                1
SCN                                                                       1
layer                                                                     1
clsrrestype                                                               1
serial                                                                    1
event #                                                                   1
limit                                                                     1
kdcphc_ack                                                                1
heap ds                                                                   1
wait event                                                                1
queue id                                                                  1
gopp id                                                                   1
error                                                                     1

154 rows selected.

SQL> select parameter2,count(*) from v$event_name group by parameter2 order by 2 desc;

PARAMETER2                                                         COUNT(*)
---------------------------------------------------------------- ----------
                                                                        602
id1                                                                     258
0                                                                        81
number                                                                   50
block#                                                                   44
passes                                                                   41
operation                                                                38
                                                                         24
QT_OBJ#                                                                  21
object #                                                                 20
Q_OBJ#                                                                   20
obj#                                                                     19
disk group                                                               15
intr                                                                     14
#bytes                                                                   14
disk group #                                                             12
log # / thread id #                                                      12
lock operation                                                           11
service ID                                                               11
tablespace #                                                             10
serial                                                                    8
value                                                                     8
diskhash#                                                                 7
0 or file #                                                               7
record type                                                               7
Internal                                                                  7
blocks                                                                    6
logid                                                                     6
file#                                                                     6
type                                                                      6
sleeptime                                                                 5
mode                                                                      5
kdlw lobid first half                                                     5
container group                                                           5
p2                                                                        5
resource id                                                               5
2                                                                         4
group ID / file ID                                                        4
where                                                                     4
wait flags                                                                4
opcode                                                                    4
first dba                                                                 4
persistent DG number                                                      4
usn<<16 | slot                                                            4
sqlid                                                                     3
TYPE                                                                      3
group and disk number                                                     3
count                                                                     3
failed                                                                    3
dbid                                                                      3
blkno                                                                     3
process#                                                                  3
reg id                                                                    3
waited                                                                    3
1                                                                         3
channel handle                                                            2
wait for scn's lo 4 bytes                                                 2
lms id                                                                    2
redo thread                                                               2
attempt count                                                             2
poll                                                                      2
lock address                                                              2
break?                                                                    2
0-MMON, 1-MMON Slave                                                      2
table space #                                                             2
message                                                                   2
groupid                                                                   2
Log #                                                                     2
disk group #:file #                                                       2
tablespace ID                                                             2
group_name2                                                               2
node#/parallelizer#                                                       2
checkpoint ID                                                             2
lock_mode                                                                 2
master object #                                                           2
#blks                                                                     2
Thread                                                                    2
bytes                                                                     2
workspace #                                                               2
interrupt                                                                 2
wait_count                                                                2
client id/group num                                                       2
sync scn                                                                  2
class id                                                                  2
size                                                                      1
fsb                                                                       1
num procs                                                                 1
low file obj add                                                          1
current aio limit                                                         1
property name                                                             1
op|restype                                                                1
pending_insts                                                             1
class*10+mode                                                             1
session ID                                                                1
undo segment #                                                            1
serial number                                                             1
view object #                                                             1
Session-id                                                                1
lock#                                                                     1
wait time                                                                 1
loop                                                                      1
slave_id                                                                  1
wait                                                                      1
file group id                                                             1
cluster incarnation number                                                1
scnwrp                                                                    1
amrv$ key                                                                 1
xidslt                                                                    1
requests                                                                  1
KZAM Fga Partition                                                        1
transaction entry #                                                       1
Wait Argument 1                                                           1
disk group number                                                         1
buffer length                                                             1
sleep time                                                                1
File Type or File number                                                  1
plan #                                                                    1
param                                                                     1
tx flags                                                                  1
retry_count                                                               1
l1bmb                                                                     1
hash value                                                                1
status                                                                    1
margin                                                                    1
consumer group id                                                         1
connection                                                                1
record length                                                             1
id                                                                        1
is_process                                                                1
nodeid                                                                    1
LTHREAD TYPE                                                              1
location                                                                  1
thread number                                                             1
base                                                                      1
scn                                                                       1
level                                                                     1
Schedule Id                                                               1
Flags                                                                     1
operation flags                                                           1
EnqMode                                                                   1
chunkNo                                                                   1
filename                                                                  1
dest|rcvr                                                                 1
pending_nd                                                                1
file #                                                                    1
KZAM Aud Partition                                                        1
element                                                                   1
Index Id                                                                  1
locn                                                                      1
gtrid hash value                                                          1
min_size                                                                  1
allocation mode                                                           1
process_sno                                                               1
rcvinc                                                                    1
chain#                                                                    1
wrap#                                                                     1
Slave process id                                                          1
KSBXIC Action                                                             1
error                                                                     1
instance                                                                  1
Op1                                                                       1
node#+sess#,cursor#+kv#                                                   1
file                                                                      1
map id                                                                    1
dginc                                                                     1
client id                                                                 1
fileno                                                                    1
channel handle count                                                      1
current size                                                              1
iocode                                                                    1
parno                                                                     1
waits                                                                     1
request                                                                   1
our thread#                                                               1
thread id #                                                               1
phase                                                                     1
pool #                                                                    1
Instance ID                                                               1
tsn#                                                                      1
segid                                                                     1
table obj#                                                                1
handle                                                                    1
edition obj#                                                              1
dg                                                                        1
pin address                                                               1
obj                                                                       1
block number                                                              1
startscn                                                                  1
client opcode                                                             1
inst id                                                                   1
tablespace # & objd                                                       1
Spillover audit file                                                      1
kjha_action                                                               1
lms#                                                                      1
group                                                                     1
task id                                                                   1

196 rows selected.


SQL> select parameter3,count(*) from v$event_name group by parameter3 order by 2 desc;

PARAMETER3                                                         COUNT(*)
---------------------------------------------------------------- ----------
                                                                        743
id2                                                                     258
0                                                                       150
tries                                                                    48
type                                                                     27
                                                                         25
timeout                                                                  25
block#                                                                   20
file #                                                                   20
shard:mode                                                               20
class#                                                                   17
sequence #                                                               13
queue type                                                               11
lock value                                                               11
operation parm                                                           10
blocks                                                                    9
dba                                                                       9
where                                                                     7
record id                                                                 7
thread                                                                    7
Internal                                                                  7
bktId<<16|instid                                                          6
p3                                                                        6
filetype                                                                  5
0/1                                                                       5
kdlw lobid sec half                                                       5
container id                                                              5
bytes                                                                     5
unused                                                                    4
block cnt                                                                 4
file ID                                                                   4
qref                                                                      4
workspace #                                                               4
non-DG number enqs                                                        4
sequence                                                                  4
disk #                                                                    4
id#                                                                       3
requests                                                                  3
wait                                                                      3
execid                                                                    3
2                                                                         3
AU number                                                                 3
notused                                                                   3
operation                                                                 3
instance                                                                  3
loop                                                                      3
size                                                                      2
block number                                                              2
slaveid                                                                   2
intr                                                                      2
100*mode+namespace                                                        2
location                                                                  2
zero                                                                      2
virtual extent number                                                     2
block                                                                     2
rdba                                                                      2
Bytes                                                                     2
file                                                                      2
event                                                                     2
bloom#                                                                    2
File number                                                               2
Sequence                                                                  2
process#                                                                  2
object #                                                                  1
set-id#                                                                   1
fail                                                                      1
ackscn                                                                    1
request identifier                                                        1
task id                                                                   1
ulevel                                                                    1
nbusy                                                                     1
Partition Id                                                              1
growth                                                                    1
target size                                                               1
100*mask+namespace                                                        1
op                                                                        1
wait time                                                                 1
allocated                                                                 1
1 or block                                                                1
count                                                                     1
objd#                                                                     1
group_name3                                                               1
1                                                                         1
not used                                                                  1
read/write                                                                1
version id                                                                1
mtype                                                                     1
log number                                                                1
childdba                                                                  1
insert/update                                                             1
Wait Argument 2                                                           1
extent                                                                    1
nothing                                                                   1
table/partition                                                           1
clatch                                                                    1
instanceid                                                                1
flag                                                                      1
only dml                                                                  1
relative file #                                                           1
hash value                                                                1
enqueue                                                                   1
serial #                                                                  1
slave ID                                                                  1
sequence # / apply #                                                      1
blockNo                                                                   1
instance|serial                                                           1
dtp                                                                       1
number of blocks                                                          1
mem_id                                                                    1
kv #                                                                      1
file number                                                               1
vol                                                                       1
wait time(millisec)                                                       1
pos                                                                       1
P3                                                                        1
id1|id2                                                                   1
startdba                                                                  1
Op2                                                                       1
Serial#                                                                   1
none                                                                      1
entry                                                                     1
bqual hash value                                                          1
diskno                                                                    1
high file obj add                                                         1
broadcast message                                                         1
scnbas                                                                    1
xidsqn                                                                    1
undo segment # / other                                                    1
waited                                                                    1
request                                                                   1
new aio limit                                                             1
key hash                                                                  1
buf_ptr                                                                   1
hash(logname)                                                             1
handle                                                                    1
generation                                                                1

136 rows selected.

Decoding P1/P2/P3 in for event 'enq: TX - row lock contention'

$
0
0

SQL> col wait_class for a20
SQL> col display_name for a35

SQL> select event#,wait_class,display_name
  2  from v$event_name where name='enq: TX - row lock contention';

    EVENT# WAIT_CLASS           DISPLAY_NAME
---------- -------------------- -----------------------------------
       267 Application          enq: TX - row lock contention

SQL> select count(event#),max(event#) from v$event_name;

COUNT(EVENT#) MAX(EVENT#)
------------- -----------
         1650        1649

SQL> select parameter1 from v$event_name
  2  where name='enq: TX - row lock contention';

PARAMETER1
----------------------------------------------------------------
name|mode

SQL> select parameter2 from v$event_name
  2  where name='enq: TX - row lock contention';

PARAMETER2
----------------------------------------------------------------
usn<<16 | slot

SQL> select parameter3 from v$event_name
  2  where name='enq: TX - row lock contention';

PARAMETER3
----------------------------------------------------------------
sequence


SQL> select userenv('sid') from dual;
USERENV('SID')
--------------
            67

SQL> create table t1 (c1 number);
Table created.

SQL> insert into t1 values(1);
1 row created.

SQL> commit;
Commit complete.

SQL> update t1 set c1=2;

1 row updated.


oracle@solaris:~$ sqlplus donghua/password@pdb1

SQL> select userenv('sid') from dual;
USERENV('SID')
--------------
            71
SQL> update t1 set c1=3;


SQL> select userenv('sid') from dual;

USERENV('SID')
--------------
             1

SQL> select seq#,event from v$session where sid=71;

      SEQ# EVENT
---------- ----------------------------------------------------------------
        45 enq: TX - row lock contention

SQL> col p1text for a40
SQL> col p2text for a40
SQL> col p3text for a40

SQL> select p1text,p1,p1raw from v$session where sid=71;

P1TEXT                                           P1 P1RAW
---------------------------------------- ---------- ----------------
name|mode                                1415053318 0000000054580006

SQL> select p2text,p2,p2raw from v$session where sid=71; <—refer to xidusn and xidslot column in v$transaction

P2TEXT                                           P2 P2RAW
---------------------------------------- ---------- ----------------
usn<<16 | slot                               196619 000000000003000B

SQL> select p3text,p3,p3raw from v$session where sid=71; <—Refer to xidsqn in v$transaction

P3TEXT                                           P3 P3RAW
---------------------------------------- ---------- ----------------
sequence                                       2018 00000000000007E2

SQL> select * from v$lock where sid=71;

ADDR             KADDR                   SID TY        ID1        ID2      LMODE    REQUEST      CTIME      BLOCK     CON_ID
---------------- ---------------- ---------- -- ---------- ---------- ---------- ---------- ---------- ---------- ----------
00000000BDE3BCA8 00000000BDE3BD20         71 AE        133          0          4          0       1339          0          3
00000000BDE3F250 00000000BDE3F2C8         71 TX     196619       2018          0          6       1270          0          0
FFFF80FFBDD386A0 FFFF80FFBDD38708         71 TM      92684          0          3          0       1270          0          3

SQL> select chr(bitand(p2, -16711680) / 16777215) || chr(bitand(p2, 16711680) / 65535) from v$session where sid=71;

CH
--
TX

SQL> select addr,xidusn,xidslot,xidsqn from v$transaction;

ADDR                 XIDUSN    XIDSLOT     XIDSQN
---------------- ---------- ---------- ----------
00000000BBB5F328          3         11       2018


SQL> col os_user for a10
SQL> col os_pid for a6
SQL> col oracle_user for a12
SQL> col lock_type for a15
SQL> col lock_held for a10
SQL> col lock_requested for a15
SQL> col status for a15
SQL> col owner for a10
SQL> col object_name for a11
SQL> set line 140
SQL> select     OS_USER_NAME os_user,
  2     PROCESS os_pid,
  3     ORACLE_USERNAME oracle_user,
  4     l.SID oracle_id,
  5     decode(TYPE,
  6             'MR', 'Media Recovery',
  7             'RT', 'Redo Thread',
  8             'UN', 'User Name',
  9             'TX', 'Transaction',
10             'TM', 'DML',
11             'UL', 'PL/SQL User Lock',
12             'DX', 'Distributed Xaction',
13             'CF', 'Control File',
14             'IS', 'Instance State',
15             'FS', 'File Set',
16             'IR', 'Instance Recovery',
17             'ST', 'Disk Space Transaction',
18             'TS', 'Temp Segment',
19             'IV', 'Library Cache Invalidation',
20             'LS', 'Log Start or Switch',
21             'RW', 'Row Wait',
22             'SQ', 'Sequence Number',
23             'TE', 'Extend Table',
24             'TT', 'Temp Table', type) lock_type,
25     decode(LMODE,
26             0, 'None',
27             1, 'Null',
28             2, 'Row-S (SS)',
29             3, 'Row-X (SX)',
30             4, 'Share',
31             5, 'S/Row-X (SSX)',
32             6, 'Exclusive', lmode) lock_held,
33     decode(REQUEST,
34             0, 'None',
35             1, 'Null',
36             2, 'Row-S (SS)',
37             3, 'Row-X (SX)',
38             4, 'Share',
39             5, 'S/Row-X (SSX)',
40             6, 'Exclusive', request) lock_requested,
41     decode(BLOCK,
42             0, 'Not Blocking',
43             1, 'Blocking',
44             2, 'Global', block) status,
45     OWNER,
46     OBJECT_NAME
47  from       v$locked_object lo,
48     dba_objects do,
49     v$lock l
50  where      lo.OBJECT_ID = do.OBJECT_ID
51  AND     l.SID = lo.SESSION_ID;

OS_USER    OS_PID ORACLE_USER   ORACLE_ID LOCK_TYPE       LOCK_HELD  LOCK_REQUESTED  STATUS          OWNER      OBJECT_NAME
---------- ------ ------------ ---------- --------------- ---------- --------------- --------------- ---------- -----------
oracle     2010   DONGHUA              71 DML             Row-X (SX) None            Not Blocking    DONGHUA    T1
oracle     2010   DONGHUA              71 Transaction     None       Exclusive       Not Blocking    DONGHUA    T1
oracle     2010   DONGHUA              71 AE              Share      None            Not Blocking    DONGHUA    T1
oracle     1959   DONGHUA              67 Transaction     Exclusive  None            Blocking        DONGHUA    T1
oracle     1959   DONGHUA              67 DML             Row-X (SX) None            Not Blocking    DONGHUA    T1
oracle     1959   DONGHUA              67 AE              Share      None            Not Blocking    DONGHUA    T1

6 rows selected.

SQL> col username for a10
SQL> col sql_text for a20

SQL> select     sn.USERNAME,
  2     m.SID,
  3     sn.SERIAL#,
  4     m.TYPE,
  5     decode(LMODE,
  6             0, 'None',
  7             1, 'Null',
  8             2, 'Row-S (SS)',
  9             3, 'Row-X (SX)',
10             4, 'Share',
11             5, 'S/Row-X (SSX)',
12             6, 'Exclusive') lock_type,
13     decode(REQUEST,
14             0, 'None',
15             1, 'Null',
16             2, 'Row-S (SS)',
17             3, 'Row-X (SX)',
18             4, 'Share',
19             5, 'S/Row-X (SSX)',
20             6, 'Exclusive') lock_requested,
21     m.ID1,
22     m.ID2,
23     t.SQL_TEXT
24  from       v$session sn,
25     v$lock m ,
26     v$sqltext t
27  where      t.ADDRESS = sn.SQL_ADDRESS
28  and        t.HASH_VALUE = sn.SQL_HASH_VALUE
29  and        ((sn.SID = m.SID and m.REQUEST != 0)
30  or         (sn.SID = m.SID and m.REQUEST = 0 and LMODE != 4 and (ID1, ID2) in
31          (select s.ID1, s.ID2
32           from      v$lock S
33           where     REQUEST != 0
34           and       s.ID1 = m.ID1
35           and       s.ID2 = m.ID2)))
36  order by sn.USERNAME, sn.SID, t.PIECE
37  /

USERNAME          SID    SERIAL# TY LOCK_TYPE       LOCK_REQUESTED         ID1        ID2 SQL_TEXT
---------- ---------- ---------- -- --------------- --------------- ---------- ---------- --------------------
DONGHUA            71      26079 TX None            Exclusive           196619       2018 update t1 set c1=3

SQL> SELECT VIEW_DEFINITION FROM V$FIXED_VIEW_DEFINITION WHERE VIEW_NAME='V$LOCK';

VIEW_DEFINITION
--------------------------------------------------------------------------------------------------------------------------------------------
select  ADDR , KADDR , SID , TYPE , ID1 , ID2 , LMODE , REQUEST , CTIME , BLOCK, CON_ID from GV$LOCK where inst_id = USERENV('Instance')

SQL> SELECT VIEW_DEFINITION FROM V$FIXED_VIEW_DEFINITION WHERE VIEW_NAME='GV$LOCK';

VIEW_DEFINITION
--------------------------------------------------------------------------------------------------------------------------------------------
select s.inst_id,l.laddr,l.kaddr,s.ksusenum,r.ksqrsidt,r.ksqrsid1,         r.ksqrsid2,l.lmode,l.request,l.ctime,decode(l.lmode,0,0,l.block),
         r.con_id  from v$_lock l, x$ksuse s, x$ksqrs r  where l.saddr=s.addr and        concat(USERENV('Instance'),l.raddr)=concat(r.inst_i
d,r.addr)

 

Where file# 203 come from in the alert log

$
0
0

2014-11-30 16:37:56.111000 +08:00
Resize operation completed for file# 203, old size 20480K, new size 21504K
Resize operation completed for file# 203, old size 21504K, new size 22528K
Resize operation completed for file# 203, old size 22528K, new size 23552K
Resize operation completed for file# 203, old size 23552K, new size 24576K
Resize operation completed for file# 203, old size 24576K, new size 25600K
Resize operation completed for file# 203, old size 25600K, new size 26624K
Resize operation completed for file# 203, old size 26624K, new size 27648K
Resize operation completed for file# 203, old size 27648K, new size 28672K
Resize operation completed for file# 203, old size 28672K, new size 29696K
Resize operation completed for file# 203, old size 29696K, new size 30720K
Resize operation completed for file# 203, old size 30720K, new size 31744K
Resize operation completed for file# 203, old size 31744K, new size 32768K
Resize operation completed for file# 203, old size 32768K, new size 33792K
Resize operation completed for file# 203, old size 33792K, new size 34816K
Resize operation completed for file# 203, old size 34816K, new size 35840K
Resize operation completed for file# 203, old size 35840K, new size 36864K
Resize operation completed for file# 203, old size 36864K, new size 37888K
Resize operation completed for file# 203, old size 37888K, new size 38912K
Resize operation completed for file# 203, old size 38912K, new size 39936K
Resize operation completed for file# 203, old size 39936K, new size 40960K
2014-11-30 16:37:57.111000 +08:00
Resize operation completed for file# 203, old size 40960K, new size 41984K
Resize operation completed for file# 203, old size 41984K, new size 43008K
Resize operation completed for file# 203, old size 43008K, new size 44032K
Resize operation completed for file# 203, old size 44032K, new size 45056K
Resize operation completed for file# 203, old size 45056K, new size 46080K
Resize operation completed for file# 203, old size 46080K, new size 47104K
Resize operation completed for file# 203, old size 47104K, new size 48128K
Resize operation completed for file# 203, old size 48128K, new size 49152K
2014-11-30 18:08:04.016000 +08:00
Resize operation completed for file# 3, old size 614400K, new size 624640K

SQL> select * from cdb_temp_files;

FILE_NAME
--------------------------------------------------------------------------------
   FILE_ID TABLESPACE_NAME                     BYTES     BLOCKS STATUS
---------- ------------------------------ ---------- ---------- -------
RELATIVE_FNO AUT   MAXBYTES  MAXBLOCKS INCREMENT_BY USER_BYTES USER_BLOCKS
------------ --- ---------- ---------- ------------ ---------- -----------
    CON_ID
----------
/u01/app/oracle/oradata/cdborcl/pdb1/pdb1_temp012014-11-29_10-40-40-PM.dbf
         3 TEMP                             50331648       6144 ONLINE
           1 YES 3.4360E+10    4194302           80   49283072        6016
         3

/u01/app/oracle/oradata/cdborcl/temp01.dbf
         1 TEMP                             62914560       7680 ONLINE
           1 YES 3.4360E+10    4194302           80   61865984        7552
         1


SQL> select 50331648/1024 from dual;

50331648/1024
-------------
        49152

Stop logging all successful backups in SQL Server error logs

$
0
0

sp_cycle_errorlog

BACKUP DATABASE [D1] 
TO DISK = N'C:\Temp\D1.bak' WITH NOFORMAT, INIT
GO

DBCC TRACEON (3226,-1)

BACKUP DATABASE [D1] 
TO DISK = N'C:\Temp\D1.bak' WITH NOFORMAT, INIT
GO

DBCC TRACEOFF (3226,-1)

BACKUP DATABASE [D1] 
TO DISK = N'C:\Temp\D1.bak' WITH NOFORMAT, INIT
GO

image

image

Permanent solution:

image

Fix slow linux problem without restarting the server (during EM Cloud Control 12c Installation)

$
0
0

[oracle@em12c ~]$ sudo su -
[root@em12c ~]# free
             total       used       free     shared    buffers     cached
Mem:      10806464    8677960    2128504    1247780      81344    7395976
-/+ buffers/cache:    1200640    9605824
Swap:     17407996      20340   17387656
[root@em12c ~]#
[root@em12c ~]# sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"
[root@em12c ~]#
[root@em12c ~]#
[root@em12c ~]# free
             total       used       free     shared    buffers     cached
Mem:      10806464    2256236    8550228    1247780       1692    1331976
-/+ buffers/cache:     922568    9883896
Swap:     17407996      20340   17387656

How to connect to DB2 database remotely

$
0
0

Catalog the node


Syntax: db2 catalog tcpip node <NODENAME> remote <REMOTE> server <PORT>


C:\Program Files\IBM\SQLLIB\BIN>db2 catalog tcpip node server1 remote 192.168.6.141 server 50000
DB20000I  The CATALOG TCPIP NODE command completed successfully.
DB21056W  Directory changes may not be effective until the directory cache is refreshed.

Catalog the database


Syntax:  db2 catalog database <database_name> at node <node_name>


C:\Program Files\IBM\SQLLIB\BIN>db2 catalog database sampledb at node server1
DB20000I  The CATALOG DATABASE command completed successfully.
DB21056W  Directory changes may not be effective until the directory cache is refreshed.

Refresh directory


C:\Program Files\IBM\SQLLIB\BIN>db2 terminate
DB20000I  The TERMINATE command completed successfully.

Connect to database


Syntax: db2 connect to <database_name> user <user_name> (you will then be prompted for a password)


C:\Program Files\IBM\SQLLIB\BIN>db2 connect to sampledb user db2admin using P@ssw0rd

   Database Connection Information

Database server        = DB2/NT64 9.7.6
SQL authorization ID   = DB2ADMIN
Local database alias   = SAMPLEDB

C:\Program Files\IBM\SQLLIB\BIN>db2 list tables

Table/View                      Schema          Type  Creation time

------------------------------- --------------- ----- --------------------------


  0 record(s) selected.

Verify catalog database


 
C:\Program Files\IBM\SQLLIB\BIN>db2 list db directory

System Database Directory

Number of entries in the directory = 1

Database 1 entry:

Database alias                       = SAMPLEDB
Database name                        = SAMPLEDB
Node name                            = SERVER1
Database release level               = d.00
Comment                              =
Directory entry type                 = Remote
Catalog database partition number    = -1
Alternate server hostname            =
Alternate server port number         =

C:\Program Files\IBM\SQLLIB\BIN>db2 list node directory show detail

Node Directory

Number of entries in the directory = 1

Node 1 entry:

Node name                      = SERVER1
Comment                        =
Directory entry type           = LOCAL
Protocol                       = TCPIP
Hostname                       = 192.168.6.141
Service name                   = 50000
Remote instance name           =
System                         =
Operating system type          = None


Cloning an Oracle Home in Oracle 12c

$
0
0
1. Create a TAR file with the Oracle home (but not the Oracle base) directory (ZIP has problems to preserve permission and ownerships) ("-p" option in tar is default if run with super user)

root@solaris:/u01/stage# tar cvf - /u01/app/oracle/product/12.1.0/dbhome_1 | gzip -c > dbhome_1.tar.gz

2. Copy the TAR file to the root directory of the target computer. If you use File Transfer Protocol (FTP), then transfer the TAR file in binary mode only.

root@solaris:/u01/stage# scp dbhome_1.tar.gz   oracle@192.168.6.101:/u01/
dbhome_1.tar.gz      100% |*************************************|  2648 MB    14:31


3. Extract the TAR file content using the following command:

root@solaris112:/# gunzip -c dbhome_1.tar.gz | tar xf -


root@solaris112:/u01# chown oracle:oinstall app
root@solaris112:/u01# chown oracle:oinstall app/oracle/
root@solaris112:/u01# chown oracle:oinstall app/oracle/product/
root@solaris112:/u01# chown oracle:oinstall app/oracle/product/12.1.0/

4. On the target computer, change the directory to the unzipped Oracle home directory, and remove all the .ora (*.ora) files present in the unzipped $ORACLE_HOME/network/admin directory.

oracle@solaris112:~$ rm /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/*.ora

5. From the $ORACLE_HOME/clone/bin directory, run the clone.pl file for the unzipped Oracle home.

oracle@solaris112:~$ export ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1

oracle@solaris112:~$ $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/clone/bin/clone.pl ORACLE_BASE="/u01/app/oracle/"ORACLE_HOME="/u01/app/oracle/product/12.1.0/dbhome_1" OSDBA_GROUP=dba -defaultHomeName

./runInstaller -clone -waitForCompletion  "ORACLE_BASE=/u01/app/oracle/" "ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1" "oracle_install_OSDBA=dba" -defaultHomeName  -silent -paramFile /u01/app/oracle/product/12.1.0/dbhome_1/clone/clone_oraparam.ini
Starting Oracle Universal Installer...

Checking Temp space: must be greater than 500 MB.   Actual 1371 MB    Passed
Checking swap space: must be greater than 500 MB.   Actual 1570 MB    Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2014-12-11_03-29-21PM. Please wait ...You can find the log of this install session at:
/u01/app/oraInventory/logs/cloneActions2014-12-11_03-29-21PM.log
..................................................   5% Done.
..................................................   10% Done.
..................................................   15% Done.
..................................................   20% Done.
..................................................   25% Done.
..................................................   30% Done.
..................................................   35% Done.
..................................................   40% Done.
..................................................   45% Done.
..................................................   50% Done.
..................................................   55% Done.
..................................................   60% Done.
..................................................   65% Done.
..................................................   70% Done.
..................................................   75% Done.
..................................................   80% Done.
..................................................   85% Done.
..........
Copy files in progress.

Copy files successful.

Link binaries in progress.

Link binaries successful.

Setup files in progress.

Setup files successful.

Setup Inventory in progress.

Setup Inventory successful.

Finish Setup successful.
The cloning of OraHome1 was successful.
Please check '/u01/app/oraInventory/logs/cloneActions2014-12-11_03-29-21PM.log' for more details.

Setup Oracle Base in progress.

Setup Oracle Base successful.
..................................................   95% Done.

As a root user, execute the following script(s):
        1. /u01/app/oraInventory/orainstRoot.sh
        2. /u01/app/oracle/product/12.1.0/dbhome_1/root.sh

..................................................   100% Done.


root@solaris112:/u01# /u01/app/oraInventory/orainstRoot.sh
root@solaris112:/u01# /u01/app/oracle/product/12.1.0/dbhome_1/root.sh

6. To configure the connection information for the new database, run Net Configuration Assistant:

$ cd $ORACLE_HOME/bin
$ ./netca

7. To create a new database for the newly cloned Oracle home, run Database Configuration Assistant:

$ cd $ORACLE_HOME/bin
$ ./dbca


Error 1:

..........SEVERE:Unable to create directory /u01/app/oracle. You may not have the proper permission to create the directory, or there is no space left in the volume.
Unable to create the Oracle Base you have specified.
The cloning of OraHome1 was unsuccessful.
Please check '/export/home/oracle/oraInventory/logs/cloneActions2014-12-11_03-25-50PM.log' for more details.

Fix: Change folder permission (Refer to step 3)

Examples on Silent operations of NETCA and DBCA in Oracle 12c

$
0
0

oracle@solaris112:~$ find $ORACLE_HOME -name *.rsp
/u01/app/oracle/product/12.1.0/dbhome_1/inventory/response/db_install.rsp
/u01/app/oracle/product/12.1.0/dbhome_1/inventory/response/oracle.server_EE.rsp
/u01/app/oracle/product/12.1.0/dbhome_1/assistants/netca/netca.rsp
/u01/app/oracle/product/12.1.0/dbhome_1/assistants/netca/netca_custom.rsp
/u01/app/oracle/product/12.1.0/dbhome_1/assistants/dbca/dbca.rsp
/u01/app/oracle/product/12.1.0/dbhome_1/network/install/netca_typ.rsp
/u01/app/oracle/product/12.1.0/dbhome_1/network/install/netca_clt.rsp


oracle@solaris112:~$ cat /u01/app/oracle/product/12.1.0/dbhome_1/assistants/netca/netca.rsp|grep -v ^$|grep -v ^#
[GENERAL]
RESPONSEFILE_VERSION="12.1"
CREATE_TYPE="CUSTOM"
[oracle.net.ca]
INSTALLED_COMPONENTS={"server","net8","javavm"}
INSTALL_TYPE=""typical""
LISTENER_NUMBER=1
LISTENER_NAMES={"LISTENER"}
LISTENER_PROTOCOLS={"TCP;1521"}
LISTENER_START=""LISTENER""
NAMING_METHODS={"TNSNAMES","ONAMES","HOSTNAME"}
NSN_NUMBER=1
NSN_NAMES={"EXTPROC_CONNECTION_DATA"}
NSN_SERVICE={"PLSExtProc"}
NSN_PROTOCOLS={"TCP;HOSTNAME;1521"}


oracle@solaris112:~$ netca -silent -responsefile /u01/app/oracle/product/12.1.0/dbhome_1/assistants/netca/netca.rsp

Parsing command line arguments:
    Parameter "silent" = true
    Parameter "responsefile" = /u01/app/oracle/product/12.1.0/dbhome_1/assistants/netca/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
    Running Listener Control:
      /u01/app/oracle/product/12.1.0/dbhome_1/bin/lsnrctl start LISTENER
    Listener Control complete.
    Listener started successfully.
Listener configuration complete.
Oracle Net Services configuration successful. The exit code is 0

oracle@solaris112:~$ cp /u01/app/oracle/product/12.1.0/dbhome_1/assistants/dbca/dbca.rsp /u01/app/oracle/product/12.1.0/dbhome_1/assistants/dbca/dbca_orcl2.rsp

oracle@solaris112:~$ cat /u01/app/oracle/product/12.1.0/dbhome_1/assistants/dbca/dbca_orcl2.rsp|grep -v ^$|grep -v ^#
[GENERAL]
RESPONSEFILE_VERSION = "12.1.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "orcl2.dbaglobe.com"
SID = "orcl2"
TEMPLATENAME = "General_Purpose.dbc"
SYSPASSWORD = "password"
SYSTEMPASSWORD = "password"
CHARACTERSET = "WE8MSWIN1252"
NATIONALCHARACTERSET= "AL16UTF16"
SAMPLESCHEMA=TRUE
TOTALMEMORY = "1200"


oracle@solaris112:~$ dbca -silent -responseFile /u01/app/oracle/product/12.1.0/dbhome_1/assistants/dbca/dbca_orcl2.rsp
Cleaning up failed steps
5% complete
Copying database files
7% complete
9% complete
16% complete
23% complete
30% complete
37% complete
41% complete
Creating and starting Oracle instance
43% complete
48% complete
53% complete
58% complete
62% complete
63% complete
64% complete
67% complete
Completing Database Creation
71% complete
74% complete
78% complete
88% complete
99% complete
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/orcl2/orcl21.log" for further details.

Examples on DB2 cold backup

$
0
0

db2 => CONNECT TO SAMPLEDB

   Database Connection Information

Database server        = DB2/NT64 9.7.10
SQL authorization ID   = ADMINIST...
Local database alias   = SAMPLEDB

db2 => QUIESCE DATABASE IMMEDIATE FORCE CONNECTIONS
DB20000I  The QUIESCE DATABASE command completed successfully.
db2 => CONNECT RESET
DB20000I  The SQL command completed successfully.
db2 => BACKUP DATABASE SAMPLEDB TO "D:\backup" WITH 2 BUFFERS BUFFER 1024 PARALLELISM 1 WITHOUT PROMPTING

Backup successful. The timestamp for this backup image is : 20141211074809

db2 => CONNECT TO SAMPLEDB

   Database Connection Information

Database server        = DB2/NT64 9.7.10
SQL authorization ID   = ADMINIST...
Local database alias   = SAMPLEDB

db2 => UNQUIESCE DATABASE
DB20000I  The UNQUIESCE DATABASE command completed successfully.
db2 => CONNECT RESET
DB20000I  The SQL command completed successfully.

db2 => list backup all for database sampledb

                    List History File for sampledb

Number of matching file entries = 1


Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log  Backup ID
-- --- ------------------ ---- --- ------------ ------------ --------------
  B  D  20141211074809001   F    D  S0000000.LOG S0000000.LOG
----------------------------------------------------------------------------
  Contains 3 tablespace(s):

00001 SYSCATSPACE
00002 USERSPACE1
00003 SYSTOOLSPACE
----------------------------------------------------------------------------
    Comment: DB2 BACKUP SAMPLEDB OFFLINE
Start Time: 20141211074809
   End Time: 20141211074811
     Status: A
----------------------------------------------------------------------------
  EID: 2 Location: D:\backup

Sample Restoration Script:

CONNECT TO SAMPLEDB
QUIESCE DATABASE IMMEDIATE FORCE CONNECTIONS
CONNECT RESET
RESTORE DATABASE SAMPLEDB FROM "D:\backup" TAKEN AT 20141211074809 WITH 2 BUFFERS BUFFER 1024 PARALLELISM 1 WITHOUT PROMPTING
CONNECT TO SAMPLEDB
UNQUIESCE DATABASE
CONNECT RESET

DB2 Configure Database Logging Wizard

$
0
0

image

image

image

image

image

image

image

image

image

image

image

Scripts:

CONNECT TO SAMPLEDB
QUIESCE DATABASE IMMEDIATE FORCE CONNECTIONS
UNQUIESCE DATABASE
CONNECT RESET
UPDATE DB CFG FOR SAMPLEDB USING logarchmeth1 "DISK:D:\PrimaryLog" logprimary 13 logsecond 4 logfilsiz 2500 failarchpath "D:\SecondaryLog"
BACKUP DATABASE SAMPLEDB TO "D:\backup" WITH 2 BUFFERS BUFFER 1024 PARALLELISM 1 WITHOUT PROMPTING

How to enable SSL encryption for Oracle SQL*Net (Without SSH Authentication)

$
0
0

1) Create a directory to store all our wallets:

 

oracle@solaris:~$ mkdir /u01/app/oracle/wallet

 

oracle@solaris112:~$ mkdir /u01/app/oracle/wallet

2) Create a wallet for the primary database. Create an empty wallet with auto login enabled:

 

oracle@solaris:~$ cd /u01/app/oracle/wallet

oracle@solaris:/u01/app/oracle/wallet$ orapki wallet create -wallet /u01/app/oracle/wallet -auto_login -pwd welcome1

Oracle PKI Tool : Version 12.1.0.2

Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.

 

oracle@solaris:/u01/app/oracle/wallet$ ls -l /u01/app/oracle/wallet

total 6

-rw-------   1 oracle   oinstall     120 Dec 14 23:29 cwallet.sso

-rw-rw-rw-   1 oracle   oinstall       0 Dec 14 23:29 cwallet.sso.lck

-rw-------   1 oracle   oinstall      75 Dec 14 23:29 ewallet.p12

-rw-rw-rw-   1 oracle   oinstall       0 Dec 14 23:29 ewallet.p12.lck

 

oracle@solaris112:/u01/app/oracle/wallet$ orapki wallet create -wallet /u01/app/oracle/wallet -auto_login -pwd welcome2

Oracle PKI Tool : Version 12.1.0.2

Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.

 

oracle@solaris112:/u01/app/oracle/wallet$ ls -l /u01/app/oracle/wallet

total 4

-rw-------   1 oracle   oinstall     120 Dec 15 07:30 cwallet.sso

-rw-rw-rw-   1 oracle   oinstall       0 Dec 15 07:30 cwallet.sso.lck

-rw-------   1 oracle   oinstall      75 Dec 15 07:30 ewallet.p12

-rw-rw-rw-   1 oracle   oinstall       0 Dec 15 07:30 ewallet.p12.lck

 

3) Add a self-signed certificate in the wallet (a new pair of private/public keys is created):

 

oracle@solaris:/u01/app/oracle/wallet$ orapki wallet add -wallet /u01/app/oracle/wallet -dn "CN=solaris.dbaglobe.com" -keysize 1024 -self_signed -validity 365 -pwd welcome1

Oracle PKI Tool : Version 12.1.0.2

Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.

 

oracle@solaris112:/u01/app/oracle/wallet$ orapki wallet add -wallet /u01/app/oracle/wallet -dn "CN=solaris112.dbaglobe.com" -keysize 1024 -self_signed -validity 365 -pwd welcome2

Oracle PKI Tool : Version 12.1.0.2

Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.

 

If you display the server’s wallet you will see the following requested certificate:

oracle@solaris:/u01/app/oracle/wallet$ orapki wallet display -wallet /u01/app/oracle/wallet                                                            Oracle PKI Tool : Version 12.1.0.2

Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.

 

Requested Certificates:

User Certificates:

Subject:        CN=solaris.dbaglobe.com

Trusted Certificates:

Subject:        CN=solaris.dbaglobe.com

 

oracle@solaris112:~$  orapki wallet display -wallet /u01/app/oracle/wallet                                                                             Oracle PKI Tool : Version 12.1.0.2

Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.

 

Requested Certificates:

User Certificates:

Subject:        CN=solaris112.dbaglobe.com

Trusted Certificates:

Subject:        CN=solaris112.dbaglobe.com

4) Export the certificate:

oracle@solaris:/u01/app/oracle/wallet$ orapki wallet export -wallet /u01/app/oracle/wallet -dn "CN=solaris.dbaglobe.com" -cert /u01/app/oracle/wallet/solaris.dbaglobe.com.txt

Oracle PKI Tool : Version 12.1.0.2

Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.

 

oracle@solaris112:~$ orapki wallet export -wallet /u01/app/oracle/wallet -dn "CN=solaris112.dbaglobe.com" -cert /u01/app/oracle/wallet/solaris112.dbaglobe.com.txt

Oracle PKI Tool : Version 12.1.0.2

Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.

5) Exchange the server and client their public keys:

oracle@solaris:/u01/app/oracle/wallet$ scp solaris112:/u01/app/oracle/wallet/solaris112.dbaglobe.com.txt .

oracle@solaris:/u01/app/oracle/wallet$ scp /u01/app/oracle/wallet/solaris.dbaglobe.com.txt  solaris112:/u01/app/oracle/wallet/

 

oracle@solaris:/u01/app/oracle/wallet$ orapki wallet add -wallet /u01/app/oracle/wallet -trusted_cert -cert /u01/app/oracle/wallet/solaris112.dbaglobe.com.txt -pwd welcome1

Oracle PKI Tool : Version 12.1.0.2

Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.

 

oracle@solaris112:~$ orapki wallet add -wallet /u01/app/oracle/wallet -trusted_cert -cert /u01/app/oracle/wallet/solaris.dbaglobe.com.txt -pwd welcome2

Oracle PKI Tool : Version 12.1.0.2

Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.

 

oracle@solaris:/u01/app/oracle/wallet$ orapki wallet display -wallet /u01/app/oracle/wallet                                                            Oracle PKI Tool : Version 12.1.0.2

Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.

 

Requested Certificates:

User Certificates:

Subject:        CN=solaris.dbaglobe.com

Trusted Certificates:

Subject:        CN=solaris112.dbaglobe.com

Subject:        CN=solaris.dbaglobe.com

oracle@solaris112:~$ orapki wallet display -wallet /u01/app/oracle/wallet

Oracle PKI Tool : Version 12.1.0.2

Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.

 

Requested Certificates:

User Certificates:

Subject:        CN=solaris112.dbaglobe.com

Trusted Certificates:

Subject:        CN=solaris.dbaglobe.com

Subject:        CN=solaris112.dbaglobe.com

6) Configure the listeners to work with TCPS

 

oracle@solaris:/u01/app/oracle/wallet$ lsnrctl stop

 

Edit server side configuration use netmgr. Sample configuration as below:

 

oracle@solaris:/u01/app/oracle/wallet$ cat /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora

SSL_CLIENT_AUTHENTICATION = FALSE

WALLET_LOCATION =

  (SOURCE =

    (METHOD = FILE)

    (METHOD_DATA =

      (DIRECTORY = /u01/app/oracle/wallet)

    )

  )

 

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = TCP)(HOST = solaris)(PORT = 1521))

    )

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = TCPS)(HOST = solaris)(PORT = 1531))

    )

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

    )

  )

 

ADR_BASE_LISTENER = /u01/app/oracle

 

oracle@solaris:/u01/app/oracle/wallet$ cat /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/sqlnet.ora

 

 

SQLNET.AUTHENTICATION_SERVICES= (BEQ, TCPS)

 

SSL_VERSION = 0

 

NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)

 

SSL_CLIENT_AUTHENTICATION = FALSE

 

WALLET_LOCATION =

  (SOURCE =

    (METHOD = FILE)

    (METHOD_DATA =

      (DIRECTORY = /u01/app/oracle/wallet)

    )

  )

 

ADR_BASE = /u01/app/oracle

 

oracle@solaris:/u01/app/oracle/wallet$ lsnrctl start

 

7) Configure the sqlnet.ora & tnsnames.ora on the client

 

oracle@solaris112:~$ cat /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/sqlnet.ora

 

#Parameter for TDE

ENCRYPTION_WALLET_LOCATION =

  (SOURCE =

    (METHOD = FILE)

    (METHOD_DATA =

      (DIRECTORY = /u01/app/oracle/wallet)

    )

  )

 

SQLNET.AUTHENTICATION_SERVICES= (BEQ, TCPS)

 

SSL_VERSION = 0

 

NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)

 

SSL_CLIENT_AUTHENTICATION = FALSE

 

WALLET_LOCATION =

  (SOURCE =

    (METHOD = FILE)

    (METHOD_DATA =

      (DIRECTORY = /u01/app/oracle/wallet)

    )

  )

 

ADR_BASE = /u01/app/oracle

 

oracle@solaris112:~$ echo "

> ORCL1_TCPS =

>   (DESCRIPTION =

>     (ADDRESS = (PROTOCOL = TCP)(HOST = solaris)(PORT = 1521))

>     (CONNECT_DATA =

>       (SERVER = DEDICATED)

>       (SERVICE_NAME = orcl1)

>     )

>   )

>

> " >> /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/tnsnames.ora

 

8) Check the connectivity

 

oracle@solaris112:/u01/app/oracle/product/12.1.0/dbhome_1/network/admin$ tnsping ORCL1_TCPS

 

TNS Ping Utility for Solaris: Version 12.1.0.2.0 - Production on 15-DEC-2014 08:39:03

 

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

 

Used parameter files:

/u01/app/oracle/product/12.1.0/dbhome_1/network/admin/sqlnet.ora

 

Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCPS)(HOST = solaris)(PORT = 1531)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl1)))

OK (20 msec)

oracle@solaris112:~$ sqlplus system/password@orcl1_tcps

 

SQL*Plus: Release 12.1.0.2.0 Production on Mon Dec 15 08:39:57 2014

 

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

 

Last Successful login time: Mon Dec 15 2014 00:39:21 +08:00

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

 

SQL>  select sys_context('userenv','network_protocol') from dual;

 

SYS_CONTEXT('USERENV','NETWORK_PROTOCOL')

--------------------------------------------------------------------------------

Tcps

SQL> select userenv('sid') from dual;

 

USERENV('SID')

--------------

            50

SQL> select * from v$session_connect_info where sid=50;

 

       SID    SERIAL# AUTHENTICATION_TYPE        OSUSER

---------- ---------- -------------------------- ------------------------------

NETWORK_SERVICE_BANNER

--------------------------------------------------------------------------------

CLIENT_CHARSET                           CLIENT_CONNEC

---------------------------------------- -------------

CLIENT_OCI_LIBRARY          CLIENT_VERSION

--------------------------- ----------------------------------------

CLIENT_DRIVER                  CLIENT_LOBATTR          CLIENT_REGID     CON_ID

------------------------------ ----------------------- ------------ ----------

        50      14986 DATABASE                   oracle

 

US7ASCII                                 Homogeneous

Home-based                  12.1.0.2.0

SQL*PLUS                       Client Temp Lob Rfc On             0          0

 

        50      14986 DATABASE                   oracle

Authentication service for Solaris: Version 12.1.0.2.0 - Production

US7ASCII                                 Homogeneous

Home-based                  12.1.0.2.0

SQL*PLUS                       Client Temp Lob Rfc On             0          0

 

        50      14986 DATABASE                   oracle

Encryption service for Solaris: Version 12.1.0.2.0 - Production

US7ASCII                                 Homogeneous

Home-based                  12.1.0.2.0

SQL*PLUS                       Client Temp Lob Rfc On             0          0

 

        50      14986 DATABASE                   oracle

Crypto-checksumming service for Solaris: Version 12.1.0.2.0 - Production

US7ASCII                                 Homogeneous

Home-based                  12.1.0.2.0

SQL*PLUS                       Client Temp Lob Rfc On             0          0

 

 

 

Possible errors 1: (To resolve it, include  –pwd parameter)

oracle@solaris:/u01/app/oracle/wallet$ orapki wallet add -wallet /u01/app/oracle/wallet -trusted_cert -cert /u01/app/oracle/wallet/solaris112.dbaglobe.com.txt

Oracle PKI Tool : Version 12.1.0.2

Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.

 

Could not install trusted cert at/u01/app/oracle/wallet/solaris112.dbaglobe.com.txt

PKI-02008: Unable to modify a read-only Auto-login wallet.

 

Possible errors 2: (To resolve it, use different port number for TCP and TCPS)

 

oracle@solaris:/u01/app/oracle/wallet$ lsnrctl start

 

LSNRCTL for Solaris: Version 12.1.0.2.0 - Production on 15-DEC-2014 00:02:21

 

Copyright (c) 1991, 2014, Oracle.  All rights reserved.

 

Starting /u01/app/oracle/product/12.1.0/dbhome_1/bin/tnslsnr: please wait...

 

TNSLSNR for Solaris: Version 12.1.0.2.0 - Production

System parameter file is /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora

Log messages written to /u01/app/oracle/diag/tnslsnr/solaris/listener/alert/log.xml

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=solaris)(PORT=1521)))

Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=TCPS)(HOST=solaris)(PORT=1521)))

TNS-12542: TNS:address already in use

 TNS-12560: TNS:protocol adapter error

  TNS-00512: Address already in use

   Solaris Error: 125: Address already in use

 

Listener failed to start. See the error message(s) above...

 

Possible errors 3: (To resolve it, use proper wallet location)

 

oracle@solaris112:~$ sqlplus system/p_ssw0rd@orcl1_tcps

 

SQL*Plus: Release 12.1.0.2.0 Production on Mon Dec 15 08:14:21 2014

 

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

 

ERROR:

ORA-28759: failure to open file

 

oracle@solaris112:~$ tnsping orcl1_tcps

 

TNS Ping Utility for Solaris: Version 12.1.0.2.0 - Production on 15-DEC-2014 08:14:50

 

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

 

Used parameter files:

/u01/app/oracle/product/12.1.0/dbhome_1/network/admin/sqlnet.ora

 

Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCPS)(HOST = solaris)(PORT = 1531)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl1)))

TNS-12560: TNS:protocol adapter error

How to enable SSL Authentication for Oracle Database Client

$
0
0

To setup SSL, refer to steps 1-7 in document “How to enable SSL encryption for Oracle SQL*Net”

http://www.dbaglobe.com/2014/12/how-to-enable-ssl-encryption-for-oracle.html

1) Configure the listeners.ora (server) & tnsnames.ora (server & client)

 

SSL_CLIENT_AUTHENTICATION = TRUE

 

SSL_CLIENT_AUTHENTICATION = TRUE

 

2) Configuring the database

 

The database parameter OS_AUTHENT_PREFIX must be null and REMOTE_OS_AUTHENT must be FALSE.

SQL> select value from v$parameter where name='remote_os_authent';

 

VALUE

--------------------------------------------------------------------------------

FALSE

SQL> select value from v$parameter where name='os_authent_prefix';

 

VALUE

--------------------------------------------------------------------------------

ops$

 

SQL> alter system set os_authent_prefix='' scope=spfile;

 

System altered.

 

SQL> startup force

 

The user within the database has to be created specifying the distiguished name (DN) on their certificate. For example,

SQL> create user solaris112_user identified externally as 'CN=solaris112.dbaglobe.com';

 

User created.

 

SQL>  grant create session to solaris112_user;

 

Grant succeeded.

 

SQL>  grant select on v$session_connect_info to solaris112_user;

 grant select on v$session_connect_info to solaris112_user

                 *

ERROR at line 1:

ORA-02030: can only select from fixed tables/views

 

 

SQL> grant select on v_$session_connect_info to solaris112_user;

 

Grant succeeded.

 

3) Connect as the TCPS authenticated user

oracle@solaris112:~$ sqlplus /@orcl1_tcps

 

SQL*Plus: Release 12.1.0.2.0 Production on Mon Dec 15 09:12:31 2014

 

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

 

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

 

SQL> show user

USER is "SOLARIS112_USER"

 

SQL> select sys_context('userenv','network_protocol') from dual;

 

SYS_CONTEXT('USERENV','NETWORK_PROTOCOL')

--------------------------------------------------------------------------------

tcps

 

SQL> select userenv('sid') from dual;

 

USERENV('SID')

--------------

            36

 

SQL> set pages 999

 

SQL> select * from v$session_connect_info where sid=36;

 

       SID    SERIAL# AUTHENTICATION_TYPE        OSUSER

---------- ---------- -------------------------- ------------------------------

NETWORK_SERVICE_BANNER

--------------------------------------------------------------------------------

CLIENT_CHARSET                           CLIENT_CONNEC

---------------------------------------- -------------

CLIENT_OCI_LIBRARY          CLIENT_VERSION

--------------------------- ----------------------------------------

CLIENT_DRIVER                  CLIENT_LOBATTR          CLIENT_REGID     CON_ID

------------------------------ ----------------------- ------------ ----------

        36      63563 GLOBAL                     CN=solaris112.dbaglobe.com

 

US7ASCII                                 Homogeneous

Home-based                  12.1.0.2.0

SQL*PLUS                       Client Temp Lob Rfc On             0          0

 

        36      63563 GLOBAL                     CN=solaris112.dbaglobe.com

Authentication service for Solaris: Version 12.1.0.2.0 - Production

US7ASCII                                 Homogeneous

Home-based                  12.1.0.2.0

SQL*PLUS                       Client Temp Lob Rfc On             0          0

 

        36      63563 GLOBAL                     CN=solaris112.dbaglobe.com

Encryption service for Solaris: Version 12.1.0.2.0 - Production

US7ASCII                                 Homogeneous

Home-based                  12.1.0.2.0

SQL*PLUS                       Client Temp Lob Rfc On             0          0

 

        36      63563 GLOBAL                     CN=solaris112.dbaglobe.com

Crypto-checksumming service for Solaris: Version 12.1.0.2.0 - Production

US7ASCII                                 Homogeneous

Home-based                  12.1.0.2.0

SQL*PLUS                       Client Temp Lob Rfc On             0          0

Database link with SSL SQL*Net encryption

$
0
0

SQL> connect donghua/password
Connected.
SQL> select instance_name from v$instance;

INSTANCE_NAME
----------------
orcl2

SQL> create database link orcl1 connect to donghua identified by password using 'orcl1_tcps';

Database link created.

SQL> select instance_name from v$instance@orcl1;

INSTANCE_NAME
----------------
orcl1

From listener.log:

2014-12-15 19:31:46.280000 +08:00
15-DEC-2014 19:31:46 * (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl1)(CID=(PROGRAM=oracle)(HOST=solaris112)(USER=oracle))) * (ADDRESS=(PROTOCOL=tcps)(HOST=192.168.6.101)(PORT=63856)) * establish * orcl1 * 0


Sample code for encryption-only SSL using JDBC/thin driver with Oracle database

$
0
0

Working Code & Compilation

import java.sql.*;
import java.util.Properties;
import oracle.jdbc.pool.OracleDataSource;
import oracle.security.pki.OraclePKIProvider;
import java.security.Security;

public class SSLTestV2 {
    public static void main(String[] args) throws SQLException {
        Connection conn = getConnection();
        conn.close();
    }

    public static Connection getConnection() throws SQLException {
        OracleDataSource ods = new OracleDataSource();
        ods.setURL("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=solaris)(PORT=1531))(CONNECT_DATA=(SERVICE_NAME=orcl1)))");
        Properties props = new Properties();
        props.setProperty("user", "donghua");
        props.setProperty("password", "Passw0rd");
        Security.insertProviderAt(new OraclePKIProvider(), 3);

        props.setProperty("oracle.net.wallet_location","(SOURCE=(METHOD=file)(METHOD_DATA=(DIRECTORY=/u01/app/oracle/wallet)))");
        ods.setConnectionProperties(props);


        Connection conn = ods.getConnection();
        DatabaseMetaData dbmd = conn.getMetaData();
        System.out.println(dbmd.getDatabaseProductVersion());
        System.out.println("JDBC driver: " + dbmd.getDriverVersion());
        System.out.println("JDBC URL: " + dbmd.getURL());
        conn.setAutoCommit(false);
        return conn;
    }
}

oracle@solaris112:~$ /usr/java/bin/javac -cp /u01/app/oracle/product/12.1.0/dbhome_1/jdbc/lib/ojdbc7.jar:/u01/app/oracle/product/12.1.0/dbhome_1/jlib/oraclepki.jar SSLTestV2.java
oracle@solaris112:~$ /usr/java/bin/java -cp .:/u01/app/oracle/product/12.1.0/dbhome_1/jdbc/lib/ojdbc7.jar:/u01/app/oracle/product/12.1.0/dbhome_1/jlib/oraclepki.jar SSLTestV2
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
JDBC driver: 12.1.0.2.0
JDBC URL: jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=solaris)(PORT=1531))(CONNECT_DATA=(SERVICE_NAME=orcl1)))

oracle@solaris112:~$

Not working code with possible errors:


root@solaris112:~# /usr/java/bin/java -version
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) Client VM (build 24.60-b09, mixed mode)

oracle@solaris112:~$ $ORACLE_HOME/jdk/bin/java -version
java version "1.6.0_75"
Java(TM) SE Runtime Environment (build 1.6.0_75-b13)
Java HotSpot(TM) Client VM (build 20.75-b01, mixed mode)
oracle@solaris112:~$

import java.sql.*;
import java.util.Properties;
import oracle.jdbc.pool.OracleDataSource;

public class SSLTestV1 {
    public static void main(String[] args) throws SQLException {
        Connection conn = getConnection();
        conn.close();
    }

    public static Connection getConnection() throws SQLException {
        OracleDataSource ods = new OracleDataSource();
        ods.setURL("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=solaris)(PORT=1531))(CONNECT_DATA=(SERVICE_NAME=orcl1)))");
        Properties props = new Properties();
        props.setProperty("user", "donghua");
        props.setProperty("password", "Passw0rd");
        props.setProperty("oracle.net.ssl_cipher_suites","(SSL_DH_anon_WITH_3DES_EDE_CBC_SHA, SSL_DH_anon_WITH_RC4_128_MD5,SSL_DH_anon_WITH_DES_CBC_SHA)");
        ods.setConnectionProperties(props);

        Connection conn = ods.getConnection();
        DatabaseMetaData dbmd = conn.getMetaData();
        System.out.println(dbmd.getDatabaseProductVersion());
        System.out.println("JDBC driver: " + dbmd.getDriverVersion());
        System.out.println("JDBC URL: " + dbmd.getURL());
        conn.setAutoCommit(false);
        return conn;
    }
}

oracle@solaris112:~$ $ORACLE_HOME/jdk/bin/javac -cp /u01/app/oracle/product/12.1.0/dbhome_1/jdbc/lib/ojdbc7.jar SSLTest.java
warning: oracle/jdbc/pool/OracleDataSource.class(oracle/jdbc/pool:OracleDataSource.class): major version 51 is newer than 50, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
1 warning

oracle@solaris112:~$ $ORACLE_HOME/jdk/bin/java -cp .:/u01/app/oracle/product/12.1.0/dbhome_1/jdbc/lib/ojdbc7.jar SSLTest
Exception in thread "main" java.lang.UnsupportedClassVersionError: oracle/jdbc/pool/OracleDataSource : Unsupported major.minor version 51.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at SSLTest.getConnection(SSLTest.java:12)
        at SSLTest.main(SSLTest.java:7)

oracle@solaris112:~$ java -cp .:/u01/app/oracle/product/12.1.0/dbhome_1/jdbc/lib/ojdbc7.jar SSLTest
Exception in thread "main" java.sql.SQLRecoverableException: IO Error: Received fatal alert: handshake_failure
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:752)
        at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666)
        at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:566)
        at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:317)
        at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:241)
        at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:184)
        at SSLTest.getConnection(SSLTest.java:20)
        at SSLTest.main(SSLTest.java:7)
Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
        at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
        at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
        at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1959)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1077)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
        at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:702)
        at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:122)
        at oracle.net.ns.Packet.send(Packet.java:419)
        at oracle.net.ns.ConnectPacket.send(ConnectPacket.java:241)
        at oracle.net.ns.NSProtocolStream.negotiateConnection(NSProtocolStream.java:157)
        at oracle.net.ns.NSProtocol.connect(NSProtocol.java:264)
        at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1452)
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:496)
        ... 8 more

oracle@solaris112:~$ java -cp .:/u01/app/oracle/product/12.1.0/dbhome_1/jdbc/lib/ojdbc7.jar SSLTest
Exception in thread "main" java.sql.SQLRecoverableException: IO Error: Remote host closed connection during handshake
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:752)
        at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666)
        at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:566)
        at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:317)
        at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:241)
        at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:184)
        at SSLTest.getConnection(SSLTest.java:20)
        at SSLTest.main(SSLTest.java:7)
Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:946)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
        at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:702)
        at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:122)
        at oracle.net.ns.Packet.send(Packet.java:419)
        at oracle.net.ns.ConnectPacket.send(ConnectPacket.java:241)
        at oracle.net.ns.NSProtocolStream.negotiateConnection(NSProtocolStream.java:157)
        at oracle.net.ns.NSProtocol.connect(NSProtocol.java:264)
        at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1452)
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:496)
        ... 8 more
Caused by: java.io.EOFException: SSL peer shut down incorrectly
        at sun.security.ssl.InputRecord.read(InputRecord.java:482)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
        ... 17 more
       

How to fix SQL Developer Unsupported JDK Version. (You are attempting to run with java …”

$
0
0

image

image

Change the Value for “SetJavaHome” in %APPDATA%\sqldeveloper\<version>\product.conf.

image

SQL Text Expansion in Oracle 12c

$
0
0

This procedure will be handy if you are asked to tune a query, which looks like short, but actual complexity hidden by the views. You can use this procedure to expand the view definition into the query.

https://docs.oracle.com/database/121/ARPLS/d_util.htm#ARPLS73973

SQL> variable x clob
SQL> begin
  2    dbms_utility.expand_sql_text(
  3      input_sql_text => 'select * from hr.emp_details_view where employee_id=107',
  4      output_sql_text => :x
  5    );
  6  end;
  7  /

PL/SQL procedure successfully completed.

SQL> print x

X
--------------------------------------------------------------------------------
SELECT "A1"."EMPLOYEE_ID" "EMPLOYEE_ID","A1"."JOB_ID" "JOB_ID","A1"."MANAGER_ID"

SQL> set long 2000
SQL> set longc 2000
SQL> set pages 999
SQL> print x

X
--------------------------------------------------------------------------------
SELECT "A1"."EMPLOYEE_ID" "EMPLOYEE_ID","A1"."JOB_ID" "JOB_ID","A1"."MANAGER_ID"
"MANAGER_ID","A1"."DEPARTMENT_ID" "DEPARTMENT_ID","A1"."LOCATION_ID" "LOCATION_
ID","A1"."COUNTRY_ID" "COUNTRY_ID","A1"."FIRST_NAME" "FIRST_NAME","A1"."LAST_NAM
E" "LAST_NAME","A1"."SALARY" "SALARY","A1"."COMMISSION_PCT" "COMMISSION_PCT","A1
"."DEPARTMENT_NAME" "DEPARTMENT_NAME","A1"."JOB_TITLE" "JOB_TITLE","A1"."CITY" "
CITY","A1"."STATE_PROVINCE" "STATE_PROVINCE","A1"."COUNTRY_NAME" "COUNTRY_NAME",
"A1"."REGION_NAME" "REGION_NAME" FROM  (SELECT "A7"."EMPLOYEE_ID" "EMPLOYEE_ID",
"A7"."JOB_ID" "JOB_ID","A7"."MANAGER_ID" "MANAGER_ID","A7"."DEPARTMENT_ID" "DEPA
RTMENT_ID","A6"."LOCATION_ID" "LOCATION_ID","A4"."COUNTRY_ID" "COUNTRY_ID","A7".
"FIRST_NAME" "FIRST_NAME","A7"."LAST_NAME" "LAST_NAME","A7"."SALARY" "SALARY","A
7"."COMMISSION_PCT" "COMMISSION_PCT","A6"."DEPARTMENT_NAME" "DEPARTMENT_NAME","A
5"."JOB_TITLE" "JOB_TITLE","A4"."CITY" "CITY","A4"."STATE_PROVINCE" "STATE_PROVI
NCE","A3"."COUNTRY_NAME" "COUNTRY_NAME","A2"."REGION_NAME" "REGION_NAME" FROM HR
."EMPLOYEES" "A7",HR."DEPARTMENTS" "A6",HR."JOBS" "A5",HR."LOCATIONS" "A4",HR."C
OUNTRIES" "A3",HR."REGIONS" "A2" WHERE "A7"."DEPARTMENT_ID"="A6"."DEPARTMENT_ID"
AND "A6"."LOCATION_ID"="A4"."LOCATION_ID" AND "A4"."COUNTRY_ID"="A3"."COUNTRY_I
D" AND "A3"."REGION_ID"="A2"."REGION_ID" AND "A5"."JOB_ID"="A7"."JOB_ID") "A1" W
HERE "A1"."EMPLOYEE_ID"=107

SQL> set lin 20000

SQL> print x

X
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SELECT "A1"."EMPLOYEE_ID" "EMPLOYEE_ID","A1"."JOB_ID" "JOB_ID","A1"."MANAGER_ID" "MANAGER_ID","A1"."DEPARTMENT_ID" "DEPARTMENT_ID","A1"."LOCATION_ID" "LOCATION_ID","A1"."COUNTRY_ID" "COUNTRY_ID","A1"."FIRST_NAME" "FIRST_NAME","A1"."LAST_NAME" "LAST_NAME","A1"."SALARY" "SALARY","A1"."COMMISSION_PCT" "COMMISSION_PCT","A1"."DEPARTMENT_NAME" "DEPARTMENT_NAME","A1"."JOB_TITLE" "JOB_TITLE","A1"."CITY" "CITY","A1"."STATE_PROVINCE" "STATE_PROVINCE","A1"."COUNTRY_NAME" "COUNTRY_NAME","A1"."REGION_NAME" "REGION_NAME" FROM  (SELECT "A7"."EMPLOYEE_ID" "EMPLOYEE_ID","A7"."JOB_ID" "JOB_ID","A7"."MANAGER_ID" "MANAGER_ID","A7"."DEPARTMENT_ID" "DEPARTMENT_ID","A6"."LOCATION_ID" "LOCATION_ID","A4"."COUNTRY_ID" "COUNTRY_ID","A7"."FIRST_NAME" "FIRST_NAME","A7"."LAST_NAME" "LAST_NAME","A7"."SALARY" "SALARY","A7"."COMMISSION_PCT" "COMMISSION_PCT","A6"."DEPARTMENT_NAME" "DEPARTMENT_NAME","A5"."JOB_TITLE" "JOB_TITLE","A4"."CITY" "CITY","A4"."STATE_PROVINCE" "STATE_PROVINCE","A3"."COUNTRY_NAME" "COUNTRY_NAME","A2"."REGION_NAME" "REGION_NAME" FROM HR."EMPLOYEES" "A7",HR."DEPARTMENTS" "A6",HR."JOBS" "A5",HR."LOCATIONS" "A4",HR."COUNTRIES" "A3",HR."REGIONS" "A2" WHERE "A7"."DEPARTMENT_ID"="A6"."DEPARTMENT_ID" AND "A6"."LOCATION_ID"="A4"."LOCATION_ID" AND "A4"."COUNTRY_ID"="A3"."COUNTRY_ID" AND "A3"."REGION_ID"="A2"."REGION_ID" AND "A5"."JOB_ID"="A7"."JOB_ID") "A1" WHERE "A1"."EMPLOYEE_ID"=107

Use SQL Developer to format the SQL Statement:

image

Cannot drop suspect mirror database? Here is explanation and workaround

$
0
0

·         Mirror database is suspect (hardware failure causing corruption), SQL Server can’t apply the redo logs on the mirror

·         With the intent to recover DB and reestablish mirroring, ALTER DATABASE … SET PARTNER OFF is issued on the principal

o   DB Mirroring breaks DBM session from the principal point of view, and then sends the message to the mirror

o   Mirror tries to break the DBM session; however, SQL Server attempts to apply all the remaining log in the redo queue before it breaks the DBM session. This is by design. The goal is to apply all the logs it has received because the user may be attempting to break the mirror so as to read the data on the mirror database. It makes sense to apply as much redo log records as possible

·         DBM session is not broken from the mirror point of view

·         All subsequent actions (drop database, restore database) are blocked, because SQL Server still views this as a mirror database

Workaround:

Shutdown the instance and remove the mdf, ndf and ldf for the suspect database, and start the instance. You should be able to restore the instance, and recreate the mirror.

Approximate Count Distinct–Oracle Database 12c

$
0
0

 

Not every query requires a completely accurate result, for example “How many distinct individuals visited our website last week?”.

New SQL function for approximate results for COUNT DISTINCT aggregates –APPROX_COUNT_DISTINCT()

  • Approximate results can be significantly faster and use less resources than exact calculations
  • –5x to 50x ++ times faster (depending upon number of distinct values and complexity of SQL)
    –Accuracy > 97% (with 95% confidence)

Example:

SQL> select count(distinct prod_id) from sh.sales;

COUNT(DISTINCTPROD_ID)
----------------------
                    72

SQL> select approx_count_distinct(prod_id) from sh.sales;

APPROX_COUNT_DISTINCT(PROD_ID)
------------------------------
                            72

SQL>  select count(distinct cust_id) from sh.sales;

COUNT(DISTINCTCUST_ID)
----------------------
                  7059

SQL> select approx_count_distinct(cust_id) from sh.sales;

APPROX_COUNT_DISTINCT(CUST_ID)
------------------------------
                          7014

Viewing all 604 articles
Browse latest View live