Archive for July 2010
PostgreSQL: Dump Schema Only or Triggers Only
I needed to extract triggers only, sequence/index only etc when we migrated database.
I received advice from postgresql General List and thought I should post exact step/script of how to accomplish this.
Open Terminal:
1. dump schema only
pg_dump -h localhost -p 5432 –username UserName –schema-only –format c –file path_to_backup.backup –schema ‘public’ db_name
2. create list of item that you want to extract
2.1. TRIGGERS only
pg_restore –list “path_to_backup.backup” | awk ‘/[0-9]*; [0-9]* [0-9]* (TRIGGER)/ { print }’ > “path_to_triggers.list”
2.2. SEQUENCE, INDEX
pg_restore –list “path_to_backup.backup” | awk ‘/[0-9]*; [0-9]* [0-9]* (SEQUENCE|INDEX)/ { print }’ > “path_to_seq.list”
3. Create SQL script from the list
3.1. TRIGGERS only
pg_restore -L path_to_triggers.list -f dest_path_triggers.sql path_to_backup.backup
3.2. SEQUENCE, INDEX
pg_restore -L path_to_seq.list -f dest_path_seq.sql path_to_backup.backup
nightly backup (pg_dump) with shell script and cron job
1. write a shell script
#!/bin/bash#backup.shlogfile=”/backups/logfile.log”# Location to place backups.backup_dir=”/backups”touch $logfiletimeslot=`date +%y%m%d_%H%M`databases=(“db1″ “db2″ “db3″)# get length of an arraytLen=${#databases[@]}for (( i=0; i<${tLen}; i++ )); doecho “Vacuum Starting at `date` for database: ${databases[$i]} ” >> $logfiletimeinfo=`date ‘+%T %x’`psql -c “vacuum verbose analyze” -d ${databases[$i]} -U postgres >> $logfileecho “Vacuum completed. Backup Starting at `date` for database: ${databases[$i]} ” >> $logfilepg_dump ${databases[$i]} -h 127.0.0.1 -U postgres | gzip > “$backup_dir/${databases[$i]}-$timeslot-backup.gz”echo “Backup and Vacuum complete at `date` for database: ${databases[$i]} ” >> $logfiledone
2. Add an entry to crontab to execute the script above
2.1. open terminal and login as postgres: $ su – postgres
2.2. list cron job: $ crontab -l
2.3. edit cron job:
2.3.1. $ crontab -e #in terminal vi editor will open)
2.3.2. i for insert mode
2.3.3. enter entry. for instance, to run it every 1 am:
00 01 * * * path_to_backup.sh > /dev/null
2>&1
2.3.4. ESC key to exist edit mode
2.3.5. :wq to save and quit
great moral leader are made of:
I salute the man who is going through life always helpful, knowing no fear, and to whom aggressiveness and resentment are alien.
- Albert Einstein
Install NetBeans 6.9 to OS X 10.5.8
NetBeans 6.9 is a great PHP IDE and I have been pretty happy about it. Although initially, I almost gave up installing this on my MacBook Pro – After installation was done and launch the application I have encountered an error saying “Cannot run on older version of Java 6 Standard Edition.
Please install Java 6 Standard Edition or newer or use –jdkhome switch to point to its installation directory.”
To solve this problem:
Application: Utilities: Java Preference >> Drag Java SE 6 to the top
If this doesn’t fix the issue try:
Terminal: type “env”. Do you see JAVA_HOME is defined? If so, is this pointing to older version? If so fixing that should resolve the issue (at least it resolved my case). Here is how I fixed:
- my JAVA_HOME was set to
/Library/Java/Homewhich was simply the symlink to
System/Library/Frameworks/ JavaVM.framework/Versions/1.5.0/Home - rename the symlink to Home_old
- then create new symlink point to 1.6 (SE 6) as follows: ln -s
/System/Library/Frameworks/ JavaVM.framework/Versions/1.6.0/Home /Library/Java/Home