Linux|centos7|postgresql数据库|yum和编译方式安装总结(全系版本)

本文主要是介绍Linux|centos7|postgresql数据库|yum和编译方式安装总结(全系版本),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、

yum方式安装postgresql

这个是官方的yum源,包括postgresql的开发包,lib库什么的,很齐全,关键是包括pgbackrest

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

以上这个命令呢,其实没有安装什么太多的东西,就是在/etc/yum.repos.d目录下生成了一个repo文件而已,该repo文件内容如下:

#######################################################
# PGDG Red Hat Enterprise Linux / CentOS repositories #
######################################################## PGDG Red Hat Enterprise Linux / CentOS stable common repository for all PostgreSQL versions[pgdg-common]
name=PostgreSQL common RPMs for RHEL / CentOS $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/common/redhat/rhel-$releasever-$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1# We provide extra package to support some RPMs in the PostgreSQL RPM repo, like
# consul, haproxy, etc.[pgdg-rhel7-extras]
name=Extra packages to support some RPMs in the PostgreSQL RPM repo RHEL / CentOS $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/common/pgdg-rhel$releasever-extras/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1# PGDG Red Hat Enterprise Linux / CentOS stable repositories:[pgdg15]
name=PostgreSQL 15 for RHEL / CentOS $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/15/redhat/rhel-$releasever-$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg14]
name=PostgreSQL 14 for RHEL / CentOS $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/14/redhat/rhel-$releasever-$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg13]
name=PostgreSQL 13 for RHEL / CentOS $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/13/redhat/rhel-$releasever-$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg12]
name=PostgreSQL 12 for RHEL / CentOS $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/12/redhat/rhel-$releasever-$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1# PGDG RHEL / CentOS Updates Testing common repositories.[pgdg-common-testing]
name=PostgreSQL common testing RPMs for RHEL / CentOS $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/testing/common/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1# PGDG RHEL / CentOS Updates Testing repositories. (These packages should not be used in production)
# Available for 12 and above.[pgdg15-updates-testing]
name=PostgreSQL 15 for RHEL / CentOS $releasever - $basearch - Updates testing
baseurl=https://download.postgresql.org/pub/repos/yum/testing/15/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg14-updates-testing]
name=PostgreSQL 14 for RHEL / CentOS $releasever - $basearch - Updates testing
baseurl=https://download.postgresql.org/pub/repos/yum/testing/14/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg13-updates-testing]
name=PostgreSQL 13 for RHEL / CentOS $releasever - $basearch - Updates testing
baseurl=https://download.postgresql.org/pub/repos/yum/testing/13/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg12-updates-testing]
name=PostgreSQL 12 for RHEL / CentOS $releasever - $basearch - Updates testing
baseurl=https://download.postgresql.org/pub/repos/yum/testing/12/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1# PGDG Red Hat Enterprise Linux / CentOS SRPM testing common repository[pgdg-source-common]
name=PostgreSQL 12 for RHEL / CentOS $releasever - $basearch - Source
baseurl=https://download.postgresql.org/pub/repos/yum/srpms/common/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1# PGDG RHEL / CentOS testing common SRPM repository for all PostgreSQL versions[pgdg-common-srpm-testing]
name=PostgreSQL common testing SRPMs for RHEL / CentOS $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/srpms/testing/common/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1# PGDG Source RPMs (SRPM), and their testing repositories:[pgdg15-source]
name=PostgreSQL 15 for RHEL / CentOS $releasever - $basearch - Source
failovermethod=priority
baseurl=https://download.postgresql.org/pub/repos/yum/srpms/15/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg15-source-updates-testing]
name=PostgreSQL 15 for RHEL / CentOS $releasever - $basearch - Source updates testing
failovermethod=priority
baseurl=https://download.postgresql.org/pub/repos/yum/srpms/testing/15/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg14-source]
name=PostgreSQL 14 for RHEL / CentOS $releasever - $basearch - Source
failovermethod=priority
baseurl=https://download.postgresql.org/pub/repos/yum/srpms/14/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg14-source-updates-testing]
name=PostgreSQL 14 for RHEL / CentOS $releasever - $basearch - Source updates testing
failovermethod=priority
baseurl=https://download.postgresql.org/pub/repos/yum/srpms/testing/14/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg13-source]
name=PostgreSQL 13 for RHEL / CentOS $releasever - $basearch - Source
failovermethod=priority
baseurl=https://download.postgresql.org/pub/repos/yum/srpms/13/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg13-source-updates-testing]
name=PostgreSQL 13 for RHEL / CentOS $releasever - $basearch - Source updates testing
failovermethod=priority
baseurl=https://download.postgresql.org/pub/repos/yum/srpms/testing/13/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg12-source]
name=PostgreSQL 12 for RHEL / CentOS $releasever - $basearch - Source
failovermethod=priority
baseurl=https://download.postgresql.org/pub/repos/yum/srpms/12/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg12-source-updates-testing]
name=PostgreSQL 12 for RHEL / CentOS $releasever - $basearch - Source update testing
failovermethod=priority
baseurl=https://download.postgresql.org/pub/repos/yum/srpms/testing/12/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1# Debuginfo/debugsource packages for stable repos[pgdg15-debuginfo]
name=PostgreSQL 15 for RHEL / CentOS $releasever - $basearch - Debuginfo
baseurl=https://download.postgresql.org/pub/repos/yum/debug/15/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg14-debuginfo]
name=PostgreSQL 14 for RHEL / CentOS $releasever - $basearch - Debuginfo
baseurl=https://download.postgresql.org/pub/repos/yum/debug/14/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg13-debuginfo]
name=PostgreSQL 13 for RHEL / CentOS $releasever - $basearch - Debuginfo
baseurl=https://download.postgresql.org/pub/repos/yum/debug/13/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg12-debuginfo]
name=PostgreSQL 12 for RHEL / CentOS $releasever - $basearch - Debuginfo
baseurl=https://download.postgresql.org/pub/repos/yum/debug/12/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1# Debuginfo/debugsource packages for testing repos
# Available for 12 and above.[pgdg15-updates-testing-debuginfo]
name=PostgreSQL 15 for RHEL / CentOS $releasever - $basearch - Debuginfo
baseurl=https://download.postgresql.org/pub/repos/yum/testing/debug/15/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg14-updates-testing-debuginfo]
name=PostgreSQL 14 for RHEL / CentOS $releasever - $basearch - Debuginfo
baseurl=https://download.postgresql.org/pub/repos/yum/testing/debug/14/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg13-updates-testing-debuginfo]
name=PostgreSQL 13 for RHEL / CentOS $releasever - $basearch - Debuginfo
baseurl=https://download.postgresql.org/pub/repos/yum/testing/debug/13/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1[pgdg12-updates-testing-debuginfo]
name=PostgreSQL 12 for RHEL / CentOS $releasever - $basearch - Debuginfo
baseurl=https://download.postgresql.org/pub/repos/yum/testing/debug/12/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
repo_gpgcheck = 1

