本文主要是介绍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和编译方式安装总结(全系版本)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!