How to Install PostgreSQL on Linux

  Installation of PostgreSQL on Linux

In this article, you will learn how to install PostgreSQL on Linux using rpm packages. Most Linux platforms such as Debian, Oracle Linux, Red Hat / CentOS, SUSE, and Ubuntu have PostgreSQL integrated with their package management.

It is recommended that you install PostgreSQL this way since it ensures a proper integration with the operating system including automatic patching and other update management functionality.

In this tutorial, we’ll show you how to install PostgreSQL on Oracle Linux version 8.2

Installation using RPMS:

Below URL can be used to download rpms of PostgreSQL version 15.1 for Linux platforms.

https://download.postgresql.org/pub/repos/yum/15/redhat/rhel-8.2-x86_64/

For smooth installation, below listed rpms are required:

  • postgresql15-devel-15.1-1PGDG.rhel8.x86_64.rpm 
  • postgresql15-contrib-15.1-1PGDG.rhel8.x86_64.rpm 
  • postgresql15-libs-15.1-1PGDG.rhel8.x86_64.rpm
  • postgresql15-server-15.1-1PGDG.rhel8.x86_64.rpm 
  • postgresql15-15.1-1PGDG.rhel8.x86_64.rpm   

Ship these rpms to server where Linux is already installed. 
Now is the time to do the actual PostgreSQL installation. This will install the latest PostgreSQL version.
  1. Install libs rpm first as below::
    yum localinstall /tmp/postgresql15-libs-15.1-1PGDG.rhel8.x86_64.rpm

      2. Next, install PGDG package using below command:
    yum localinstall /tmp/postgresql15-15.1-1PGDG.rhel8.x86_64.rpm   

      3. At third step server package can be installed as below
   yum localinstall /tmp/postgresql15-server-15.1-1PGDG.rhel8.x86_64.rpm 
      4. Now devel package will be installed
    yum localinstall /tmp/postgresql15-devel-15.1-1PGDG.rhel8.x86_64.rpm 
      5. And at the last step, contrib package can be installed for additional extensions as below:
    yum localinstall /tmp/postgresql15-contrib-15.1-1PGDG.rhel8.x86_64.rpm 

      6. Once all rpm pacages are installed successfully, you can now safetly initialize PostgreSQL database using below command:

/usr/pgsql-15/bin/postgresql-15.1-setup initdb

     7. Next, start the PostgreSQL service and enable it to start at system reboot with the following command:

systemctl start postgresql-15.1

systemctl enable postgresql-15.1

    8. You can check the status of PostgreSQL with the following command:

systemctl start postgresql-15.1

    9. By default, PostgreSQL listens on port 5432. You can check it with the following command:

netstat -tulnp |grep 5432

Once installation is complete, you can access it using pgAdmin tool and any other GUI based tool like dbeaver.

For connecting it remotely, some configurations are required. Like changes in postgresql.conf file and pg_hba.conf files which by default can be found in "/var/lib/pgsql/15/data" directory.

Edit postgresql.conf file and comment listen_address directive and add new line as below:

listen_address='IP_ADDR_PG_SERVER"

Edit pg_hba.conf and add below lines:

host    all    postgres    CLIENT_IP_ADDR    trust

For making these changes effective, restart postgresql service as below:

systemctl restart postgresql-15.1

Now you can connect to your postgresql database using pgAdmin tool from your client machine


<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6554968143327802"
     crossorigin="anonymous"></script>

Comments

Popular posts from this blog

Ora2pg Mirgation Tool

Oracle vs PostgreSQL Comparison