How to Install PostgreSQL?
PostgreSQL as a powerful open source object-relational database management solution evolved from being specifically used for UNIX based operating systems and designed to be compatible for Windows, MacOS, and Solaris making it portable across platforms.
Steps To Install PostgreSQL:
Below are the detailed steps to install PostgreSQL in your PC.
Follow https://www.postgresql.org/download/ and you can find download binary package for your preferred operating system.
Prior to the installation, Postgres demands minimum requirement of the system to run on and has documented the specifics:
Installation on Windows
PostgreSQL follows a regular standard installation wizard, where the user accepts terms and conditions and specifies the installation directory.
As part of the installation in windows, the wizard prompts for password configuration.
Followed by port configuration on which the PostgreSQL service is ought to be hosted.
4.5 (1,813 ratings)
And next, we are prompted to select the locale to be used by database cluster. This influences the text encoding techniques used, which in turn affects sorting order for the text.
And as a final step, we can launch the stack builder tools which comes with PostgreSQL suite. Stack builder provides a wide set of packages, drivers and tools which accessorizes PostgreSQL installation
After selecting the appropriate server config in the stack builder.
It enlists various drivers and tools, from which we can select the desired and proceed to install them.
Installation on Ubuntu
Ubuntu by default has access to PostgreSQL repositories, hence we can refresh our local package index and install it through ‘apt’.
Or we can directly download the required from the apt repository by navigating to https://www.postgresql.org/download/linux/ubuntu/
$ sudo apt-get update
$ sudo apt-get install PostgreSQL PostgreSQL-contrib
Here -contrib is used to include a package that facilitates add-on features bundled with PostgreSQL.
The installation creates a user account called ‘postgres’, which can be logged in using
$ sudo -i -u postgres
the postgres prompt can be accessed by typing
PostgreSQL on ubuntu by default assigns on 5432 port, from which user is given the privilege to change in the PostgreSQL.conf file
This file acts as the configuration setting for PostgreSQL in the system, where we can change the desired port in the attribute
port = 5478
For YUM installation, navigate to YUM Postgres repository and download the rpm of the respective distribution
curl -O http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg- centos92-9.2-6.noarch.rpm
followed by the traditional rpm installation
rpm -ivh pgdg-centos92-9.2-6.noarch.rpm
Installation on MAC
PostgreSQL can be installed easily on MAC equipped with Homebrew and Lunchy. Before proceeding with installation, make sure homebrew is up to date
$ brew update
$ brew doctor
and followed by the installation command for postgres.
$ brew install PostgreSQL
The user can custom define the port on which Postgres should run on the system, by setting up the MAC environment variables as below
Besides the usual way of installing PostgreSQL on different operating systems, we can also install via text mode.
For Windows :
By running the following in the CMD prompt
PostgreSQL-10.4-1-windows-installer.exe –mode text
For Linux distributions
PostgreSQL-10.4-1-Linux-x64-installer.run –mode text
Run the below sh file
PostgreSQL-10.4-1-osx-installer.app/Contents/MacOS/installbuilder.sh – mode text
With wide choices in the market, Postgres supports several substantial features like MVCC (Multi-Version Concurrency Control), tablespaces, point in time recovery, hot backups which have made it stand out and more preferable when coming to server scalability.
The below section will provide essential instructions to be followed to install Postgres on the server and facilitating data source for Plesk access :
Getting started with the pgAdmin tool
pgAdmin is the most popular rich open source administration client for PostgreSQL
1)In the pgAdmin browser, right click on PostgreSQL node under ‘servers’ and connect server
2)Input the PostgreSQL username and password to establish the connection.
3) With the database node, right-click and create a database; Then save.
4) Followed by which you can create login roles, create queries and vast functionalities in a feasible way.
Steps to Install PostgreSQL server (with Plesk)
In real-time, with the scalable feature trait of PostgreSQL, we often require hosting of Postgres on a server and the following section will guide the basic configuration specifics :
1) Install the required server files,
yum install PostgreSQL PostgreSQL-server
Total download size: 6.8 M
Is this ok [y/N]:
2) Initiate PostgreSQL server and configure admin settings
change to the Postgres system user to the admin user which Plesk uses, with the help of command :
Enter the username and password, and configuration of Postgres is done.
Now as root user, modify the config (/var/lib/pgsql/data/pg_hba.conf) Existing entry (host all all 127.0.0.1/32 ident) should be modified to
host all all 127.0.0.1/32 md5
This allows login requests from the server. once done, execute the following and restart the server
sed -i ‘s/host\s*all\s*all\s*127.0.0.1\/32\s*ident\s*sameuser/#&/’ /var/lib/pgsql/data/pg_hba.conf && echo -e “\n# Allow password connections from localhost\nhost all all 127.0.0.1/32 md5” >> /var/lib/pgsql/data/pg_hba.conf && /etc/init.d/postgresql restart
3) Final step is registering the server with plesk to perform database operations
/usr/local/psa/bin/database-server –update-server localhost:5432 -type postgresql -admin admin -passwd `cat /etc/psa/.psa.shadow` && service psa restart
Now login to Plesk control panel; Under ‘Websites and Domains’ tab, select ‘Databases
Opt for Add New Database, after which you can enter the name of postgres database and select ‘PostgreSQL’ type in drop down.
- You can run a regression test on the newly configured server before installing. This ensures that the server runs as expected and can be achieved using the command:
- You can refer documentation and Man pages by executing
- After installation, you can remove the binary and source files using the command
- If you are going to build on a distributed platform with the same source tree, you can make use of the command :
This will help in propagating the changes altogether in all distributed platforms before rebuilding.
This has been a guide on how to Install PostgreSQL. Here we have discussed steps to install PostgreSQL on a different operator. You may also look at the following articles to learn more –