🆗,查看这个repo文件,可以看到postgresql  12-15版本都有了,那么,postgresql数据库所有都安装,比如,lib库,开发库都安装的命令就是:

yum install postgresql12*

但此时会报错,缺少很多个核心依赖,比如llvm5.0-devel,python3-libs:

Error: Package: postgresql12-plpython3-12.18-1PGDG.rhel7.x86_64 (pgdg12)Requires: libpython3.6m.so.1.0()(64bit)
Error: Package: postgresql12-devel-12.18-1PGDG.rhel7.x86_64 (pgdg12)Requires: llvm-toolset-7-clang >= 4.0.1
Error: Package: postgresql12-llvmjit-12.18-1PGDG.rhel7.x86_64 (pgdg12)Requires: libLLVM-5.0.so()(64bit)
Error: Package: postgresql12-llvmjit-12.18-1PGDG.rhel7.x86_64 (pgdg12)Requires: llvm5.0 >= 5.0
Error: Package: postgresql12-devel-12.18-1PGDG.rhel7.x86_64 (pgdg12)Requires: llvm5.0-devel >= 5.0
Error: Package: postgresql12-plpython3-12.18-1PGDG.rhel7.x86_64 (pgdg12)Requires: python3-libs
Error: Package: postgresql12-devel-12.18-1PGDG.rhel7.x86_64 (pgdg12)Requires: perl(IPC::Run)You could try using --skip-broken to work around the problemYou could try running: rpm -Va --nofiles --nodigest

