Postgresql install linux yum

Установка и запуск PostgreSQL на CentOS

Обновлено

Обновлено: 03.09.2021 Опубликовано: 30.05.2017

Тематические термины: PostgreSQL, CentOS Данная инструкция написана на примере систем CentOS 7 и 8, а также PostgreSQL 9/10 (из коробки) или любой другой версии (настройка репозитория).

Установка

PostgreSQL 9/10 В зависимости от версии операционной системы, из коробки будет установлена версия 9.2 (CentOS 7) или 10 (CentOS 8). Просто вводим команду:

PostgreSQL > 9.2 Для установки более свежей версии PostgreSQL на CentOS необходимо подключить репозиторий:

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-`rpm -E %`-x86_64/pgdg-redhat-repo-latest.noarch.rpm

Установка PostgreSQL в CentOS 8 осуществлена через модульные репозитории, что помешает нам — отключаем их командой:

* в данном примере будет установлен postgresql версии 11.
** система проверит репозиторий на наличие нужного пакета и задаст запрос на подтверждение установки программы — отвечаем Y.

Запуск

  1. Инициализировать базу. Это делается с помощью утилиты postgresql-setup с ключом initdb.
  2. Разрешить автозапуск сервиса.
  3. Стартовать службу.

В зависимости от версии postgresql, эти операции выполняются, немного, по-разному.

Источник

Linux downloads (Red Hat family)

PostgreSQL is available on these platforms by default. However, each version of the platform normally «snapshots» a specific version of PostgreSQL that is then supported throughout the lifetime of this platform. Since this can often mean a different version than preferred, the PostgreSQL project provides a repository of packages of all supported versions for the most common distributions.

PostgreSQL Yum Repository

The PostgreSQL Yum Repository will integrate with your normal systems and patch management, and provide automatic updates for all supported versions of PostgreSQL throughout the support lifetime of PostgreSQL.

The PostgreSQL Yum Repository currently supports:

  • Red Hat Enterprise Linux
  • Rocky Linux
  • CentOS (7 and 6 only)
  • Oracle Linux
  • Fedora *

* Note: due to the shorter support cycle on Fedora, all supported versions of PostgreSQL are not available on this platform. We do not recommend using Fedora for server deployments.

To use the PostgreSQL Yum Repository, follow these steps:

  1. Select version:
  2. Select platform:
  3. Select architecture:
  4. Copy, paste and run the relevant parts of the setup script:

Included in Distribution

These distributions all include PostgreSQL by default. To install PostgreSQL from these repositories, use the yum command on RHEL 6 and 7:

yum install postgresql-server

or dnf command on RHEL 8 and Fedora:

dnf install postgresql-server

Which version of PostgreSQL you get will depend on the version of the distribution:

Distribution Version
RHEL / Rocky Linux 9 13
RHEL / Rocky Linux / OL 8 13, 12, 10 and 9.6 via modules
RHEL / CentOS / SL / OL 7 9.2 (also supplies package rh-postgresql10, rh-postgresql96, rh-postgresql95 and rh-postgresql94 via SCL)
RHEL / CentOS / SL / OL 6 8.4 (also supplies package rh-postgresql96, via SCL)
Fedora 37 14
Fedora 36 14

Other Red Hat family distributions may ship a different version of PostgreSQL by default, check with your distribution vendor to be sure.

The repository contains many different packages including third party addons. The most common and important packages are (substitute the version number as required):

postgresql-client libraries and client binaries
postgresql-server core database server
postgresql-contrib additional supplied modules
postgresql-devel libraries and headers for C language development

Post-installation

Due to policies for Red Hat family distributions, the PostgreSQL installation will not be enabled for automatic start or have the database initialized automatically. To make your database installation complete, you need to perform the following steps, based on your distribution:

For RHEL / Rocky Linux / CentOS / SL / OL 7, 8, 9 or Fedora 36 and later derived distributions:

postgresql-setup --initdb systemctl enable postgresql.service systemctl start postgresql.service

For RHEL / CentOS / SL / OL 6

service postgresql initdb chkconfig postgresql on

Direct RPM download

If you cannot, or do not want to, use the yum based installation method, all the RPMs that are in the yum repository are available for direct download and manual installation as well.

Copyright © 1996-2023 The PostgreSQL Global Development Group

Источник

How To Install PostgreSQL 15 on Centos 7

Install PostgreSQL 15 on Centos 7

In this guide, we want to teach you How To Install PostgreSQL 15 on Centos 7.

PostgreSQL 15 contains many new features and enhancements, including:

  • Support for the SQL MERGE command.
  • Selective publication of tables’ contents within logical replication publications, through the ability to specify column lists and row filter conditions.
  • More options for compression, including support for Zstandard (zstd) compression. This includes support for performing compression on the server side during pg_basebackup.
  • Support for structured server log output using the JSON format.
  • Performance improvements, particularly for in-memory and on-disk sorting.

