Building PostgreSQL from the source code enables you to customize build parameters, compiler optimizations, and installation location.
You can download the sources from the website. Then, unpack it:
$ tar xf postgresql-11.4.tarFirst, make a directory for build and configure the source tree for your system.
$ mkdir build_dir
$ ./configure --prefix=/path/to/build_dirThen build and install the source code. (8: # of cores in your machine)
$ make -j8 installYou need to tell the system how to find the newly installed shared libraries. Set the shared library search path in ~/.bashrc:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/build_dir/lib
export PATH=/path/to/build_dir/bin:$PATHThen, apply the modified path:
$ source ~/.bashrcBefore you can do anything, you must initialize a database storage area on disk. To initialize a database cluster, use the command initdb, which is installed with PostgreSQL. The desired file system location of your database cluster is indicated by the -D option:
$ initdb -D /path/to/data_dirThen, start the server with a log file:
$ pg_ctl -D /path/to/data_dir -l logfile startYou can stop the server using below command:
$ pg_ctl -D /path/to/data_dir -m smart stop