PostgreSQL, as we know is an Open Source RDBMS. Since I am not that much into Database, I don’t know how it compares with MySQL 😦 My focus on this post is on how to install it on a Linux server. Lets start with it 🙂
Download source-code. First step will be to download the source-code from its official site. Choose the version that you want to install. I chose 9.3.5 since this was my requirement. I downloaded the zipped tar file. Choose any one that suits you. Its around 21MB in size.
Unpack the tar file. Now we need to untar the downloaded file & configure it to prepare installation. Issue below command to untar it.
tar -xvf postgresql-9.3.5.tar.gz
Do a listing of the pwd (present working directory) & see if a new directory is created or not. Now move to this directory. By default, PostgreSQL is installed under /usr/local/pgsql directory. If you want to install it here, just run the configuration script, that is :
If you want it to be installed somewhere else, then issue :
Prefix means the directory where you want to install it. Choose accordingly. This step will take some time, So, be patient 😉
You may run into a few errors like : –
configure: error: readline library not found configure: error: zlib library not found.
To fix it, install these packages.
readline-devel.x86_64 & zlib-devel.x86_64
Make sure to use packages for your architecture.
Build installer & run installer. Now that we have configured the source, we can now make the installer & install PostgreSQL. Just issue
It will produce the installer. Its better to execute this command & then go have a cup of coffee 😉 It will take some more time & after that issue command :
It will install PostgreSQL on your Linux machine 🙂
make: Leaving directory `/opt/postgresql-9.3.5/config' PostgreSQL installation complete.
Add a user postgres. Issue
& create its password.
Create data directory. Make a directory inside PostgreSQL installation directory /usr/local/pgsql or anywhere it is installed.
mkdir -p /usr/local/pgsql
mkdir -p /opt/PostgreSQL/9.3/data
Change ownership of this directory to postgres.
chown postgres /usr/local/pgsql
Initiate the database. Switch to postgres ID & issue this command
/opt/PostgreSQL/bin/initdb -D /opt/PostgreSQL/9.3/data
This will dump a few lines of text on screen.
The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale "en_US.UTF-8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". Data page checksums are disabled. fixing permissions on existing directory /opt/PostgreSQL/9.3/data ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 128MB creating configuration files ... ok creating template1 database in /opt/PostgreSQL/9.3/data/base/1 ... ok initializing pg_authid ... ok initializing dependencies ... ok creating system views ... ok loading system objects' descriptions ... ok creating collations ... ok creating conversions ... ok creating dictionaries ... ok setting privileges on built-in objects ... ok creating information schema ... ok loading PL/pgSQL server-side language ... ok vacuuming database template1 ... ok copying template1 to template0 ... ok copying template1 to postgres ... ok syncing data to disk ... ok WARNING: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb. Success. You can now start the database server using: /opt/PostgreSQL/9.3/bin/postgres -D /opt/PostgreSQL/9.3/data or /opt/PostgreSQL/9.3/bin/pg_ctl -D /opt/PostgreSQL/9.3/data -l logfile start
PostgreSQL is now installed on your Linux machine 🙂 Hope, this post was able to explain it in an easy manner 🙂 Looking forward to hearing from you 🙂