Install PostgreSQL 9.0 from source code at Ubuntu

System: Ubuntu 10.04 and PostgreSQL 9.0.3

Download the source code from: http://www.postgresql.org/ftp/source/

Unzip the source and go to a directory. All followings happen via command line terminal. So open a terminal:

hadoop@fxu-t60:~/Downloads/postgresql-9.0.3$ ./configure
....
....
configure: error: readline library not found
If you have readline already installed, see config.log for details on the failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-readline to disable readline support.

Install readline package to fix this:

sudo apt-get install libreadline6-dev

Next problem you might see:

<pre>hadoop@fxu-t60:~/Downloads/postgresql-9.0.3$ ./configure
....
....</pre>
configure: error: zlib library not found
If you have zlib already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-zlib to disable zlib support.

Install zlib package to fix this:

sudo apt-get install zlib1g-dev

Now everything is ready to go:

./configure
sudo make
sudo make install

Then create the data directory to store all data files and do some configuration

sudo mkdir /usr/local/pgsql/data
sudo adduser postgres
sudo chown postgres /usr/local/pgsql/data
su - postgres

Then initialize the database:

postgres@fxu-t60:~$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/
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".

fixing permissions on existing directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 32MB
creating configuration files ... ok
creating template1 database in /usr/local/pgsql/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... 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

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.

Success. You can now start the database server using:

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

Then create log directory and a sample database:

postgres@fxu-t60:~$ cd /usr/local/pgsql/data/
postgres@fxu-t60:/usr/local/pgsql/data$ mkdir log
postgres@fxu-t60:/usr/local/pgsql/data$ /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >/usr/local/pgsql/data/log/logfile 2>&1 &
[1] 16002
postgres@fxu-t60:/usr/local/pgsql/data$ cd ..
postgres@fxu-t60:/usr/local/pgsql$ bin/createdb mydb
postgres@fxu-t60:/usr/local/pgsql$ bin/psql mydb
psql (9.0.3)
Type "help" for help.

mydb=#

(optional) change postgres user password,type: sudo passwd postgres
(optional) To start the server automatically at every boot, add: su -c ‘/usr/local/pgsql/bin/pg_ctl start -l /usr/local/pgsql/data/log/logfile -D /usr/local/pgsql/data’ postgres to your /etc/rc.local file

Advertisements

19 thoughts on “Install PostgreSQL 9.0 from source code at Ubuntu

  1. I received a error message when I try to start the server:

    ~ $ /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
    postgres cannot access the server configuration file “/usr/local/pgsql/data/postgresql.conf”: Permission denied

    What went wrong?

  2. This is great, but the process keeps exiting after I enter “cd ..” after the line

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

    Any idea how to fix this?

    1. What do you mean exit? If you do not want it running at background, Try: /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >/usr/local/pgsql/data/log/logfile 2>&1

      1. Here’s the output from my console, if it’s any help:

        postgres@ubuntu:/usr/local/pgsql/data$ /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >/usr/local/pgsql/data/log/logfile 2>&1 &
        [1] 23010

        postgres@ubuntu:/usr/local/pgsql/data$ cd ..
        [1]+ Exit 1 /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data > /usr/local/pgsql/data/log/logfile 2>&1 (wd: /usr/local/pgsql/data)
        (wd now: /usr/local/pgsql)

      2. I get it’s running back end, but why does it output [1]+ Stopped?

        Perhaps I’m singling out the wrong part, but when I run the next instruction, it outputs

        postgres@ubuntu:/usr/local/pgsql$ bin/createdb mydb
        createdb: could not connect to database postgres: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket “/tmp/.s.PGSQL.5432”?

  3. Since the db is not running, so you cannot create table.
    I still can not diagnose the reason why the db is stopped. My best practice is redo the whole process at a new machine.
    Good luck!

  4. I had a problem as

    postgres@ubuntu:/usr/local/pgsql/data$ /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >/usr/local/pgsql/data/log/logfile 2>&1 &
    [1] 23010

    postgres@ubuntu:/usr/local/pgsql/data$ cd ..
    [1]+ Exit 1 /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data > /usr/local/pgsql/data/log/logfile 2>&1 (wd: /usr/local/pgsql/data)
    (wd now: /usr/local/pgsql)

    I found the problem. I first remove “libreadline6-dev” and “zlib1g-dev” and also “postgres” user which is in my system from previous install. Then I followed instruction in this page and now it works. (-;

  5. If we installed the postgresql –without-readline and –without-zlibs will it be possible to add them after the installation? or should we uninstall the existing installation and redo the installation.

    Please advice.

  6. We have installed postgresql 9.3 DB from source and it has thrown an error with readline and zlibs, and we have proceeded with configuration –without-readline & –without-zlib.

    Could you please let me know if there is a way to add the zlibs to the existing DB,

  7. I got an error after inserting this command “/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/” . This is the error “FATAL: wrong number of index expressions
    STATEMENT: CREATE TRIGGER pg_sync_pg_database AFTER INSERT OR UPDATE OR DELETE ON

    pg_database FOR EACH STATEMENT EXECUTE PROCEDURE flatfile_update_trigger();

    child process exited with exit code ”

    Do you have any suggestions?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s