Linux centos7安装postgresql12

it2025-12-27  6

一、安装包下载

官网地址:https://www.postgresql.org/

下载地页面:https://www.postgresql.org/download/linux/redhat/

本文介绍离线安装,即介绍centos7不能上网时的安装方法,如果centos7能上网,请自行搜索yum安装方法。

离线安装首先需要在能上网的电脑将安装包下载下来,然后复制到centos上安装。

首先,在一台能上网的电脑上进入上面的下载地页面后,滑到最下,依次点击以下:

依次进入下图这个4个里面,把rpm包下载下来。

最后,将上面下载的rpm包复制到centos7上。

二、安装

1、CentOS上依次安装RPM包,注意顺序

rpm -ivh postgresql12-libs-12.4-1PGDG.rhel7.x86_64.rpm rpm -ivh postgresql12-12.4-1PGDG.rhel7.x86_64.rpm rpm -ivh postgresql12-server-12.4-1PGDG.rhel7.x86_64.rpm rpm -ivh postgresql12-contrib-12.4-1PGDG.rhel7.x86_64.rpm

2、初始化数据库:

[root@localhost ~] /usr/pgsql-12/bin/postgresql-12-setup initdb

3、配置开机启动与启动:

[root@localhost ~] systemctl enable postgresql-12 [root@localhost ~] systemctl start postgresql-12

4、修改密码:

首先,切换到postgres用户。然后执行修改用户密码SQL语句。其中“postgres”为要修改密码的用户,“123456”为用户的密码。

[root@localhost ~] su - postgres bash-4.2$ psql -c "alter user postgres with password '123456'"

5、修改配置文件:

打开并编辑文件“/var/lib/pgsql/12/data/postgresql.conf”。将“#listen_addresses = ‘localhost’”改为“listen_addresses = ‘*’” 打开并编辑文件“/var/lib/pgsql/12/data/pg_hba.conf”。在文件的末尾添加“host all all 0.0.0.0/0 md5”。

6、安装Python3支持包:

如果不需要数据库Python3支持,则忽略该步骤。

[root@localhost ~] yum install postgresql12-plpython3

要使用python扩展,需要打开数据库,执行如下SQL语句。

CREATE extension plpython3u;

 

最新回复(0)