解决方案为增加阿里云的epel源和centos的scl源:

wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum install centos-release-scl-rh

阿里云的epel源和阿里云的基础源就不介绍了,主要是scl源, SCL是Software Collections的缩写,由CentOS 特别兴趣小组所维护。其收录了许多程序的新版本,例如gcc, PHP, git, python等。安装的软件可与旧版共存,包名多以rh-为前缀;它的repo文件 CentOS-SCLo-scl-rh.repo 内容如下:

# CentOS-SCLo-rh.repo
#
# Please see http://wiki.centos.org/SpecialInterestGroup/SCLo for more
# information[centos-sclo-rh]
name=CentOS-7 - SCLo rh
#baseurl=http://mirror.centos.org/centos/7/sclo/$basearch/rh/
mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-rh
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo[centos-sclo-rh-testing]
name=CentOS-7 - SCLo rh Testing
baseurl=http://buildlogs.centos.org/centos/7/sclo/$basearch/rh/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo[centos-sclo-rh-source]
name=CentOS-7 - SCLo rh Sources
baseurl=http://vault.centos.org/centos/7/sclo/Source/rh/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo[centos-sclo-rh-debuginfo]
name=CentOS-7 - SCLo rh Debuginfo
baseurl=http://debuginfo.centos.org/centos/7/sclo/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

如果觉得这个源的速度比较慢,可以使用国内的清华源,上述的repo文件内容修改为如下即可:

