Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > Oracle Database

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-24-2008, 08:09 AM
Ed Stevens
 
Posts: n/a
Default script problem solved, but I still don't understand ....

Platform - Oracle 9.2 EE on Solaris 8

I was putting together a note asking for a second set of eyes, but as
I reviewed it before posting, I found the solution. But I still don't
understand everything about it.

Running a shell script that calls SQL*Plus to execute a sql script.
Ran fine from the command line but failed when run from crontab.
Output showed that after connecting, the first SQL statement returned
a ORA-01034: ORACLE not available.

I finally realized that even though I was setting ORACLE_SID in the
shell script, I wasn't exporting it so that SQLPlus could see it.
After adding 'export ORACLE_SID' to the shell script it ran like a
champ.

But I still don't understand why it got (or seemed to get) a
successful connection in the first place, or once it had it, a DML
statement would return 'ORACLE not available'.

The actual invocation of sqlplus in the shell script looks like this:

sqlplus "/ as sysdba" @mysqlscript


and the output looked like this. Note the successfull 'connected'
just before the DELETE statement.

SQL*Plus: Release 9.2.0.1.0 - Production on Wed Oct 13 14:42:00 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected.
SQL> DELETE FROM mytable
2 WHERE sample_time < sysdate - &1
3 ;
old 2: WHERE sample_time < sysdate - &1
new 2: WHERE sample_time < sysdate - 15
DELETE FROM mytable
*
ERROR at line 1:
ORA-01034: ORACLE not available


I'm sure this is something I should know. Maybe I do know it, but am
just having a DSA (Dumb S*** Attack (tm)) I think my memory is maxed
out, and everytime I have to remember something new, something else
has to be tossed to make room. One of these days it will be my own
name that gets thrown out to make room for the names of seven new
databases to be created . . .
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-24-2008, 08:10 AM
Holger Baer
 
Posts: n/a
Default Re: script problem solved, but I still don't understand ....

Ed Stevens wrote:
> sqlplus "/ as sysdba" @mysqlscript
>
>
> and the output looked like this. Note the successfull 'connected'
> just before the DELETE statement.
>
> SQL*Plus: Release 9.2.0.1.0 - Production on Wed Oct 13 14:42:00 2004
>
> Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
>
> Connected.
> SQL> DELETE FROM mytable
> 2 WHERE sample_time < sysdate - &1
> 3 ;
> old 2: WHERE sample_time < sysdate - &1
> new 2: WHERE sample_time < sysdate - 15
> DELETE FROM mytable
> *
> ERROR at line 1:
> ORA-01034: ORACLE not available
>
>
> I'm sure this is something I should know. Maybe I do know it, but am
> just having a DSA (Dumb S*** Attack (tm)) I think my memory is maxed
> out, and everytime I have to remember something new, something else
> has to be tossed to make room. One of these days it will be my own
> name that gets thrown out to make room for the names of seven new
> databases to be created . . .


Personally I'd expect an 'Connected to an idle instance'. Try what you get
if you do

export ORACLE_SID=foo
sqlplus "/ as sysdba"

since I don't have a Solaris at hand I can't check the outcome. But it should
get you on the right track anyway.

HTH

Holger
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-24-2008, 08:10 AM
Steve
 
Posts: n/a
Default Re: script problem solved, but I still don't understand ....

Holger Baer wrote:
> Ed Stevens wrote:
>
>> sqlplus "/ as sysdba" @mysqlscript
>>
>>
>> and the output looked like this. Note the successfull 'connected'
>> just before the DELETE statement.
>>
>> SQL*Plus: Release 9.2.0.1.0 - Production on Wed Oct 13 14:42:00 2004
>>
>> Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
>>
>> Connected.
>> SQL> DELETE FROM mytable
>> 2 WHERE sample_time < sysdate - &1
>> 3 ;
>> old 2: WHERE sample_time < sysdate - &1
>> new 2: WHERE sample_time < sysdate - 15
>> DELETE FROM mytable
>> *
>> ERROR at line 1:
>> ORA-01034: ORACLE not available
>>
>>
>> I'm sure this is something I should know. Maybe I do know it, but am
>> just having a DSA (Dumb S*** Attack (tm)) I think my memory is maxed
>> out, and everytime I have to remember something new, something else
>> has to be tossed to make room. One of these days it will be my own
>> name that gets thrown out to make room for the names of seven new
>> databases to be created . . .

>
>
> Personally I'd expect an 'Connected to an idle instance'. Try what you get
> if you do
>
> export ORACLE_SID=foo
> sqlplus "/ as sysdba"
>
> since I don't have a Solaris at hand I can't check the outcome. But it
> should
> get you on the right track anyway.
>
> HTH
>
> Holger


