Skip to content

Latest commit

 

History

History
82 lines (72 loc) · 2.66 KB

postgres-installation-guide.md

File metadata and controls

82 lines (72 loc) · 2.66 KB

How to Install & Run postgreSQL with Sourcecode

This installation guide is limited to linux environment.

Installation Procedures

  1. Create a user and login to postgres account. If you are using separate devices for data and log storage, you need to mount them to /home/postgres/ as well.
$ adduser postgres
$ su - postgres
  1. Download the source code from the postgreSQL website.
$ wget https://ftp.postgresql.org/pub/source/v9.4.5/postgresql-9.4.5.tar.gz
  1. Untar the sourcecode.
$ tar -xvzf postgresql-9.4.5.tar.gz 
  1. Create a new directory to build and configure the source tree. Then build and install the sourcecode.
$ cd postgresql-9.4.5
$ mkdir build
$ ./configure --prefix=/home/postgres/postgresql-9.4.5/build
$ make -j install
  1. Then add the shared library path to ~/.bashrc. Then apply the change.
vim ~/.bashrc
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/postgres/postgresql-9.4.5/build/lib
export PATH=/home/postgres/postgresql-9.4.5/build/bin:$PATH

source ~/.bashrc

Also add the shared library to .profile of postgres user.

$ cd ~
$ vim .profile
PATH=$PATH:/home/postgres/postgresql-9.4.5/build/bin
export PATH
$ . ~/.profile

How to Start PostgreSQL Server

  1. Initialize the database storage with initdb command of postgres. You can dedicate a data directory using -D option.
$ initdb -D /home/postgres/test_data
$ initdb --encoding=UTF-8 --no-locale --username=root --pgdata=/home/postgres/test_data
  1. Start the database server with logfile. You can modify the configurations with postgresql.conf file inside a data directory.
$ pg_ctl -D /home/postgres/test_data -l logfile start
  1. Create/drop USER and table examples:
$ psql
postgres=# \du
                             List of roles
 Role name |                   Attributes                   | Member of 
-----------+------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication | {tpcc}
 tpcc      |                                                | {}
postgres=# DROP DATABASE tpcc;
DROP DATABASE
postgres=# DROP USER tpcc;
DROP ROLE
postgres=# \q
  1. End the database server.
$ pg_ctl -D /home/postgres/test_data -m smart stop
  • You can also configure postgres configurations via postgresql.conf in the data directory.

References