[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/sclo/$basearch/sclo/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/sclo/$basearch/rh/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

🆗,这四个源配置好后就可以非常方便的安装postgresql  12-15的版本了

那么,如果是有网的环境还可以,但如果是离线环境呢?这个也比较简单的,制作离线yum源就可以了

二、

yum 离线源的制作

以上面配置的四个yum源为基础,制作yum离线源,首先,需要创建一个任意名称的目录,存放一会拉取下来的rpm文件

其次,安装yum-utils ,以生成yumdownloader 这个工具,然后进入上面创建的目录 ,拉取rpm文件

最后,就是安装createrepo 这个工具,生成仓库信息

以上步骤都完成后,打包上述目录就可以扔到离线环境使用了,本文就以postgresql-12的离线yum安装包制作为例

安装离线yum源的rpm包下载工具

 yum install yum-utils -y

开始下载rpm包,等待下载完毕:

    mkdir postgresql-12-offlinecd postgresql-12-offlineyumdownloader postgresql12* pgbackrest --resolve

开始制作离线仓库:

  yum install createrepo -ycd postgresql-12-offline/yumdownloader createrepo --resolveyumdownloader deltarpm-3.6-3.el7.x86_64 python-deltarpm-3.6-3.el7.x86_64 deltarpm-3.6-3.el7.x86_64 python-deltarpm-3.6-3.el7.x86_64 --resolvecreaterepo postgresql-12-offline/
cd ..
tar cvjf postgresql-12-offline.tar.gz postgresql-12-offline

制作完毕后,tar包保存后,在其它服务器上挂载这个仓库就可以离线安装postgresql12和pgbackrest了,挂载示例如下:

1、

上述的离线包上传到服务器上,然后解压,解压后的目录移动到/opt目录下

[root@centos7 ~]# tar xf postgresql-12-offline.tar.gz 
[root@centos7 ~]# du -sh postgresql-12-offline
292M	postgresql-12-offline
[root@centos7 ~]# mv postgresql-12-offline /opt/

2、

保留本地yum源,在本地yum内编辑如下内容:

[local]
nmae=local
baseurl=file:///mnt/
enable=1
gpgcheck=0
[pgoffline]
name=pgoffline
baseurl=file:///opt/postgresql-12-offline
enable=1
gpgcheck=0

3、

安装postgresql-12

[root@centos7 ~]# yum install postgresql12-server postgresql12-lib postgresql12-devel postgresql12-contrib postgresql12-tcl postgresql12-odbc-y

4、

安装pgbackrest

[root@centos7 ~]# yum install pgbackrest -y

以上就是离线安装postgresql12的过程,其它版本的postgresql基本是一样的,yumdownload 后面的版本改一下就可以了

下面说一说数据库初始化以及简单的配置问题

三、

postgresql12-server的初始化和简单配置

1、

创建postgresql的数据存储目录

mkdir -p /data/pgsql/data

2、

配置环境变量,这些变量用于初始化,一般写入/etc/profile 或者 /etc/bashrc 这两个文件的末尾,任选一个就可以了

PGDATA=/data/pgsql/data
export PGDATA
PGHOME=/data/pgsql
export PGHOME
PATH=$PATH:$PGHOME/bin:$PGDATA
export PATH  PGHOME PGDATA

3、

postgresql数据库初始化

[root@centos7 system]# /usr/pgsql-12/bin/postgresql-12-setup initdb
Initializing database ... OK

4、

移动刚初始化的数据文件到/data/pgsql/data目录下,并更改配置文件和启动脚本:

vim /data/pgsql/data/postgresql.conf
主要是以下几项:
data_directory = '/data/pgsql/data'
listen_addresses = '*' 
port = 5432                       
max_connections = 100 vim /usr/lib/systemd/system/postgresql-12.service
主要是这个:
Environment=PGDATA=/data/pgsql/data/

5、

重新赋权,然后启动数据库

chown -Rf postgres. /data/pgsql/
chmod -Rf 0750 /data/pgsql/data/
systemctl daemon-reload
systemctl start postgresql-12 &&systemctl enable postgresql-12

6、

查看数据库状态是否正常:

[root@centos7 data]# systemctl status postgresql-12
● postgresql-12.service - PostgreSQL 12 database serverLoaded: loaded (/usr/lib/systemd/system/postgresql-12.service; enabled; vendor preset: disabled)Active: active (running) since Sun 2024-03-17 05:07:42 CST; 5min agoDocs: https://www.postgresql.org/docs/12/static/Main PID: 2066 (postmaster)CGroup: /system.slice/postgresql-12.service├─2066 /usr/pgsql-12/bin/postmaster -D /data/pgsql/data/├─2067 postgres: logger   ├─2069 postgres: checkpointer   ├─2070 postgres: background writer   ├─2071 postgres: walwriter   ├─2072 postgres: autovacuum launcher   ├─2073 postgres: stats collector   └─2074 postgres: logical replication launcher   Mar 17 05:07:42 centos7 systemd[1]: Starting PostgreSQL 12 database server...
Mar 17 05:07:42 centos7 postmaster[2066]: 2024-03-17 05:07:42.320 CST [2066] LOG:  starting PostgreSQL 12.18 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
Mar 17 05:07:42 centos7 postmaster[2066]: 2024-03-17 05:07:42.320 CST [2066] LOG:  listening on IPv4 address "0.0.0.0", port 5432
Mar 17 05:07:42 centos7 postmaster[2066]: 2024-03-17 05:07:42.320 CST [2066] LOG:  listening on IPv6 address "::", port 5432
Mar 17 05:07:42 centos7 postmaster[2066]: 2024-03-17 05:07:42.321 CST [2066] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
Mar 17 05:07:42 centos7 postmaster[2066]: 2024-03-17 05:07:42.321 CST [2066] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
Mar 17 05:07:42 centos7 postmaster[2066]: 2024-03-17 05:07:42.327 CST [2066] LOG:  redirecting log output to logging collector process
Mar 17 05:07:42 centos7 postmaster[2066]: 2024-03-17 05:07:42.327 CST [2066] HINT:  Future log output will appear in directory "log".
Mar 17 05:07:42 centos7 systemd[1]: Started PostgreSQL 12 database server.

yum安装的postgresql,数据库日志是直接开启的,省去了不少麻烦,剩下的就是配置pg_hba.conf 文件开启安全访问这些了,就不在此废话了

注意:由于前面安装了postgresql12-contrib,因此,所有官方插件是可以直接使用的,非常的方便,例如pg_trgm 这个插件,就可以直接安装了:

psql (12.18)
Type "help" for help.postgres=# create extension pg_trgm;
CREATE EXTENSION

查询有哪些可用插件:

SELECT name FROM pg_available_extensions;

输出如下:

hstore
plpgsql
hstore_plperl
adminpack
hstore_plperlu
amcheck
cube
insert_username
autoinc
bloom
earthdistance
intagg
btree_gin
file_fdw
fuzzystrmatch
btree_gist
intarray
citext
dblink
jsonb_plperl
dict_xsyn
lo
dict_int
jsonb_plperlu
isn
ltree
moddatetime
pgrowlocks
pageinspect
pg_trgm
tcn
pgstattuple
pg_buffercache
xml2
postgres_fdw
pg_freespacemap
pg_prewarm
pg_visibility
refint
pgcrypto
pg_stat_statements
seg
sslinfo
tablefunc
tsm_system_rows
tsm_system_time
unaccent
uuid-ossp

yum安装方式确实是非常非常的方便的哦

四、

postgresql的编译安装

postgresql的编译安装就比较简单了,PostgreSQL: File Browser

1、在这个官方网站下载自己喜欢的版本,然后上传到服务器上,本例中我下载的是postgresql-12.5.tar.bz2

将此文件随便放置到哪都可以,按规范是/usr/local/src目录下,进入此目录,解压上传的源码压缩包

[root@centos7 ~]# mv postgresql-12.5.tar.bz2 /usr/local/src/
[root@centos7 ~]# cd !$
cd /usr/local/src/
[root@centos7 src]# ls
postgresql-12.5.tar.bz2
[root@centos7 src]# pwd
/usr/local/src
[root@centos7 src]# ls
postgresql-12.5.tar.bz2
[root@centos7 src]# tar xf postgresql-12.5.tar.bz2 
[root@centos7 src]# ls
postgresql-12.5  postgresql-12.5.tar.bz2

2、

进入解压目录,创建预编译用的目录,进入这个目录:

[root@centos7 src]# cd postgresql-12.5
[root@centos7 postgresql-12.5]# mkdir build
[root@centos7 postgresql-12.5]# cd build/

3、

查看编译帮助

[root@centos7 build]# ../configure --help
`configure' configures PostgreSQL 12.5 to adapt to many kinds of systems.Usage: ../configure [OPTION]... [VAR=VALUE]...To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.Defaults for the options are specified in brackets.Configuration:-h, --help              display this help and exit--help=short        display options specific to this package--help=recursive    display the short help of all the included packages-V, --version           display version information and exit-q, --quiet, --silent   do not print `checking ...' messages--cache-file=FILE   cache test results in FILE [disabled]-C, --config-cache      alias for `--cache-file=config.cache'-n, --no-create         do not create output files--srcdir=DIR        find the sources in DIR [configure dir or `..']Installation directories:--prefix=PREFIX         install architecture-independent files in PREFIX[/usr/local/pgsql]--exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX[PREFIX]By default, `make install' will install all the files in
`/usr/local/pgsql/bin', `/usr/local/pgsql/lib' etc.  You can specify
an installation prefix other than `/usr/local/pgsql' using `--prefix',
for instance `--prefix=$HOME'.
、、、、、、、、、、后面的略略略

可以看到,可执行文件可以指定到自己喜欢的位置,也就是 --exec-prefix=EPREFIX  ,比较有意思的一个选项是--with-pgport=PORTNUM,这个可以初始化数据库后,就指定的端口了

编译的依赖不多,大概有这些:

yum install bzip2 bzip2-devel zlib zlib-devel readline readline-devel openssl openssl-devel autoconf gcc gcc-c++ llvm llvm-devel perl perl-devel systemd-devel libbsd-devel  pam-deve perl-ExtUtils-Embed  tcl tcl-devel python-devel -y

4、

预编译阶段

根据上面的编译帮助,那么,比较全的一个编译命令是:

../configure --prefix=/opt/pgsql --exec-prefix=/opt/pgsqlb_exec --with-pgport=15433  --with-gssapi --with-tcl --with-perl --with-python  --with-icu --with-pam --with-bsd-auth --with-bonjou --with-systemd --with-includes=/opt/pgsql/includes  --with-libs=/opt/pgsql/libs

5、

编译阶段和编译安装阶段

make && make install

编译完成后,配置环境变量,然后初始化,修改配置文件这些都和yum安装基本一样,就不废话了

库什么的都按编译命令生成了,例如include,如果不指定编译,这些目录是会默认和bin什么的在一起的

[root@centos7 pgsql]# pwd
/opt/pgsql
[root@centos7 pgsql]# ls
include  share

这篇关于Linux|centos7|postgresql数据库|yum和编译方式安装总结(全系版本)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/818486

相关文章

centos7基于keepalived+nginx部署k8s1.26.0高可用集群

《centos7基于keepalived+nginx部署k8s1.26.0高可用集群》Kubernetes是一个开源的容器编排平台,用于自动化地部署、扩展和管理容器化应用程序,在生产环境中,为了确保集... 目录一、初始化(所有节点都执行)二、安装containerd(所有节点都执行)三、安装docker-

详谈redis跟数据库的数据同步问题

《详谈redis跟数据库的数据同步问题》文章讨论了在Redis和数据库数据一致性问题上的解决方案,主要比较了先更新Redis缓存再更新数据库和先更新数据库再更新Redis缓存两种方案,文章指出,删除R... 目录一、Redis 数据库数据一致性的解决方案1.1、更新Redis缓存、删除Redis缓存的区别二

oracle数据库索引失效的问题及解决

《oracle数据库索引失效的问题及解决》本文总结了在Oracle数据库中索引失效的一些常见场景,包括使用isnull、isnotnull、!=、、、函数处理、like前置%查询以及范围索引和等值索引... 目录oracle数据库索引失效问题场景环境索引失效情况及验证结论一结论二结论三结论四结论五总结ora

Jsoncpp的安装与使用方式

《Jsoncpp的安装与使用方式》JsonCpp是一个用于解析和生成JSON数据的C++库,它支持解析JSON文件或字符串到C++对象,以及将C++对象序列化回JSON格式,安装JsonCpp可以通过... 目录安装jsoncppJsoncpp的使用Value类构造函数检测保存的数据类型提取数据对json数

Redis事务与数据持久化方式

《Redis事务与数据持久化方式》该文档主要介绍了Redis事务和持久化机制,事务通过将多个命令打包执行,而持久化则通过快照(RDB)和追加式文件(AOF)两种方式将内存数据保存到磁盘,以防止数据丢失... 目录一、Redis 事务1.1 事务本质1.2 数据库事务与redis事务1.2.1 数据库事务1.

Linux磁盘分区、格式化和挂载方式

《Linux磁盘分区、格式化和挂载方式》本文详细介绍了Linux系统中磁盘分区、格式化和挂载的基本操作步骤和命令,包括MBR和GPT分区表的区别、fdisk和gdisk命令的使用、常见的文件系统格式以... 目录一、磁盘分区表分类二、fdisk命令创建分区1、交互式的命令2、分区主分区3、创建扩展分区,然后

mac安装redis全过程

《mac安装redis全过程》文章内容主要介绍了如何从官网下载指定版本的Redis,以及如何在自定义目录下安装和启动Redis,还提到了如何修改Redis的密码和配置文件,以及使用RedisInsig... 目录MAC安装Redis安装启动redis 配置redis 常用命令总结mac安装redis官网下

Linux中chmod权限设置方式

《Linux中chmod权限设置方式》本文介绍了Linux系统中文件和目录权限的设置方法,包括chmod、chown和chgrp命令的使用,以及权限模式和符号模式的详细说明,通过这些命令,用户可以灵活... 目录设置基本权限命令:chmod1、权限介绍2、chmod命令常见用法和示例3、文件权限详解4、ch

Java中的密码加密方式

《Java中的密码加密方式》文章介绍了Java中使用MD5算法对密码进行加密的方法,以及如何通过加盐和多重加密来提高密码的安全性,MD5是一种不可逆的哈希算法,适合用于存储密码,因为其输出的摘要长度固... 目录Java的密码加密方式密码加密一般的应用方式是总结Java的密码加密方式密码加密【这里采用的

Java中ArrayList的8种浅拷贝方式示例代码

《Java中ArrayList的8种浅拷贝方式示例代码》:本文主要介绍Java中ArrayList的8种浅拷贝方式的相关资料,讲解了Java中ArrayList的浅拷贝概念,并详细分享了八种实现浅... 目录引言什么是浅拷贝?ArrayList 浅拷贝的重要性方法一:使用构造函数方法二:使用 addAll(