Skip to main content

Installing PostgreSQL on Linux

Recently I had to install postgresql on a linux machine. I ended up referring to more than one article on the web. So here's an attempt to capture all in one document.

1. Download latest postgresql-XXX.tar.gz (where XXX is a release number) distribution of postgres database. At the time of writing this document 8.2 is the latest release.

2. Due to built-in security reasons, postgres cannot run as a root user. Therefore, become a superuser and create a postgres group. Then add a user postgres to the group as follows;

sudo su - root (become a superuser)

groupadd postgres (create a postgres group)

useradd postgres –g postgres (create a postgres user)

3. Extract the tar file into /usr/local directory. This should create a postgresql-XXX subdirectory in /usr/local.

cd /usr/local

gunzip -c /path-to-file/postgresql-XXX.tar.gz | tar xvf -

4. create a /usr/local/pgsql directory where postgres database will be installed.

mkdir /usr/local/pgsql

5. Assign ownership of directories created above to postgres user.

chown -R postgres.postgres /usr/local/pgsql

chown -R postgres.postgres /usr/local/postgresql-XXX

6. Switch to postgres user from superuser.

su - postgres

7. Configure and prepare postgres for installation.

./configure

gmake

If successful, the last line displayed should be as below.

"All of PostgreSQL is successfully made. Ready to install."

8. start installation

gmake install

9. Set environment variables. Add following to .bashrc in home directory of postgres user. For example, /home/postgres

LD_LIBRARY_PATH=/usr/local/pgsql/lib

export LD_LIBRARY_PATH

PATH=/usr/local/pgsql/bin:$PATH

export PATH

MANPATH=/usr/local/pgsql/man:$MANPATH

export MANPATH

10. Link runtime libraries for faster access. (you need to be a superuser to execute this command. Type exit, run the command and then type "su - postgres" to log back in as postgres user).

/sbin/ldconfig /usr/local/pgsql/lib

11. Create a directory for storing database data files.

mkdir /usr/local/pgsql/data

12. Start postgres process.

cd /usr/local/pgsql/bin

postgres -D /usr/local/pgsql/data >logfile 2>&1 &

13. Add following to /etc/rc.d/rc.local script so that postgres is restarted upon reboot.

/usr/local/pgsql/bin/pg_ctl start -l logfile -D /usr/local/pgsql/data

This completes the Postgres installation.

Comments

Popular posts from this blog

Creating no-reply@domain.com account in Postfix

If you wanted to send emails to users but did not want to receive any replies to the email, you would need to setup a no-reply@domain.com email account. These kind of email ids are useful when sending emails containing forgotten passwords or activation code. Below are the steps for creating such account in Postfix. 1. Identify the file containing alias for Postfix First, make sure the following line in the ALIAS DATABASE section of the /etc/postfix/main.cf is NOT commented out: alias_maps = hash:/etc/aliases 2. Create an alias that redirects messages to /dev/null Edit /etc/aliases and add following entry devnull: /dev/null 3. Create a virtual email id Edit /etc/postfix/virtual and add following entry no-reply@domain.com devnull 4. refresh postfix alias and postfix cache Execute following commands. (You may require root privileges) > newaliases > postfix reload

jupyter notebook execution error: "http://localhost:8889/tree?token=xxx" doesn’t understand the “open location” message

I got this error when I tried to launch jupyter notebook on a mac. It is not a fatal error. I could still go to browser directly and copy/paste the url manually. The error indicates that when the command automatically tried to launch a browser, it couldn't find the default browser in jupyter configuration file. The easy fix is to specify the browser. Here are the steps to do so; 1.   Open ~/.jupyter/jupyter_notebook_config.py in an editor.       If the file does not exist then you can create a default config file by typing the following command;       jupyter notebook --generate-config 2. Search for a word "browser" to locate a following line.     #c.NotebookApp.browser = ''     By default it is commented. You can uncomment it and use one of the following values depending on your browser preference.     # set default browser to chrome     c.NotebookApp.browser = 'chrome'     # set default browser to safari     c.NotebookApp.browser = 

.ssh/config: “Bad configuration option: UseKeychain” on Mac OS

After upgrading Mac OS to Mojave I started seeing this error when doing "git pull". I was able to follow the steps below as described here ; 1. open ssh config vi ~/.ssh/config 2. Add the following lines to ssh config to keep your configuration compatible with both new and old versions of openssh. IgnoreUnknown UseKeychain UseKeychain yes That fixed the issue for me. Try running git pull again.    More details about the issue are available here .