Category: mac


PostgreSQL Utility for EnterpriseDB Installation

January 30th, 2012 — 10:00pm

PostgreSQL Installer provided by EnterpriseDB is so handy and make your life very easy for OS X Desktop installation.

Maybe I just don’t know the handy utility but I wrote a shell script to control/display various tasks hence I wanted to share this with you.

The utility contains: start | stop | restart | stopfast | stopnow | status | vac_status | show_connections | version | restore backup


NODE_NAME=`uname -n`
NODE_NAME=${NODE_NAME%%\.*local}
NODE_NUMBER=${NODE_NAME##*SQL-}
PGBIN=/Library/PostgreSQL/9.1/bin
PGDATA=/Library/PostgreSQL/9.1/data
pidof(){
# usage: `pidof`
ps -ef | grep postgres | awk '{if ($3==1)print $2}'
}
start(){
pid=`pidof`
if [ "$pid" == "" ] ; then
echo "Starting postgres..."
su - postgres -c "${PGBIN}/pg_ctl -w start -D ${PGDATA} -l ${PGDATA}/pg_log/startup.log"
else
status
fi
}
stop(){
pid=`pidof`
if [ "$pid" != "" ] ; then
echo "Stopping postgres..."
su - postgres -c "${PGBIN}/pg_ctl stop -m smart -w -D ${PGDATA}"
else
echo "Postgres is not running"
fi
}
stopfast(){
pid=`pidof`
if [ "$pid" != "" ] ; then
echo "Stopping postgres..."
su - postgres -c "${PGBIN}/pg_ctl stop -m fast -w -D ${PGDATA}"
else
echo "Postgres is not running"
fi
}
stopnow(){
pid=`pidof`
if [ "$pid" != "" ] ; then
echo "Stopping postgres..."
su - postgres -c "${PGBIN}/pg_ctl stop -m immediate -w -D ${PGDATA}"
else
echo "Postgres is not running"
fi
}
status(){
pid=`pidof`
if [ "$pid" != "" ] ; then
echo "postgres is running"
echo `ps -ef | grep postgres | grep -v grep | awk '{if ($3==1) print "Postgres: " $8 ", Data Directory: " $10}'`
else
echo "postgres is not running"
fi
}
vac_status(){
su - postgres -c "${PGBIN}/psql -c \"select relname, last_autovacuum, last_autoanalyze from pg_stat_user_tables where last_autovacuum IS NOT NULL order by last_autovacuum desc\""
}
show_connections(){
su - postgres -c "${PGBIN}/psql -c \"SELECT datname, usename, procpid, client_addr, waiting, query_start, current_query FROM pg_stat_activity;\""
}
version(){
su - postgres -c "${PGBIN}/psql -c \"SELECT version()\""
}
restore_bak(){
echo "backup file path : "
read BACKUPFILEPATH
echo "database name : "
read DBNMAE
chmod -R 777 $BACKUPFILEPATH
cat ${BACKUPFILEPATH} | gunzip | ${PGBIN}/psql -U postgres ${DBNMAE}
${PGBIN}/psql -d ${DBNMAE} -U postgres < /users.sql
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
;;
stopfast)
stopfast
;;
stopnow)
stopnow
;;
vac_status)
vac_status
;;
show_connections)
show_connections
;;
restore_bak)
restore_bak
;;
version)
version
;;
*)
echo "Usage: $0 { start | stop | restart | stopfast | stopnow | status | vac_status | show_connections | version | restore_bak }"
exit 1
esac
exit 0

Comment » | mac, OS X, PostgreSQL, System Admin

PostgreSQL DB Version Control with apgdiff

January 29th, 2012 — 9:05pm

apgdiff (Another PostgreSQL Diff Tool) is so easy to setup and use.

# you need at least Java 1.6

$ java -version

java version “1.6.0_29″
Java(TM) SE Runtime Environment (build 1.6.0_29-b11-402-10M3527)
Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02-402, mixed mode)

# download binary and that’s it.

$ curl -O http://apgdiff.startnet.biz/download/apgdiff-2.3-bin.zip
$ unzip apgdiff-2.3-bin.zip

# create SQL dump files

$ pg_dump –host HOST_IP –port 5432 -U DB_USER -s -f new.sql ALPHA_DB
$ pg_dump –host HOST_IP –port 5432 -U USER -s -f old.sql PROD_DB

# generate upgrade statement

$ PATH_TO_APGDIFF=/tmp/apgdiff
$ java -jar $PATH_TO_APGDIFF/apgdiff-2.3.jar –ignore-start-with old.sql new.sql > upgrade.sql

Comment » | Bash Shell, mac, OS X, PostgreSQL

Know how to use Chrome developer tools I – Disable Cache

January 29th, 2012 — 2:50pm

1. Open Web Developer Tools
(Option + Command + i) or (Menu > View > Developer > Developer Tools

 

 

 

 

2. Disable Cache

2.1. Go to Settings

2.1.1. Click Gear icon on lower bottom

2.1.2. Check Disable Cache

 

Comment » | HTML, JavaScript, mac, OS X, Web Development

How to get IP address on your mac from Terminal

August 2nd, 2011 — 8:40pm

This will give you ethernet one

ifconfig en0 | grep ‘inet ‘ | cut -d ‘ ‘ -f2

This will give you airport one

ifconfig en1 | grep ‘inet ‘ | cut -d ‘ ‘ -f2

so if you are writing script to get your IP in either case you could:

MYIP=`ifconfig en0 | grep ‘inet ‘ | cut -d ‘ ‘ -f2`
if [$MYIP -eq '']; then
MYIP=`ifconfig en1 | grep ‘inet ‘ | cut -d ‘ ‘ -f2`
fi

MYIP=`ifconfig en0 | grep ‘inet ‘ | cut -d ‘ ‘ -f2`if [$MYIP -eq '']; then MYIP=`ifconfig en1 | grep ‘inet ‘ | cut -d ‘ ‘ -f2`fi

echo $MYIP

Comment » | Bash Shell, mac, OS X

Back to top