About Me

My photo
Working as Technical Lead in CollabNET software private limited.

Friday, 20 March 2009

Enable pgsql logging

Some days back I came to situation to find when the table rows are inserted and deleted by an unknown thread!.

Got an idea from one of my colleague and enabled the pgsql logging. It worked great :)

To enable logging

# Edit the pgsql configuration file
/var/lib/pgsql/data/postgresql.conf

# Under section # ERROR REPORTING AND LOGGING
# Edit the logging options and set your preferrence!.


...
log_directory = 'pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_line_prefix = '%u %h %t'
log_statement = 'all'
log_hostname = on
...


# Go to pgsql logging dir and tail for the logfile.
cd /var/lib/pgsql/data/pg_log/

Thursday, 26 February 2009

Recursive shell command s

I was searching for macking the commands work recursively.

Below is the way to do it.

MIGRATION_CONFIG_FILE="$(dirname $(dirname $(readlink $0)))"/$CONFIGURATION_FILE.

Monday, 16 February 2009

Splitting a patch file

Some times the patch file needs to be splitted to individual files for easy handling.

Below is the command to do that, cut the patch file matching pattern "Index:".

csplit artf21810.diff /Index:/ {*}

Friday, 13 February 2009

Script to delete folder in a loop

#!/bin/sh
i=0
while [ $i -le 40 ]
do
folder="psr-pub-$i"
#chown apache:apache $folder -R
rm -rf $folder
i=`expr $i + 1`
done

Shell script to connect postgress in a loop

i=211
while [ $i -le 250 ]
do
folder="psr-pub-$i"
echo "Starting processing $folder."
./svnmapping.sh $folder
echo "Done with $folder"
i=`expr $i + 1`
done


projectName=$1
userId="user1308"

DBConnect="psql -d psrdb -U psruser --tuples-only --single-line"

date=`date +"%F %T"`
projId=`echo "select id from project where path='projects.$projectName'" | $DBConnect`
projId=`echo $projId`

parent_folder_id=`echo "select id as parent_folderid from folder where path = 'scm' and project_id='$projId'" | $DBConnect`
parent_folder_id=`echo $parent_folder_id`

nextscm_id_query="select max(substring(id from (char_length('reps')+1))) from scm_repository"
primaryId_query="select id from objecttype where application='Scm' and name='Repository'"
secondaryId_query="select id from objecttype where application='Scm' and name='Commit'"

nextscm_id=`echo $nextscm_id_query | $DBConnect`
nextscmId=`echo $nextscm_id`
nextscmId=reps`expr $nextscmId + 1`
primaryId=`echo $primaryId_query | $DBConnect`
primaryId=`echo $primaryId`
secondaryId=`echo $secondaryId_query | $DBConnect`
secondaryId=`echo $secondaryId`

insertscm="insert into scm_repository values('$nextscmId', 'exsy1002', '/svnroot/$projectName', 'f')"
insertfolder="insert into folder values ('$nextscmId', 'scm.$projectName', '$projectName', '$projectName', '100', '$date+05:30', '$date+05:30','f', '$primaryId', '$secondaryId', '$userId', '$userId', '$parent_folder_id', '$projId', '0')"

scm=`echo $insertscm | $DBConnect`
fol=`echo $insertfolder | $DBConnect`

echo $scm" "$fol