Friday, November 18, 2016

How to kill a process on a port on ubuntu

Sometimes, when we strying to up an service and get message like: the port *** is used by another service. And we are notable to start our app to use that port. In that case, we are in need to free the port by stopping the running process. For this purpose a first we need to find out the process which is using that port.

By using the below query we can get the process id using this port:

sudo lsof -t -i:8080 [For this case 8080 is our reference port number]

to get the process in details, we can use:
ps -ef | grep


And then we can kill the process by :
kill -9

We can use the below command at once to kill the process:
sudo kill $(sudo lsof -t -i:8080)

Thursday, November 17, 2016

Sheel Script for Deleting files older than some days

find is the common tool for this kind of task :

find ./target_dir ! -name 'stayhere.txt' -mtime +5 -type f -delete


EXPLANATIONS

./target_dir your directory (replace with your own)
! -name File to exclude
-mtime +5 older than 5 days
-type f only files
-delete no surprise. Remove it to test your find filter before executing the whole command
And take care that ./target_dir exists to avoid bad surprises !

Tuesday, November 15, 2016

TODO in Ecplise IDE

in Eclipse, no TODO shortcut found; but a possible solution is to create a template so when you write some string and hit Ctrl + spacebar and Enter your TODO code will be entered.
Window -> Preferences -> Java -> Editor -> Templates -> New
  • Set the Name of the template (e.g. todo)
  • Set the Pattern (e.g. //TODO)
When you type todo and press Ctrl + spacebar and Enter // TODO will be inserted
Such a trivial todo is useless but you can tweak it by using variables as shown in the picture. Use "Insert Variable" button to insert variables.
enter image description here
When you use the pattern shown in the picture following will be inserted:
// TODO inserted by UserName [21. 1. 2015, 13:07:07]

Monday, August 15, 2016

Oracle Database Architectural Quick Reference


how to determine an index need to be rebuild

Is an index required to be rebuilt? We can check a post regarding this:

Richard Foote's Oracle Blog

Indexes will occupy a lot of space, so you can check whether it was being used. For this you can check out for v$object_usage. If needed you can also enable Monitoring usage of indexes by using 

Alter index enable Monitoring Usage ; 

If there is Fragmentation of Index then it needs to be rebuilt. Refer the above link mentioned in this discussion which is a very useful one.

We can check if an index needs to be rebuilt by executing the following statements:


ANALYZE INDEX index_name VALIDATE STRUCTURE;

SELECT HEIGHT, DEL_LF_ROWS, LF_ROWS, LF_BLKS FROM INDEX_STATS;

If the value for DEL_LF_ROWS/LF_ROWS is greater than 2, or LF_ROWS is lower than LF_BLKS, or HEIGHT is 4 then the index should be rebuilt.