Thursday 15 December 2011

Postgressql

Windows OS postgresql command:

1. go to postgresql's executable commands directory
> cd c:\Program Files\PostgreSQL\9.0\bin 

2. Backup a postgresql database
> pg_dump.exe -U <username> -h <ip_address> -p <port> -W <db_name> > <backup_file>

3. Resume a backup db to database system
> psql.exe -U <username> -h <ip_address> -p <port> -d <db_name> < <backup_file>

4. To execute a postgresql script
> psql.exe -U <username> -h <ip_address> -p <port> -d <db_name> -c "<command>"
 
5. To drop a database
> psql.exe -U <username> -h <ip_address> -p <port> -d <db_name> -c "DROP DATABASE <db_name>"

6.To create a database
> psql.exe -U <username> -h <ip_address> -p <port> -d <db_name> -c "CREATE DATABASE <db_name>"

6.To create a database that support for UTF-8
> createdb.exe -E UTF8 -T template0 --lc-collate=american_usa --lc-ctype=american_usa -h <ip_address> -p <port> -U <username> -W  <db_name>

Convert Chinese Character to UTF-8

1. Create a source file "c:\source.txt", put the Chinese characters inside, and save it in "UTF-8" format.

2. Open the command prompt:

c:\>native2ascii -encoding utf8 c:\source.txt c:\output.txt

You can get the UTF-8 output in the c:\output.txt