Oh the tension. 2-0 up at half-time. Visions of last-day drama and an eleventh-hour escape floating tantilisingly before my eyes. Then, grim reality. A second-half collapse and the prize is snatched away once more. So, this is what it must be like to be an Arsenal fan.
I know that they say misery loves company, but it’s not really any consolation. Yes, my beloved West Ham have been relegated from the Premiership.
In an effort to rouse myself from the resultant depression, I decided to have a look at addressing one of those minor annoyances that I’m always intending to get around to but somehow never quite do. In this case, it’s how to get confirmation that my Oracle XE database has started before trying to connect to it ( and that it’s shut down before I turn off my computer).
It’s probably useful at this point to have a quick overview of the setup.
I’m running Oracle 10g XE on an Ubuntu 10.04 desktop.
I’m using the menu items in Applications/Oracle Database 10g Express Edition to start and stop the database. The database was installed and configured using these instructions.
Of course, being a traditionalist, I can tell when the database is up by simply tailing the database’s alert.log file and waiting to see that it’s open…
tail -f /usr/lib/oracle/xe/app/oracle/admin/XE/bdump/alert_XE.log
The problem with this is that the startup script doesn’t just start the database. It starts the TNS listener as well. It’s not until both are up an running that you can connect via TNS.
Even then, you still have to wait whilst the listener appears to have a moment of existential crisis – “why am I here ? What is my purpose?” before it remembers that it’s supposed to be routing connections to your database.
In the interim, if you try to connect to your database, you will be rebuffed with the ever helpful
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
Why does this happen ? You try again a few seconds later and everything works fine. Fortunately, your listener is not in need of therapy…
What No Listener ?
So exactly how does the listener know when your database is available ?
Essentially, when the database starts up, it kicks off a number of processes. One of these – PMON – has a look around for a TNS Listener and if it finds one running, registers the database with it.
If no Listener is running, then PMON will poll every so often until it finds one.
There’s a full explanation of the ins and outs of this process in the Oracle Database 10g Release 2 documentation.
Is this what’s happening with XE ? Well, let’s do a test.
We’re going to check the listener’s log file to see when it can start handling connections after a startup.
So, in Terminal…
cd $ORACLE_HOME/network/log tail -f listener.log
On the desktop, now run the Start Database Menu Item.
In my case, the output from the listener.log looks something like this :
TNSLSNR for Linux: Version 10.2.0.1.0 - Production on 17-MAY-2011 09:22:53 Copyright (c) 1991, 2005, Oracle. All rights reserved. System parameter file is /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/network/admin/listener.ora Log messages written to /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/network/log/listener.log Trace information written to /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/network/trace/listener.trc Trace level is currently 0 Started with pid=1906 Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=mikes-laptop)(PORT=1521))) Listener completed notification to CRS on start TIMESTAMP * CONNECT DATA [* PROTOCOL INFO] * EVENT [* SID] * RETURN CODE 17-MAY-2011 09:22:53 * (CONNECT_DATA=(CID=(PROGRAM=)(HOST=mikes-laptop)(USER=mikes))(COMMAND=status)(ARGUMENTS=64)(SERVICE=LISTENER)(VERSION=169869568)) * status * 0 Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=8081))(Presentation=HTTP)(Session=RAW)) 17-MAY-2011 09:23:40 * service_register * XE * 0
So, the listener does not register the database until 47 seconds after startup. Hmmm, maybe we should have a look at the startup script that Oracle supply with XE.
The scripts behind the Start Database and Stop Database menu items can be found in /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/config/scripts. The startup script is called startdb.sh. Incidentally, the shutdown script is called stopdb.sh.
The main portion of startdb.sh is quite interesting…
# Starting Oracle Database 10g Express Edition instance and Listener $SQLPLUS -s /nolog @$ORACLE_HOME/config/scripts/startdb.sql > /dev/null 2>&1 if [ ! `ps -ef | grep tns | cut -f1 -d" " | grep -q oracle` ] then $LSNR start > /dev/null 2>&1 else echo "" fi
Yep, it starts the database before it starts the listener. So reversing the order – i.e. starting the listener first – should resolve our problem.
There’s more though. We don’t really want to have to start a terminal session and tail the alert.log if we can just get the script to tell us, via the Gnome desktop, that everything is up and running.
What we’d like to do is to get these scripts to display a desktop notification once they have completed.
Now, I recently came across a handy little utility to do this.
The libnotify package
Once more into the Terminal, dear friends…
sudo apt-get install libnotify-bin
Once we’ve got this package we can do stuff like this in a shell script to get a pop-up message on the desktop
#!/bin/sh iconPath='/usr/share/icons/gnome/32x32/status' icon='weather-storm.png' notify-send -t 500 -i "$iconPath/$icon" 'Mad Science Weather' 'Igor, ready the lightning rod !' exit 0
The switches that I’m using for notify send are -t ( timeout in milliseconds) and -i (display this icon). The next string in the command – “Mad Science Weather” – is the heading and the last string is the message you want to display.
This being a shell script, we can of course substitute the literal strings for the header and message with variables.
When you run this, you should get a notification, complete with the icon, showing up in the top right-hand corner of your desktop.
Now all we need to do is to amend the database scripts to pop-up the appropriate notification.
Of course, it’s always a good idea to back up your scripts before making any changes, just in case…
cd /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/config/scripts sudo cp startdb.sh startdb.bak sudo cp stopdb.sh stopdb.bak
We now need to change the scripts to look something like this ( startdb.sh first) :
#!/bin/bash
#
# svaggu 09/28/05 - Creation
# svaggu 11/09/05 - dba groupd check is added
#
xsetroot -cursor_name watch
case $PATH in
"") PATH=/bin:/usr/bin:/sbin:/etc
export PATH ;;
esac
SAVE_LLP=$LD_LIBRARY_PATH
ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
ORACLE_SID=XE
LSNR=$ORACLE_HOME/bin/lsnrctl
SQLPLUS=$ORACLE_HOME/bin/sqlplus
export ORACLE_HOME
export ORACLE_SID
#
# Variables for the desktop notification
#
iconPath='/usr/share/icons/gnome/32x32/status/'
infoIcon='info.png'
errIcon='error.png'
icon=$infoIcon
msg='Oracle Database and TNS Listener now running'
LOG="$ORACLE_HOME_LISTNER/listener.log"
user=`/usr/bin/whoami`
group=`/usr/bin/groups $user | grep dba`
if test -z "$group"
then
xterm -T "Warning" -n "Warning" -hold -e "echo Operation failed. $user is not a member of \'dba\' group."
# Added message setting here for the notify change - Mike 15/5/11
msg="Database not started. $user is not a member of \'dba\' group."
icon=$errIcon
else
# Starting Oracle Database 10g Express Edition instance and Listener
# NOTE - swapping the order to start the listener BEFORE the db - Mike
if [ ! `ps -ef | grep tns | cut -f1 -d" " | grep -q oracle` ]
then
$LSNR start > /dev/null 2>&1
else
echo ""
fi
$SQLPLUS -s /nolog @$ORACLE_HOME/config/scripts/startdb.sql > /dev/null 2>&1
fi
xsetroot -cursor_name left_ptr
#
# Added desktop notification to advise when the database has started
# Mike
#
notify-send -t 1000 -i "$iconPath/$icon" 'Oracle XE' "$msg"
The changes to the stopdb.sh script are fairly similar :
#!/bin/bash
#
# svaggu 09/28/05 - Creation
# svaggu 11/09/05 - dba groupd check is added
#
xsetroot -cursor_name watch
case $PATH in
"") PATH=/bin:/usr/bin:/sbin:/etc
export PATH ;;
esac
SAVE_LLP=$LD_LIBRARY_PATH
ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
ORACLE_SID=XE
SQLPLUS=$ORACLE_HOME/bin/sqlplus
export ORACLE_HOME
export ORACLE_SID
#
# Variables for the desktop notification - Mike
#
iconPath='/usr/share/icons/gnome/32x32/status/'
infoIcon='info.png'
errIcon='error.png'
icon=$infoIcon
msg='Database shutdown complete'
user=`/usr/bin/whoami`
group=`/usr/bin/groups $user | grep dba`
if test -z "$group"
then
xterm -T "Warning" -n "Warning" -hold -e "echo Operation failed. $user is not a member of \'dba\' group."
# Added message setting here for the notify change - Mike
msg="Operation failed. $user is not a member of \'dba\' group."
icon=$errIcon
else
# Stop Oracle Database 10g Express Edition instance
$SQLPLUS -s /nolog @$ORACLE_HOME/config/scripts/stopdb.sql > /dev/null 2>&1
fi
xsetroot -cursor_name left_ptr
notify-send -t 1000 -i "$iconPath/$icon" 'Oracle XE' "$msg"
A point of interest here – the stop script only does a shutdown of the database, it doesn’t stop the listener. Of course, this being XE, the listener is probably going to be used solely for the single XE instance. Anyway, if you do want to stop the listener when the stop script runs, you simply need to add the following line (preferably after the database shutdown command) :
$ORACLE_HOME/bin/lsnrctl stop
Now we just have to wait for the notification to know that everything is up and running and we can connect with impunity ( or at least, free from the tyranny of ORA-12514)…
Thankfully, the football season is nearly over. All that’s left for me now is to help Simon through the ordeal of Luton’s Play-Off final against the mighty AFC Wimbledon on Saturday.


