在CentOS 8上安装PostgreSQL

时间:2020-07-27 12:58:43  来源:igfitidea点击:

在本教程中,我们将学习如何在CentOS 8/RHEL 8上安装PostgreSQL。

PostgreSQL 13是最新版本,我们可以通过在命令提示符下运行以下SET命令作为root来安装在CentOS上的最新版本:

sudo dnf -qy module disable postgresql
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo dnf install -y postgresql13-server

我们已在CentOS计算机上成功安装PostgreSQL。
现在运行以下开始并启用CentOS'PostgreSQL的服务:

sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13

过程说明

带有CentOS默认软件存储库的PostgreSQL版本。

但是,它不是最新版本。
要获得最新版本,我们需要设置PostgreSQL DNF存储库。

我们通过禁用默认PostgreSQL包启动:

sudo dnf -qy module disable postgresql

接下来,我们通过运行以下命令安装了DNF存储库:

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

要安装PostgreSQL 13,我们执行以下命令:

sudo dnf install -y postgresql13-server

有几种不同版本的PostgreSQL可用。
我们可以运行以下命令以获取所有可用版本的列表:

dnf search postgresql | grep -i server

了解群集

在安装期间创建了一个名为“postgres”的新Linux用户。
此Linux用户是Postgres集群的超级用户。

“postgres”用户没有密码,因此我们需要使用root权限登录用户帐户,如下所示:

su - postgres

“postgres”用户可以使用没有密码的“psql”命令登录Postgres shell。

PostgreSQL 13已安装到'/var/lib/pgsql/13'目录。
'/var/lib/pgsql/13/data/postgresql.conf'是CentOS 8 PostgreSQL 13集群的主要配置文件。

在'/var/lib/pgsql/13/data'目录中,'/base /'目录是实际存储所有数据库的位置。