It dates back to 1986 as part of the POSTGRES project at the University of California, Berkeley, and carries 30 years of active development on its core platform. Its consistent performance over the years has proved its integrity, architecture, and extensibility for enterprise use. It is ACID-compliant and offers support for powerful addons like the popular PostGIS geospatial database extender. We’re going to cover the installation of PostgreSQL on common platforms in this article. So let’s get started.

Ubuntu

PostgreSQL is available for all flavors and versions of Ubuntu. You have got the choice to install and use the version available by default with your version of Ubuntu and supported for its lifetime or to use a specific version by adding the PostgreSQL repository and installing the same. We’ll be covering both options here. To use the default supported version provided by Ubuntu’s repository, run: PostgreSQL Apt Repository supports the current LTS versions of Ubuntu, i.e., 20.04, 18.04 and 16.04. Though it may not be fully supported, the same packages work on non-LTS versions as well by using the closest LTS version. To use PostgreSQL apt repository, follow these steps: To install a specific version from the PostgreSQL repository, instead of just postgresql which refers to the latest version, specify it like postgresql-12: The repository also contains different packages, including third-party addons. For example, commonly available packages for version 12 of PostgreSQL includes: Once installation completes, you can check the status of DB service by using the below command: For Ubuntu, post-installation, the service should be enabled and running like:

CentOS

Like Ubuntu, RHEL/CentOS repositories also contain a specific version of PostgreSQL, which is supported through the lifetime for the OS. You can install the same using: or you can use DNF if using CentOS 8. Run below commands post-installation to initialize DB, enable the PostgreSQL service, and start it: Or to use the packages directly from PostgreSQL yum repositories, we have to add the repository as: And then to install a specific version of PostgreSQL like version 13, which is the latest stable release at the time of writing this article, use: yum repository also contains additional packages for PostgreSQL, out of which some of the important ones are listed below: Run below steps post-installation to initialize DB, enable the PostgreSQL service, and start it: You can check the status of the DB service by using the below command:

Windows

Windows 32-bit and 64-bit installers are available from the official PostgreSQL site here.

You can download the applicable binary based on the required version and architecture.

We’ll be downloading the latest version available, which is v13.3 for Windows 64-bit platform. Once the download completes, launch the installer by double-clicking on it.

Click Next to proceed.

Click Next to continue with the default path or specify your custom installation path.

You can keep the default components selected and click Next to proceed.

Next, it asks for the data directory location; this can be kept as the default unless you have a separate dedicated disk or directory assigned for it. Click Next to proceed.

Specify a strong password that will be assigned to postgres user. Click Next when done.

Default port 5432 should be good for most cases. Click Next to go to the next page.

Select the locale for the DB and click Next to continue.

All the selected settings for the installation wizard will be listed for you to review and confirm. If anything needs to be changed, go back and change the same or click Next to proceed to the next page.

Setup will show that it’s ready to proceed with the installation. When ready, click Next to start the installation.

Wait for the installation to complete. A confirmation will be shown for the same.

Once completed, you can uncheck Stack Builder and click Finish to exit from the installation wizard. Click on Start Menu and search for SQL Shell (psql) and click on its icon to open the psql shell.

SQL Shell (psql) opens up where you can interact with your PostgreSQL instance after specifying the connection details. All of the items can be selected as the default by simply pressing Enter except for the password, where you need to input the password specified for postgres user during the installation wizard. This will land you in postgres=# prompt.

Connect to PostgreSQL

A postgres user gets created automatically post-installation, which has superadmin access to the DB instance. On Linux, as a privileged user, you can switch to this account as: Once in, we can reset postgres user password as: And then launch PostgreSQL prompt with psqlas: This will land you inside PostgreSQL prompt: At this prompt, you can interact with the database and do DB admin or user tasks. As a demo, the below steps create a DB and a user and then assign privileges to the new user to work on the new database: We can then list the DBs using \l command: Now you can simply connect to a DB using:

Summary

PostgreSQL is one of the widely adopted databases in the enterprise world because of its robustness, feature set, and scalability. It’s easy to learn and tries to be compatible with SQL standards. There’s a tutorial available for PostgreSQL on its official site.

How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 78How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 44How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 99How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 35How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 77How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 41How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 61How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 5How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 49How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 86How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 35How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 88How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 14How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 59How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 72How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 8How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 29How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 85How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 21How to Install PostgreSQL on Ubuntu  CentOS and Windows  - 42