Thanks! Easily added this on Linux Mint to the slightly different 11g scripts. Works like a charm. My scripts were in a different location, however, namely:
/u01/app/oracle/product/11.2.0/xe/config/scripts/
David,
good point. When I originally wrote this, I was running on XE 10g. 11g does indeed have a different home directory, just to keep everyone on their toes !
Mike
Thanks for your personal marvelous posting! I actually enjoyed reading it,
you happen to be a great author.I will always bookmark your blog
and definitely will come back from now on. I want to encourage
that you continue your great writing, have a
nice afternoon!
I absolutely love your blog and find the majority of your post’s to be just what I’m looking for.
Would you offer guest writers to write content to suit your
needs? I wouldn’t mind creating a post or elaborating on a few of the subjects you write about here. Again, awesome weblog!
My partner and I stumbled over here different web address and thought I may as well check things out. I like what I see so now i’m following you.
Look forward to looking at your web page again.
I like what you guys are up too. This kind of clever work and coverage!
Keep up the amazing works guys I’ve added you guys to blogroll.
Hi I am so grateful I found your blog page, I really found you by mistake, while I was looking on Aol for something else, Anyways I am here now and would just like to say kudos for a marvelous post and a all round exciting blog (I also love the theme/design), I don’t have time to read it all at the minute but I have book-marked it and also added in your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the superb job.
Appreciating the commitment you put into your site and detailed information you provide. It’s nice to come across a blog every once in a while that
isn’t the same out of date rehashed material. Excellent read! I’ve bookmarked
your site and I’m including your RSS feeds to my Google account.
Hello! I’ve been reading your blog for a while now and finally got the bravery to go ahead and give you a
shout out from Dallas Tx! Just wanted to tell you
keep up the excellent job!
I am really enjoying the theme/design of your web site.
Do you ever run into any internet browser compatibility issues?
A number of my blog visitors have complained about my
site not operating correctly in Explorer
but looks great in Opera. Do you have any tips to help fix
this issue?
I am curious to find out what blog system you’re working with? I’m experiencing some minor security issues with
my latest website and I would like to find something more
risk-free. Do you have any suggestions?
Hmm it looks like your website ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your
blog. I too am an aspiring blog blogger but I’m still new to the whole thing. Do you have any helpful hints for novice blog writers? I’d genuinely appreciate it.
Woah! I’m really enjoying the template/theme of this website. It’s simple,
yet effective. A lot of times it’s hard to get that “perfect balance” between user friendliness and visual appearance. I must say you’ve done a awesome job with this.
Additionally, the blog loads super fast for me
on Opera. Excellent Blog!
Do you mind if I quote a few of your posts as long as
I provide credit and sources back to your webpage?
My blog site is in the exact same area of interest as
yours and my users would really benefit from a lot of the information you present here.
Please let me know if this ok with you. Appreciate it!
Hello would you mind letting me know which web host you’re utilizing? I’ve
loaded your blog in 3 different internet browsers and I must say this blog loads a lot
quicker then most. Can you recommend a good hosting provider at a honest price?
Thank you, I appreciate it!
Wonderful website you have here but I was wondering if you knew of any discussion boards that cover the same topics discussed in this article?
I’d really like to be a part of online community where I can get advice from other knowledgeable individuals that share the same interest. If you have any recommendations, please let me know. Bless you!
Howdy! This is my 1st comment here so I just wanted to give a quick shout out and say I truly enjoy reading through your articles. Can you suggest any other blogs/websites/forums that deal with the same subjects? Thanks for your time!
Do you have a spam problem on this blog; I also am a blogger, and I was curious about your situation; we have developed some nice methods and we are looking to trade techniques with others, please shoot me an e-mail if interested.
Please let me know if you’re looking for a article author for
your weblog. You have some really great articles and I believe I would be a good asset.
If you ever want to take some of the load off, I’d really like to write some articles for your blog in exchange for a link back to mine. Please blast me an e-mail if interested. Cheers!
Have you ever thought about adding a little bit more than just your articles? I mean, what you say is important and all. Nevertheless think of if you added some great photos or video clips to give your posts more, “pop”! Your content is excellent but with pics and clips, this site could definitely be one of the most beneficial in its field. Great blog!
Fascinating blog! Is your theme custom made or did you download it from somewhere? A theme like yours with a few simple adjustements would really make my blog stand out. Please let me know where you got your design. Thank you
Hey would you mind sharing which blog platform you’re using?
I’m planning to start my own blog in the near future but I’m having a
difficult time selecting between BlogEngine/Wordpress/B2evolution and Drupal.
The reason I ask is because your layout seems different then most blogs and I’m looking for something unique. P.S Apologies for being off-topic but I had to ask!
Hi there just wanted to give you a quick heads up. The text in your article seem to be running off the screen in Safari. I’m not sure if this
is a format issue or something to do with internet browser compatibility but I figured
I’d post to let you know. The design look great though! Hope you get the issue solved soon. Kudos
With havin so much content do you ever run into any issues of plagorism or copyright violation? My blog has a lot of unique content I’ve either written myself
or outsourced but it looks like a lot of it is popping it up all over the web without my agreement.
Do you know any methods to help stop content from being stolen?
I’d really appreciate it.
Have you ever considered publishing an ebook or guest authoring on other blogs? I have a blog based upon on the same information you discuss and would really like to have you share some stories/information. I know my readers would value your work. If you are even remotely interested, feel free to shoot me an e-mail.
Hey! Someone in my Facebook group shared this website with us so I came to give it a look. I’m definitely enjoying the information.
I’m bookmarking and will be tweeting this to my followers! Exceptional blog and brilliant design.
Superb blog! Do you have any helpful hints for aspiring writers? I’m planning to start my
own blog soon but I’m a little lost on everything. Would you advise starting with a free platform like WordPress or go for a paid option? There are so many choices out there that I’m totally confused .
. Any ideas? Thanks!
My programmer is trying to convince me to move
to .net from PHP. I have always disliked the idea because of the costs.
But he’s tryiong none the less. I’ve been using
WordPress on numerous websites for about a year and am
concerned about switching to another platform. I have heard
excellent things about blogengine.net. Is there a way
I can transfer all my wordpress posts into it? Any kind of help would be really appreciated!
Does your blog have a contact page? I’m having a tough time locating it but, I’d
like to shoot you an e-mail. I’ve got some creative ideas for your blog you might be interested in hearing. Either way, great blog and I look forward to seeing it improve over time.
It’s a shame you don’t have a donate button! I’d without a doubt donate to this brilliant
blog! I guess for now i’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to new updates and will talk about this site with my Facebook group. Talk soon!
Greetings from California! I’m bored at work so I decided to browse your blog on my iphone
during lunch break. I enjoy the information you provide here and can’t wait to take a look when I get home. I’m amazed at how quick your blog
loaded on my phone .. I’m not even using WIFI, just 3G .. Anyways, fantastic blog!
Howdy! I know this is kinda off topic however I’d figured I’d ask. Would you be interested in trading links or maybe guest writing a blog post or vice-versa? My blog discusses a lot of the same topics as yours and I think we could greatly benefit from each other. If you happen to be interested feel free to shoot me an email. I look forward to hearing from you! Awesome blog by the way!
Currently it looks like Drupal is the best blogging platform out there right now. (from what I’ve read) Is
that what you are using on your blog?
Wonderful post however I was wondering if you
could write a litte more on this subject? I’d be very thankful if you could elaborate a little bit further. Kudos!
Howdy! I know this is kinda off topic but I was wondering if you knew where I could find a captcha plugin for my comment form? I’m
using the same blog platform as yours and I’m having problems finding one? Thanks a lot!
When I initially commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get three e-mails with the same comment. Is there any way you can remove people from that service? Many thanks!
Hello there! This is my first visit to your blog! We are a team of volunteers and starting a new project in a community in the same niche. Your blog provided us beneficial information to work on. You have done a outstanding job!
Howdy! I know this is somewhat off topic but I was wondering which blog platform are you using for this website? I’m getting tired of WordPress because I’ve had issues with hackers and I’m looking at options for another
platform. I would be great if you could point me in
the direction of a good platform.
Hello! This post couldn’t be written any better! Reading this post reminds me of my previous room mate! He always kept chatting about this. I will forward this article to him. Pretty sure he will have a good read. Thank you for sharing!
Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You clearly know what youre talking about, why throw away your intelligence on just posting videos to your weblog when you could be giving us something informative to read?
Today, I went to the beach front with my kids. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is entirely off topic but I had to tell someone!
Yesterday, while I was at work, my sister stole my iphone and tested to see if it can survive a thirty foot drop, just so she can be a youtube sensation. My apple ipad is now broken and she has 83 views. I know this is completely off topic but I had to share it with someone!
I was wondering if you ever thought of changing the page layout of your site? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or 2 images. Maybe you could space it out better?
Hi there, i read your blog from time to time and i own a similar one and i was just curious if you get a lot of spam responses? If so how do you stop it, any plugin or anything you can suggest? I get so much lately it’s driving
me crazy so any support is very much appreciated.
This design is steller! You certainly know
how to keep a reader amused. Between your wit and your videos, I was almost moved to start
my own blog (well, almost…HaHa!) Great job. I really enjoyed
what you had to say, and more than that, how you presented it.
Too cool!
I’m really enjoying the design and layout of your website. It’s
a very easy on the eyes which makes it much more pleasant for me to come here and visit more often.
Did you hire out a developer to create your theme?
Excellent work!
Hey there! I could have sworn I’ve been to this website before but after browsing through some of the post I realized it’s new to me.
Anyhow, I’m definitely delighted I found it and I’ll be
book-marking and checking back frequently!
Hello! Would you mind if I share your blog with my zynga group?
There’s a lot of folks that I think would really enjoy your content. Please let me know. Many thanks
Hello, I think your blog might be having browser compatibility issues. When I look at your blog site in Ie, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, terrific blog!
Sweet blog! I found it while surfing around on Yahoo News. Do you have any tips on how to get listed in Yahoo News? I’ve been trying for a while
but I never seem to get there! Many thanks
Hello! This is kind of off topic but I need some guidance from an established blog.
Is it difficult to set up your own blog?
I’m not very techincal but I can figure things out pretty quick. I’m thinking about making my own but I’m not sure where to start. Do you have any tips or suggestions? With thanks
Hi! Quick question that’s entirely off topic.
Do you know how to make your site mobile friendly?
My weblog looks weird when viewing from my iphone. I’m trying to find a theme or plugin that might be able to correct this problem. If you have any recommendations, please share. Thank you!
I’m not that much of a internet reader to be honest but your blogs really nice, keep it up! I’ll go ahead
and bookmark your site to come back later. Cheers
I really like your blog.. very nice colors & theme. Did you design this website yourself or did you hire someone to do it for you?
Plz reply as I’m looking to design my own blog and would like to find out where u got this from. appreciate it
Wow! This blog looks just like my old one! It’s on a completely different topic but
it has pretty much the same layout and design.
Superb choice of colors!
Hello just wanted to give you a brief heads
up and let you know a few of the images aren’t loading correctly. I’m not sure why but I think its a linking
issue. I’ve tried it in two different browsers and both show the same outcome.
Hi are using WordPress for your site platform? I’m new to the blog world but I’m trying to get started and set up my own. Do you need any coding expertise to make your own blog? Any help would be really appreciated!
Whats up this is kinda of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding expertise so I wanted to get guidance from someone
with experience. Any help would be enormously appreciated!
Heya! I just wanted to ask if you ever have any issues with hackers?
My last blog (wordpress) was hacked and I ended up losing
several weeks of hard work due to no backup. Do you have any methods to prevent hackers?
Hi there! Do you use Twitter? I’d like to follow you if that would be okay. I’m undoubtedly
enjoying your blog and look forward to new posts.
Hi there! Do you know if they make any plugins to protect
against hackers? I’m kinda paranoid about losing everything I’ve worked
hard on. Any recommendations?
Hello there! Do you know if they make any plugins to assist with SEO?
I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good gains.
If you know of any please share. Thank you!
I know this if off topic but I’m looking into starting my own blog and was curious what all is required to get set up? I’m assuming having a blog like yours would cost a pretty penny?
I’m not very internet smart so I’m not 100% sure.
Any suggestions or advice would be greatly appreciated. Appreciate it
Hmm is anyone else experiencing problems with the images on
this blog loading? I’m trying to find out if its a problem on my end or if it’s
the blog. Any responses would be greatly appreciated.
I’m not sure why but this site is loading incredibly slow for me. Is anyone else having this problem or is it a problem on my end? I’ll
check back later and see if the problem still exists.
Hi there! I’m at work browsing your blog from my new iphone 4! Just wanted to say I love reading your blog and look forward to all your posts! Keep up the outstanding work!
Wow that was strange. I just wrote an extremely long comment but after I clicked submit my comment didn’t show
up. Grrrr… well I’m not writing all that over again. Regardless, just wanted to say wonderful blog!