ORACLE_SID=foo sqlplus "/ as sysdba" @mysqlscript would be better... is
&1 defined?

Steve
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-24-2008, 08:10 AM
Holger Baer
 
Posts: n/a
Default Re: script problem solved, but I still don't understand ....

Steve wrote:
>>
>> Personally I'd expect an 'Connected to an idle instance'. Try what you
>> get
>> if you do
>>
>> export ORACLE_SID=foo
>> sqlplus "/ as sysdba"
>>
>> since I don't have a Solaris at hand I can't check the outcome. But it
>> should
>> get you on the right track anyway.
>>
>> HTH
>>
>> Holger

>
>
> ORACLE_SID=foo sqlplus "/ as sysdba" @mysqlscript would be better... is
> &1 defined?
>
> Steve


You've lost me there. Why would that be better to demonstrate the fact that
you can get a connected (to an idle instance) when using any arbitrary ORACLE_SID?
The point is that you'll get on any subsequent command (other than startup) the
not connected error.

Cheers
Holger
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-24-2008, 08:10 AM
Ed Stevens
 
Posts: n/a
Default Re: script problem solved, but I still don't understand ....

On Thu, 14 Oct 2004 08:38:43 +0200, Holger Baer
<holger.baer@science-computing.de> wrote:

>Ed Stevens wrote:
>> sqlplus "/ as sysdba" @mysqlscript
>>
>>
>> and the output looked like this. Note the successfull 'connected'
>> just before the DELETE statement.
>>
>> SQL*Plus: Release 9.2.0.1.0 - Production on Wed Oct 13 14:42:00 2004
>>
>> Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
>>
>> Connected.
>> SQL> DELETE FROM mytable
>> 2 WHERE sample_time < sysdate - &1
>> 3 ;
>> old 2: WHERE sample_time < sysdate - &1
>> new 2: WHERE sample_time < sysdate - 15
>> DELETE FROM mytable
>> *
>> ERROR at line 1:
>> ORA-01034: ORACLE not available
>>
>>
>> I'm sure this is something I should know. Maybe I do know it, but am
>> just having a DSA (Dumb S*** Attack (tm)) I think my memory is maxed
>> out, and everytime I have to remember something new, something else
>> has to be tossed to make room. One of these days it will be my own
>> name that gets thrown out to make room for the names of seven new
>> databases to be created . . .

>
>Personally I'd expect an 'Connected to an idle instance'. Try what you get
>if you do
>
>export ORACLE_SID=foo
>sqlplus "/ as sysdba"
>
>since I don't have a Solaris at hand I can't check the outcome. But it should
>get you on the right track anyway.
>
>HTH
>
>Holger


If it had given 'Connected to an idle instance' it would all make
perfect sense. But as you can see from the original post, it clearly
said 'Connected'. Here's what trying to connect to a null
ORACLE_SID gives at the command line, followed by an attempt with a
bogus value. Both gave expected results. This was just from a
command prompt, not within a script and certainly not in a script
executed by cron.

oracle@ncensn130: echo $ORACLE_SID
VITXD01
oracle@ncensn130: ORACLE_SID=
oracle@ncensn130: echo $ORACLE_SID

oracle@ncensn130: sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.1.0 - Production on Thu Oct 14 06:26:54 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

ERROR:
ORA-12162: TNS:service name is incorrectly specified


Enter user-name: ^C
oracle@ncensn130: ORACLE_SID=FOO
oracle@ncensn130: echo $ORACLE_SID
FOO
oracle@ncensn130: sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.1.0 - Production on Thu Oct 14 06:27:31 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to an idle instance.

SQL> exit
Disconnected
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-24-2008, 08:10 AM
John Hurley
 
Posts: n/a
Default Re: script problem solved, but I still don't understand ....

snip

> I finally realized that even though I was setting ORACLE_SID in the
> shell script, I wasn't exporting it so that SQLPlus could see it.
> After adding 'export ORACLE_SID' to the shell script it ran like a
> champ.


Everyone it seems approaches shell scripts (batch jobs one could say)
that use oracle utilities a little differently.

My approach is to always dot in some kind of small file that sets (and
exports) all of the oracle environment that you need to have
established as the first step.

#!/bin/ksh
#
# doc notes as needed
#
.. /u01/app/oracle/local/bin/.9ioraenv

The .9ioraenv file could check what host you are on, what oracle homes
are available, what sids, ... etc ... then set the environment as
needed (whatever you require). This type of approach might be useful
to your environment.

John
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-24-2008, 08:11 AM
Ed Stevens
 
Posts: n/a
Default Re: script problem solved, but I still don't understand ....

On 14 Oct 2004 05:34:26 -0700, johnbhurley@sbcglobal.net (John Hurley)
wrote:

>snip
>
>> I finally realized that even though I was setting ORACLE_SID in the
>> shell script, I wasn't exporting it so that SQLPlus could see it.
>> After adding 'export ORACLE_SID' to the shell script it ran like a
>> champ.

>
>Everyone it seems approaches shell scripts (batch jobs one could say)
>that use oracle utilities a little differently.
>
>My approach is to always dot in some kind of small file that sets (and
>exports) all of the oracle environment that you need to have
>established as the first step.
>
>#!/bin/ksh
>#
># doc notes as needed
>#
>. /u01/app/oracle/local/bin/.9ioraenv
>
>The .9ioraenv file could check what host you are on, what oracle homes
>are available, what sids, ... etc ... then set the environment as
>needed (whatever you require). This type of approach might be useful
>to your environment.
>
>John


I do that as well, and did it in this particular instance. The one
'gotcha' is ORACLE_SID on a box with multiple SIDs. That leaves the
following possibilities:

1) A separate 'environment' file specific to each sid. Calling
scripts have to know which sid-specific environment file to call.

2) (my approach) A single generic 'environment' file that leaves the
setting of ORACLE_SID to the calling script. Or sets it on behalf of
the calling script, but would have to have the calling script supply
the value as a command line parm.

Either way, the main script will have to be the one to know and
specify sid-specific info. It was simply my failure to export it that
caused the problem.

And still leaves me with the fundamental question of how I was able to
get a good connect -- *not* a 'connected to an idle instance' -- then
have the first DML statement result in a ORA-01034: ORACLE not
available.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-24-2008, 08:11 AM
Joel Garry
 
Posts: n/a
Default Re: script problem solved, but I still don't understand ....

Ed Stevens <nospam@noway.nohow> wrote in message news:<dr5tm0p1v8gf3nt2iarmfege20dt06iepm@4ax.com>. ..
>
> And still leaves me with the fundamental question of how I was able to
> get a good connect -- *not* a 'connected to an idle instance' -- then
> have the first DML statement result in a ORA-01034: ORACLE not
> available.


I'm frustrated as heck right now because I've done this same thing and
can't remember the answer.

But it might be something like being logged on as root rather than the
oracle user, so you can connect, because that just means running
sqlplus, but when you try to actually do anything you get the 1034
because the shared memory area is owned by oracle:dba (or whatever)
and root is explicitly enjoined from doing certain things in Oracle,
even if it is in the dba group.

I also have a vague memory of something like this when I forgot the -
in the su - oracle, where the oracle .profile had the proper
environment call and the sysadmin had tried to run oracle things as
root, so the environment was partly set up under cron.

jg
--
@home.com is bogus.
http://www.oreillynet.com/pub/a/netw.../phishing.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-24-2008, 08:12 AM
Holger Baer
 
Posts: n/a
Default Re: script problem solved, but I still don't understand ....

Ed Stevens wrote:
[..]
>
>
> If it had given 'Connected to an idle instance' it would all make
> perfect sense. But as you can see from the original post, it clearly
> said 'Connected'. Here's what trying to connect to a null
> ORACLE_SID gives at the command line, followed by an attempt with a
> bogus value. Both gave expected results. This was just from a
> command prompt, not within a script and certainly not in a script
> executed by cron.
>

[..]

Ok, my point was, that if you're really connected to an instance,
sqlplus is in the habit of telling you which instance it's connected
to. And as an absolut shot in the dark I thought maybe that's just
the solaris sqlplus maybe in conjunction with the fact that it was
run from a script.

Sometimes I get those fantasies ;-)

Holger
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-24-2008, 08:12 AM
Holger Baer
 
Posts: n/a
Default Re: script problem solved, but I still don't understand ....

Holger Baer wrote:
> Ed Stevens wrote:
> [..]
>
>>
>>
>> If it had given 'Connected to an idle instance' it would all make
>> perfect sense. But as you can see from the original post, it clearly
>> said 'Connected'. Here's what trying to connect to a null
>> ORACLE_SID gives at the command line, followed by an attempt with a
>> bogus value. Both gave expected results. This was just from a
>> command prompt, not within a script and certainly not in a script
>> executed by cron.
>>

> [..]
>
> Ok, my point was, that if you're really connected to an instance,
> sqlplus is in the habit of telling you which instance it's connected
> to. And as an absolut shot in the dark I thought maybe that's just
> the solaris sqlplus maybe in conjunction with the fact that it was
> run from a script.
>
> Sometimes I get those fantasies ;-)
>
> Holger


I just shouldn't write before my second cup. ;-)

I intended to say, that if sqlplus does not give an
'connected to: ... ' then it's not connected to a running instance.

Cheers
Holger
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:26 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540