Change The Location of PostgreSQL Database Store Its Table and Index

Find a way to split the postgres database into different partitions.
Two main use case [1]
  1. First, if the partition or volume on which the cluster was initialized runs out of space and cannot be extended, a tablespace can be created on a different partition and used until the system can be reconfigured.
  2. Second, tablespaces allow an administrator to use knowledge of the usage pattern of database objects to optimize performance. For example, an index which is very heavily used can be placed on a very fast, highly available disk, such as an expensive solid state device. At the same time a table storing archived data which is rarely used or not performance critical could be stored on a less expensive, slower disk system.

To Create a Tablespace

CREATE TABLESPACE fastspace LOCATION '/mnt/sda1/postgresql/data';

To Change the Tablespace of an Existing Table and Index

The following psql command will create a list of alternate table command to change the table's tablespace [2]
-- tabelspace is null - find table that doesn't have any tablespace set
select 'alter table '||schemaname||'.'||tablename||' set tablespace fastspace;' from pg_tables where schemaname='myschema' and tablespace is null;
 
select 'alter index '||schemaname||'.'||indexname||' set tablespace fastspace;' from pg_indexes where schemaname='myschema' and tablespace is null;


It will return something similar to this
                               ?column?
-----------------------------------------------------------------------
 alter table myschema.table1 set tablespace fastspace;
 alter table myschema.table2 set tablespace fastspace;
 alter table myschema.table3 set tablespace fastspace;
(3 rows)
                               ?column?
-----------------------------------------------------------------------
 alter index 
myschema.index1 set tablespace fastspace;
 alter index 
myschema.index2 set tablespace fastspace;
 alter index 
myschema.index2 set tablespace fastspace;
(3 rows)
 Then just run each generated command to change/set the tablespace.

Reference:
1. http://www.postgresql.org/docs/8.1/static/manage-ag-tablespaces.html
2. http://www.postgresql.org/message-id/01c001c9335f$06e991d0$274610ac@praveenkm

Config Git Default Setting

Some Git configurations I need to set every time I re-install OS, cygwin or in a new system

User Name
git config --global user.name "Your Name"
User Email
git config --global user.email you@example.com
Default Editor (I prefer vi)
git config --global core.editor vi
Colorized Git Output (when using a terminal)
git config --global color.ui auto
Pager Indentation Width (I like it to be 4 characters)
git config --global core.pager 'less -x4'
Sample output of 'git diff HEAD~' when color.ui is set to auto
HEAD is at https://kernel.googlesource.com/pub/scm/git/git - 2ae48a9bb87193de9e9da10abd9e7286c0e4c43d
git running in cygwin on Win7

Edited on 2015.03.27: Added "Pager Indentation Width"

Set Up DD-WRT Router To Use Google DNS/OpenDNS

Google DNS teams up with OpenDNS and some "Content Delivery Networks (CDNs) to attach location data to the DNS requests, so when you request a web page, it will go to a server near you" [1]

Here's how I update the configuration of my DD-WRT'ed Linksys WRT54G-TM to use Google DNS.

  1. Log into your router's dd-wrt web interface.  You can access it using 192.168.1.1 in your browser.
  2. Go to Services tab » Services sub tab » Services Management section » DNSMasq sub section
  3. Enable both DNSMasq and Local DNS options
  4. In the Additional DNSMasq Options text box, enter:
  5. no-resolv
    strict-order
    server=8.8.8.8
    server=8.8.4.4
  6. Click Apply Settings

Reference:
[1]: http://lifehacker.com/5835775/google-dns-and-opendns-users-are-getting-a-web-speed-boost
[2]: http://www.dd-wrt.com/wiki/index.php/OpenDNS
[3]: http://code.google.com/speed/public-dns/docs/using.html


Useful System Statistics Linux/Ubuntu Command Line Program - Dstat

Sample dstat output from my Ubuntu desktop

I was looking for for a Ubuntu command line program to monitor my desktop's network speed.  I found this ubuntuforums.org page that mention dstat.  It's easy to install
sudo apt-get install dstat
It not only monitor your network card speed, but also monitor cpu, disk i/o and many more.  See the dstat official page for more information.

Btw, here's the dstat man page (manual page)