How to install PostgreSQL on Linux Cloud Servers

2020-11-04 By Mark 63 Views linux postgresql development
0 reviews

PostgreSQL is a highly scalable, powerful free open-source relational database management system that runs on operating systems such as Unix, including Linux and Windows OS. It is an enterprise level database system that offers high levels of resistance, integrity and accuracy.


This article will guide you how to install the PostgreSQL on CentOS, Ubuntu & Debian servers.


CentOS


  1. Run the below command to add PostgreSQL Yum Repository and it will combine with your Linux system and offers automatic updates for all supported versions of PostgreSQL on your CentOS server.

    # yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
    

    postgresql1

  2. Once added the PostgreSQL yum repository, then run the below command to install the PostgreSQL on your server.

    # yum install postgresql-server postgresql
    

    postgresql2

  3. Initialize PostgreSQL Database to complete the database installation.

    # postgresql-setup initdb
    

    postgresql3

  4. Once the database initialize completed, then run the below commands to start, enable and check the status of PostgreSQL.

    # systemctl start postgresql
    
    # systemctl enable postgresql
    
    # systemctl status postgresql
    

    postgresql4

  5. Run the below command to verify the installation.

    # su - postgres
    

    postgresql5

  6. You can use the below command to change the password for user postgres for security purpose.

    # postgres=# \password postgres
    

    postgresql6


Ubuntu / Debian


  1. Run the below commands to add PostgreSQL Repository and it will combine with your Linux system and offers automatic updates for all supported versions of PostgreSQL on your Ubuntu server.


    Import the GPG repository key with the below commands:

    # apt-get install wget ca-certificates
    
    # wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
    

    postgresql7

    postgresql8

  2. Add the PostgreSQL repository by using the below command.

    # sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
    

    postgresql9

  3. Now update the server to effect the changes.

    # apt-get update
    

    postgresql10

  4. Once added the PostgreSQL repository and updated the server, then run the below commmand to install the PostgreSQL on your server.

    # apt-get install postgresql postgresql-contrib
    

    postgresql11

  5. Once the installation completed, then run the below commands to start, enable and check the status of PostgreSQL.

    # service postgresql start
    
    # service postgresql enable
    
    # service postgresql status
    

    postgresql12

  6. Run the below command to access PostgreSQL and launch the postgres shell program.

    # sudo -i -u postgres
    
    # psql
    

    postgresql13

  7. You can use the below command to change the password for user postgres for security purpose.

    # postgres=# \password postgres
    

    postgresql14

  8. Run the below command from the postgres shell to check the details of the connection.

    # \conninfo
    

    postgresql15


Related Tutorials

What do you think about this article?

Rate this article