Monday, March 7, 2011

How to : install and test PostgreSql on Centos

basically, just download and config , then make && make install.

  • Download the latest and stable source from Postgresql Site

wget http://wwwmaster.postgresql.org/redir/407/h/source/v9.0.3/postgresql-9.0.3.tar.gz

  • Unzip the tarball file.

tar -zxf postgresql-9.0.3.tar.gz

  • run the config, make sure prerequisites are there

yum install openssl-devel
yum install zlib-devel
yum install gnu-crypto
yum install readline-devel
yum install gcc-objc++


./configure –help  # list all options to run the compilation, you can override the installation folder using the –-pre-fix options.


Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/postgresql]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]

you can also just run ./configure , it will pick up all default options.

  • make and make install
make && make install
  • make sure it’s installed without error, add the bin folder to profile , then we can initialize the db.

In /etc/profile or ~/.profile
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/pgsql/bin"
export PATH

  • Create postgres user and init the db
useradd postgres
mkdir /usr/local/psql/data
chown postgres /usr/local/psql/data


[root@home pgsql]# su - postgres
[postgres@home ~]$ initdb --pgdata=/usr/local/pgsql/data

image
  • start the service and client

pg_ctl -D /usr/local/pgsql/data start
image

Now, DB server is ready, we can use the postgres which is a superuser to create some database.

Su – postgres
psql 
\l will list all the database.
image

Create database HelloDB;
Create database helloDB;
#connect helloDb
\c helloDB;

Here,let’s download some sample data from http://pgfoundry.org/projects/dbsamples/
world-1.0.tar.gz
upzip and use \I to install the db from the sql .

image

table city, will list all rows in city table.

image

I will write a C# application using the standard ado.net library to read the city table.

How To : using Postgresql C# Client Npgsql to access postgresql database

1 comment:

Anonymous said...

I want to install postgreSQL on my CentOS, thanks already to guide how to install.

 
Locations of visitors to this page