Tuesday, December 6, 2011

Postgres Installation on mac


Follow the below instructions to extract, install and configure "Postgres"

#tar -xvfz postgresql-8.4.7.tar.gz
#cd  postgresql-8.4.7
$./configure
$make 
$make install
Create postgres account(System Preferences->Accounts->new User->postgres)

$su -
imac:~ root#mkdir /usr/local/pgsql/data
imac:~ root#chown postgres /usr/local/pgsql/data
imac:~ root#su -l postgres
imac:~ postgres$/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
The above command will take the default encoding SQL_ASCII
If you want to select different encoding use:
/usr/local/pgsql/bin/initdb -E UTF8 /usr/local/pgsql/data

set the path using:
imac:~ postgres$ export PATH=$PATH:/usr/local/pgsql/bin

starting the postgres using:
imac:~ postgres$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/data/logfile start

stopping the postgres using:
imac:~ postgres$ /usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data 

Using Postgres command line shell
Starting Postgres Interpreter Shell

  • SU to user 'postgres' (see above)
  • $ psql test              (test is name of database you want to connect to)
// Quit shell
test=> \q
// import sql file
test=> \i basics.sql
// list databases
test=> \l
// 'use' database test
test=> \c test
// List tables in current dbms
test=> \d
// Show table structure
test=> \d tablename


No comments:

Post a Comment