Steps To Install PostgreSQL 15 on Centos 7

To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Centos 7.

Set up PostgreSQL 15 on Centos 7

To install PostgreSQL 15, you must add the PostgreSQL 15 repository on your server.

First, install Epel Repository on Centos 7 by using the command below:

sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Then, install the required packages:

sudo yum install libzstd-devel

Add PostgreSQL 15 Repository on Centos 7

At this point, you can use the command below to add the latest PostgreSQL repository on your server:

sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

Then, update your local package index with the following command:

Install PostgreSQL 15 on Centos 7

First, you need to install Epel Repo

At this point, you can use the following command to install PostgreSQL 15 on your Centos 7 server:

sudo yum install -y postgresql15-server 

when your installation is completed, verify it by checking its version:

In your output you will see:

Output psql (PostgreSQL) 15.0 

Initialize PostgreSQL 15 Database

At this point, you need to initialize the initdb database which is responsible for creating a new PostgreSQL cluster . A cluster is a group or collection of several databases that are managed by a cluster.

To do this, run the following command:

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

When it is finished, you will get the following output:

Output Initializing database . OK

Manage PostgreSQL 15 Service

At this point, you can start and enable your PostgreSQL 15 on Centos 7. To do this, run the commands below:

# sudo systemctl enable postgresql-15 # sudo systemctl start postgresql-15

Verify your PostgreSQL 15 is active and running on your server with the command below:

sudo systemctl status postgresql-15
Output ● postgresql-15.service - PostgreSQL 15 database server Loaded: loaded (/usr/lib/systemd/system/postgresql-15.service; enabled; vendor preset: disabled) Active: active (running) since Sun 2022-10-30 09:26:56 EDT; 14s ago Docs: https://www.postgresql.org/docs/15/static/ Process: 8563 ExecStartPre=/usr/pgsql-15/bin/postgresql-15-check-db-dir $ (code=exited, status=0/SUCCESS) Main PID: 8569 (postmaster) CGroup: /system.slice/postgresql-15.service . 

Connect To PostgreSQL 15 Shell on Centos 7

PostgreSQL uses a concept called roles to handle authentication and authorization.

During the PostgreSQL installation, Postgres is set up to use ident authentication, meaning that it associates Postgres roles with a matching Unix/Linux system account.

If a role exists within Postgres, a Unix/Linux username with the same name is able to sign in as that role.

One way is to switch over to the Postgres account on your server by running the following command:

Output -bash-4.2$ 

You can access the Postgres 15 shell on Centos 7 by running the following command:

-bash-4.2$ psql

With this command, you will see that your shell prompt changes to:

Output psql (15.0) Type "help" for help. postgres=#

To exit from the PostgreSQL 15 shell on Centos 7, run the following command:

With this command, you will be back to the Postgres Linux command prompt.

You can type exit to return to the regular system user.

Also, you can connect to your Postgres shell on Centos 7 in another way by typing the following command:

In this way, you will directly connect to your PostgreSQL 15 shell.

Output psql (15.0) Type "help" for help. postgres=#

Create a new PostgreSQL 15 Role

At this point, you can create a new Postgres role in two ways.

First, if you are logged in as a Postgres account, you can use the following command:

-bash-4.2$ createuser --interactive

Second, you can use sudo for each command without switching from your normal account on Centos 7:

sudo -u postgres createuser --interactive

Both ways will be asked to enter your role name and whether the new role is a superuser or not.

Output Enter name of role to add: orca Shall the new role be a superuser? (y/n) y

Create a new PostgreSQL 15 Database

The Postgres authentication system for any role used to log in, the role should have a database with the same name which it can access.

If you logged in as the Postgres account, run the following command to create the database with the name of the role you have created in the previous step:

-bash-4.2$ createdb orca

Or you can use sudo to create the database on Centos 7:

sudo -u postgres createdb orca

Open the Postgres 15 Shell with the new Role

At this point, you need to create a Linux user with the same name as your Postgres role and database. To do this, run the following command:

sudo adduser orca

Now you can connect to the Postgres database with the following commands:

Or you can use the following command instead:

Output psql (15.0) Type "help" for help. orca=#

When you have logged in to your PostgreSQL database on Centos 7, you can check your current connection information by running the following command:

In your output you will see:

Output You are connected to database "orca" as user "orca" via socket in "/var/run/postgres

For more information, you can visit the PostgreSQL Documentation page.

Conclusion

At this point, you have learned to Install PostgreSQL 15 on Centos 7.

You may be like these articles:

Источник

Читайте также:  Alt linux root password
Оцените статью
Adblock
detector