This installation guide is limited to linux environment.
- 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- Download the source code from the postgreSQL website.
$ wget https://ftp.postgresql.org/pub/source/v9.4.5/postgresql-9.4.5.tar.gz- Untar the sourcecode.
$ tar -xvzf postgresql-9.4.5.tar.gz - 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- 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 ~/.bashrcAlso 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- Initialize the database storage with
initdbcommand 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- Start the database server with logfile. You can modify the configurations with
postgresql.conffile inside a data directory.
$ pg_ctl -D /home/postgres/test_data -l logfile start- 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- End the database server.
$ pg_ctl -D /home/postgres/test_data -m smart stop- You can also configure postgres configurations via
postgresql.confin the data directory.