Linux 8 快速安装 PostgreSQL 17.2

科技   2024-12-19 08:03   北京  

作者 | JiekeXu
来源 |公众号 JiekeXu DBA之路(ID: JiekeXu_IT)
如需转载请联系授权 | (个人微信 ID:JiekeXu_DBA)
大家好,我是 JiekeXu,江湖人称“强哥”,青学会MOP技术社区联合创始人,荣获 Oracle ACE Pro 称号,墨天轮 MVP,墨天轮年度“墨力之星”,拥有 Oracle OCP/OCM 认证,MySQL 5.7/8.0 OCP 认证以及 PCA、PCTA、OBCA、OGCA、KCP 等众多国产数据库认证证书,今天和大家一起来看看 Linux 8 快速安装 PostgreSQL 17.2,欢迎点击最上方蓝字“JiekeXu DBA之路”关注我的微信公众号,然后点击右上方三个点“设为星标”置顶,更多干货文章才能第一时间推送,谢谢!

前 言
一、查看操作系统信息
二、操作系统相关设置
三、下载软件包并解压
四、编译安装
编译安装要求
配置参数选项
配置
编译安装
编译中遇到的几个小错误
五、配置环境变量
六、初始化PG实例
七、启动PG数据库实例
八、登录测试
九、配置开机自启动
十、参考链接


前  言

2024 年 9 月 26 日 - PostgreSQL 全球开发组宣布 PostgreSQL 17 正式发布,作为世界上最先进的开源数据库,PostgreSQL 17 是目前的最新版本。2024 年 11 月 21 日:PostgreSQL 17.2、16.6、15.10、14.15、13.18 和 12.22 发布!五年一个大版本,PostgreSQL 的下一个主要版本计划是 PG18 版本,计划于 2025 年 9 月发布。

PostgreSQL 版本发布策略除另有说明外,这些发布的目标日期为每年 2 月、5 月、8 月和 11 月的第二个星期四,目前即将发布的时间表是

  • 2025 年 2 月 13 日

  • 2025 年 5 月 8 日

  • 2025 年 8 月 14 日

  • 2025 年 11 月 13 日

下面我们来看一下如何在 Linux 8.7 上快速安装 PostgreSQL 17.2。

一、查看操作系统信息

[root@JiekeXu-Lix8 ~]# cat /etc/redhat-release Red Hat Enterprise Linux release 8.7 (Ootpa)[root@JiekeXu-Lix8 ~]# cat /etc/os-release NAME="Oracle Linux Server"VERSION="8.7"ID="ol"ID_LIKE="fedora"VARIANT="Server"VARIANT_ID="server"VERSION_ID="8.7"PLATFORM_ID="platform:el8"PRETTY_NAME="Oracle Linux Server 8.7"ANSI_COLOR="0;31"CPE_NAME="cpe:/o:oracle:linux:8:7:server"HOME_URL="https://linux.oracle.com/"BUG_REPORT_URL="https://bugzilla.oracle.com/"
ORACLE_BUGZILLA_PRODUCT="Oracle Linux 8"ORACLE_BUGZILLA_PRODUCT_VERSION=8.7ORACLE_SUPPORT_PRODUCT="Oracle Linux"ORACLE_SUPPORT_PRODUCT_VERSION=8.7[root@JiekeXu-Lix8 ~]# df -hFilesystem Size Used Avail Use% Mounted ondevtmpfs 1.8G 0 1.8G 0% /devtmpfs 1.8G 1.4M 1.8G 1% /dev/shmtmpfs 1.8G 34M 1.8G 2% /runtmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup/dev/mapper/ol_jiekexu--lix8-root 37G 6.7G 31G 19% //dev/mapper/ol_jiekexu--lix8-home 19G 453M 18G 3% /home/dev/sda1 1014M 336M 679M 34% /boottmpfs 363M 32K 363M 1% /run/user/0/dev/sr0 12G 12G 0 100% /run/media/root/OL-8-7-0-BaseOS-x86_64[root@JiekeXu-Lix8 ~]# free -m total used free shared buff/cache availableMem: 3627 1475 113 136 2039 1724Swap: 4051 0

二、操作系统相关设置

使用 root 用户操作,这里不在讲解具体细节,仅列出步骤即可。

1) 内核参数设置cp /etc/sysctl.conf /etc/sysctl.conf_`date +"%Y%m%d_%H%M%S"`cat >> /etc/sysctl.conf << "EOF"############################for postgresql###########kernel.shmall =4294967296kernel.shmmax=135497418752kernel.shmmni =4096kernel.sem = 50100 64128000 50100 1280fs.file-max =7672460fs.aio-max-nr =1048576net.ipv4.ip_local_port_range= 9000 65000net.core.rmem_default= 262144net.core.rmem_max= 4194304net.core.wmem_default= 262144net.core.wmem_max= 4194304net.ipv4.tcp_max_syn_backlog= 4096net.core.netdev_max_backlog= 10000net.ipv4.tcp_timestamps= 0#net.ipv4.tcp_tw_recycle=1net.ipv4.tcp_timestamps=1net.ipv4.tcp_keepalive_time= 72net.ipv4.tcp_keepalive_probes= 9net.ipv4.tcp_keepalive_intvl= 7vm.zone_reclaim_mode=0vm.dirty_background_bytes= 40960000vm.dirty_ratio =80vm.dirty_expire_centisecs= 6000vm.dirty_writeback_centisecs= 50vm.swappiness=0vm.overcommit_memory= 0vm.overcommit_ratio= 90EOF
使用 sysctl -p 生效
2)操作系统资源限制cat >> /etc/security/limits.conf << "EOF"#################for postgresql db ###########postgres soft nofile 131072 postgres hard nofile 131072 postgres soft nproc 131072 postgres hard nproc 131072 postgres soft core unlimited postgres hard core unlimited postgres soft memlock 500000000 postgres hard memlock 500000000EOF
3)关闭防火墙和 SeLinux需要关闭 SELINUX 和操作系统防火墙 iptables设置 selinux 为 disable 并重启操作系统;用 systemctl status firewalld 命令关闭防火墙。
cp /etc/selinux/config /etc/selinux/config_`date +"%Y%m%d_%H%M%S"`&& sed -i 's/SELINUX\=enforcing/SELINUX\=disabled/g' /etc/selinux/config
systemctl stop firewalldsystemctl disable firewalldsystemctl status firewalld
4)配置网络 yum 源或者本地 yum 源
mkdir -p /etc/yum.repos.d/bakmv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bakwget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repodnf clean alldnf repolist
5) 安装编译所需 rpm 包[root@JiekeXu-Lix8 ~]# yum install -y zlib zlib-devel libaio cmake make gcc gcc-c++ readline readline-devel perl \ bison flex libyaml net-tools expect openssh-clients tcl openssl openssl-devel libicu libicu-devel \ ncurses-devel python3 python3-devel openldap pam systemtap-sdt-devel perl-ExtUtils-Embed[root@JiekeXu-Lix8 yum.repos.d]# yum install perl-Env bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel make libffi-devel -y
[root@JiekeXu-Lix8 ~]# rpm -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n" coreutils glib2 lrzsz mpstat dstatsysstat e4fsprogs xfsprogs ntp readline-devel zlib-devel openssl-develpam-devel libxml2-devel libxslt-devel python-devel tcl-devel gcc makesmartmontools flex bison perl-devel perl-Ext Utils* openldap-devel jadetex openjade bzip2 | grep 'not installed' |column -tpackage mpstat is not installedpackage dstatsysstat is not installedpackage e4fsprogs is not installedpackage ntp is not installedpackage openssl-develpam-devel is not installedpackage libxml2-devel is not installedpackage libxslt-devel is not installedpackage python-devel is not installedpackage makesmartmontools is not installedpackage perl-Ext is not installedpackage Utils* is not installedpackage openldap-devel is not installedpackage jadetex is not installedpackage openjade is not installed
6)创建用户密码groupadd postgresuseradd -g postgres postgresecho "postgres" |passwd --stdin postgres密码:postgres

三、下载软件包并解压

[root@JiekeXu-Lix8 ~]# wget https://ftp.postgresql.org/pub/source/v17.2/postgresql-17.2.tar.gz[root@JiekeXu-Lix8 ~]# tar -xvf /root/postgresql-17.2.tar.gz  -C /home/postgres/[root@JiekeXu-Lix8 ~]# cd /home/postgres/[root@JiekeXu-Lix8 postgres]# lltotal 4drwxrwxr-x 2 postgres postgres    6 Dec 11 23:44 pgdatadrwxrwxr-x 6 root     root     4096 Nov 19 04:32 postgresql-17.2[root@JiekeXu-Lix8 postgres]# chown -R postgres. postgresql-17.2/[root@JiekeXu-Lix8 postgres]# lltotal 4drwxrwxr-x 2 postgres postgres    6 Dec 11 23:44 pgdatadrwxrwxr-x 6 postgres postgres 4096 Nov 19 04:32 postgresql-17.2[root@JiekeXu-Lix8 postgres]# su - postgres [postgres@JiekeXu-Lix8 ~]$ lltotal 4drwxrwxr-x 2 postgres postgres    6 Dec 11 23:44 pgdatadrwxrwxr-x 6 postgres postgres 4096 Nov 19 04:32 postgresql-17.2[postgres@JiekeXu-Lix8 ~]$ ln -s postgresql-17.2 postgres[postgres@JiekeXu-Lix8 ~]$ lltotal 4drwxrwxr-x 2 postgres postgres    6 Dec 11 23:44 pgdatalrwxrwxrwx 1 postgres postgres   16 Dec 11 23:47 postgres -> postgresql-17.2drwxrwxr-x 6 postgres postgres 4096 Nov 19 04:32 postgresql-17.2

四、编译安装

编译安装要求

  • 需要 GNU make 3.81 或更新版本;

  • 需要 GCC 建议使用 GCC 的最新版本;

  • 需要 gzip 或 bzip2 之外,还需要 tar 来解压源分发版;

  • 需要 Flex 2.5.35 或更高版本以及 Bison 2.3 或更高版本;

  • 需要 Perl 5.14 或更高版本;

  • 默认情况下使用 GNU Readline 库。它允许psql 实现历史命令上下翻转;

  • 默认需要 zlib 压缩库。如果不想使用它,则必须指定选项--without-zlib;使用此选项将禁用 pg_dump 和pg_restore 中对压缩存档的支持。

  • 默认情况下使用 ICU 库。如果您不想使用它,则必须指定选项--without-icu。使用此选项将禁用对 ICU 排序规则功能的支持。ICU 支持需要安装ICU4C包。目前ICU4C的最低要求版本为 4.2。

  • 要构建PL/Python服务器编程语言,您需要安装包含头文件和sysconfig模块的Python。最低要求版本为Python 3.2。

  • 要构建PL/Tcl过程语言,您当然需要安装Tcl,最低要求版本是Tcl 8.4。

  • 如果要支持加密的客户端连接,则需要 OpenSSL。在没有 /dev/urandom 的平台(Windows 除外)上,随机数生成也需要 OpenSSL。最低要求版本为 1.0.2。

  • 如果您希望支持使用这些服务进行身份验证,则需要 MIT Kerberos(用于 GSSAPI)、OpenLDAP 和/或 PAM。

  • 如果您希望支持使用该方法进行数据压缩,则需要 LZ4;请参阅 default_toast_compression 和 wal_compression。

  • 如果您希望支持使用该方法进行数据压缩,则需要 Zstandard;请参阅 wal_compression。最低要求版本为 1.4.0。

  • 要构建 PostgreSQL 文档,则需要:yum install docbook-dtds docbook-style-xsl libxslt fop

配置参数选项

使用 configure 命令便可以进行相关的配置操作,可以 -h 查看相关的帮助命令进行配置。

[postgres@JiekeXu-Lix8 postgres]$ ./configure -h`configure' configures PostgreSQL 17.2 to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them asVAR=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 specifyan installation prefix other than `/usr/local/pgsql' using `--prefix',for instance `--prefix=$HOME'.
--几个选项的简单说明:--with-pgport=NUMBER 设置NUMBER为服务器和客户端的默认端口号。默认值为 5432。以后可以随时更改端口,但如果您在此处指定端口,则服务器和客户端都将编译相同的默认值,这非常方便。通常,选择非默认值的唯一好理由是您打算在同一台机器上运行多个PostgreSQL服务器。
--enable-nls[=LANGUAGES] 启用本地语言支持 ( NLS ),即能够以英语以外的语言显示程序消息。LANGUAGES是一个可选的空格分隔的语言代码列表,其中包含您想要支持的语言,例如--enable-nls='de fr'。(您的列表和实际提供的翻译集之间的交集将自动计算。)如果您未指定列表,则将安装所有可用的翻译。
要使用此选项,您将需要实现Gettext API。
--with-perl 构建PL/Perl服务器端语言。
--with-python 构建PL/Python服务器端语言。
--with-tcl 构建PL/Tcl服务器端语言。
--with-lz4 使用LZ4压缩支持进行构建。
--with-zstd 使用Zstandard压缩支持进行构建。
--with-pam 使用PAM进行构建(可插入身份验证模块)支持。
--without-icu 无需支持ICU即可构建库,禁用 ICU 排序功能
--with-extra-version=STRING 附加STRING到 PostgreSQL 版本号。例如,您可以使用它来标记从未发布的 Git 快照构建的二进制文件或包含带有额外版本字符串(例如标识符git describe或分发包发布号)的自定义补丁。

配置

[root@JiekeXu-Lix8 yum.repos.d]# yum install make gcc gcc-c++ gzip bzip2-devel flex bison perl perl-Env  perl-ExtUtils-Embed readline-devel zlib zlib-devel  icu libicu-devel python3 python3-devel  tcl openssl openssl-devel
[root@JiekeXu-Lix8 ~]# python3Python 3.6.8 (default, Oct 5 2022, 16:22:51) [GCC 8.5.0 20210514 (Red Hat 8.5.0-15.0.1)] on linuxType "help", "copyright", "credits" or "license" for more information.>>> quit()

[postgres@JiekeXu-Lix8 postgres]$ ./configure --prefix=/home/postgres/postgres --with-perl --with-python --with-pgport=54321 --with-opensslchecking build system type... x86_64-pc-linux-gnuchecking host system type... x86_64-pc-linux-gnuchecking which template to use... linuxchecking whether NLS is wanted... nochecking for default port number... 54321checking for block size... 8kBchecking for segment size... 1GBchecking for WAL block size... 8kBchecking for gcc... gccchecking whether the C compiler works... yeschecking for C compiler default output file name... a.outchecking for suffix of executables... checking whether we are cross compiling... nochecking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking for gcc option to accept ISO C99... none neededchecking for g++... g++checking whether we are using the GNU C++ compiler... yeschecking whether g++ accepts -g... yeschecking for gawk... gawkchecking whether gcc supports -Wdeclaration-after-statement, for CFLAGS... yeschecking whether gcc supports -Werror=vla, for CFLAGS... ye…… --省略中间过程schecking for __int128... yeschecking for __int128 alignment bug... okchecking alignment of PG_INT128_TYPE... 16checking for builtin __sync char locking functions... yeschecking for builtin __sync int32 locking functions... yeschecking for builtin __sync int32 atomic operations... yeschecking for builtin __sync int64 atomic operations... yeschecking for builtin __atomic int32 atomic operations... yeschecking for builtin __atomic int64 atomic operations... yeschecking for __get_cpuid... yeschecking for __get_cpuid_count... yeschecking for __cpuid... nochecking for __cpuidex... nochecking for _xgetbv with CFLAGS=... nochecking for _xgetbv with CFLAGS=-mxsave... nochecking for _mm512_popcnt_epi64 with CFLAGS=... nochecking for _mm512_popcnt_epi64 with CFLAGS=-mavx512vpopcntdq -mavx512bw... yeschecking for _mm_crc32_u8 and _mm_crc32_u32 with CFLAGS=... nochecking for _mm_crc32_u8 and _mm_crc32_u32 with CFLAGS=-msse4.2... yeschecking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=... nochecking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc... nochecking for __builtin_loongarch_crcc_w_b_w, __builtin_loongarch_crcc_w_h_w, __builtin_loongarch_crcc_w_w_w and __builtin_loongarch_crcc_w_d_w... nochecking which CRC-32C implementation to use... SSE 4.2 with runtime checkchecking for library containing sem_init... none requiredchecking which semaphore API to use... unnamed POSIXchecking which random number source to use... OpenSSLchecking for perl.h... yeschecking for libperl... yeschecking Python.h usability... yeschecking Python.h presence... yeschecking for Python.h... yeschecking for xmllint... /usr/bin/xmllintchecking for xsltproc... /usr/bin/xsltprocchecking for fop... nochecking for dbtoepub... nochecking whether gcc supports -Wl,--as-needed, for LDFLAGS... yeschecking whether gcc supports -Wl,--export-dynamic, for LDFLAGS_EX_BE... yesconfigure: using compiler=gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4)configure: using CFLAGS=-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2configure: using CPPFLAGS= -D_GNU_SOURCE configure: using LDFLAGS= -Wl,--as-neededconfigure: creating ./config.statusconfig.status: creating GNUmakefileconfig.status: creating src/Makefile.globalconfig.status: creating src/include/pg_config.hconfig.status: creating src/include/pg_config_ext.hconfig.status: creating src/interfaces/ecpg/include/ecpg_config.hconfig.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.sconfig.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_sema.cconfig.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.cconfig.status: linking src/include/port/linux.h to src/include/pg_config_os.hconfig.status: linking src/makefiles/Makefile.linux to src/Makefile.port[postgres@JiekeXu-Lix8 postgres]$

编译安装

[postgres@JiekeXu-Lix8 postgres]$ gmake world -j2
gmake[4]: Nothing to be done for 'all'.gmake[4]: Leaving directory '/home/postgres/postgresql-17.2/src/common'gmake[3]: Leaving directory '/home/postgres/postgresql-17.2/src/test/regress'gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2 -I. -I. -I../../../src/interfaces/libpq -I./../regress -I../../../src/include -D_GNU_SOURCE -c -o specparse.o specparse.cgcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2 -I. -I. -I../../../src/interfaces/libpq -I./../regress -I../../../src/include -D_GNU_SOURCE -c -o specscanner.o specscanner.crm -f pg_regress.o && ln -s ../../../src/test/regress/pg_regress.o .gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2 isolation_main.o pg_regress.o -L../../../src/interfaces/libpq -lpq -L../../../src/port -L../../../src/common -Wl,--as-needed -Wl,-rpath,'/home/postgres/postgres/lib',--enable-new-dtags -lpgcommon -lpgport -lssl -lcrypto -lz -lreadline -lpthread -lrt -ldl -lm -o pg_isolation_regressgcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2 isolationtester.o specparse.o specscanner.o -L../../../src/interfaces/libpq -lpq -L../../../src/port -L../../../src/common -Wl,--as-needed -Wl,-rpath,'/home/postgres/postgres/lib',--enable-new-dtags -lpgcommon -lpgport -lssl -lcrypto -lz -lreadline -lpthread -lrt -ldl -lm -o isolationtestergmake[2]: Leaving directory '/home/postgres/postgresql-17.2/src/test/isolation'gmake -C test/perl allgmake[2]: Entering directory '/home/postgres/postgresql-17.2/src/test/perl'gmake[2]: Nothing to be done for 'all'.gmake[2]: Leaving directory '/home/postgres/postgresql-17.2/src/test/perl'gmake[1]: Leaving directory '/home/postgres/postgresql-17.2/src'[postgres@JiekeXu-Lix8 postgres]$

[postgres@JiekeXu-Lix8 postgres]$ gmake install-world -j2
gmake[3]: Entering directory '/home/postgres/postgresql-17.2/src/common'gmake[3]: Nothing to be done for 'all'.gmake[3]: Leaving directory '/home/postgres/postgresql-17.2/src/common'/usr/bin/mkdir -p '/home/postgres/postgres/lib/pgxs/src/test/isolation'gmake[4]: Entering directory '/home/postgres/postgresql-17.2/src/common'gmake[4]: Nothing to be done for 'all'.gmake[4]: Leaving directory '/home/postgres/postgresql-17.2/src/common'gmake[3]: Leaving directory '/home/postgres/postgresql-17.2/src/interfaces/libpq'/usr/bin/install -c pg_isolation_regress '/home/postgres/postgres/lib/pgxs/src/test/isolation/pg_isolation_regress'/usr/bin/install -c isolationtester '/home/postgres/postgres/lib/pgxs/src/test/isolation/isolationtester'gmake[2]: Leaving directory '/home/postgres/postgresql-17.2/src/test/isolation'gmake -C test/perl installgmake[2]: Entering directory '/home/postgres/postgresql-17.2/src/test/perl'gmake[2]: Nothing to be done for 'install'.gmake[2]: Leaving directory '/home/postgres/postgresql-17.2/src/test/perl'/usr/bin/mkdir -p '/home/postgres/postgres/lib/pgxs/src'/usr/bin/install -c -m 644 Makefile.global '/home/postgres/postgres/lib/pgxs/src/Makefile.global'/usr/bin/install -c -m 644 Makefile.port '/home/postgres/postgres/lib/pgxs/src/Makefile.port'/usr/bin/install -c -m 644 ./Makefile.shlib '/home/postgres/postgres/lib/pgxs/src/Makefile.shlib'/usr/bin/install -c -m 644 ./nls-global.mk '/home/postgres/postgres/lib/pgxs/src/nls-global.mk'gmake[1]: Leaving directory '/home/postgres/postgresql-17.2/src'[postgres@JiekeXu-Lix8 postgres]$
--查看版本[postgres@JiekeXu-Lix8 postgres]$ /home/postgres/postgres/bin/postgres --versionpostgres (PostgreSQL) 17.2

仅客户端安装

--仅客户端安装:如果您只想安装客户端应用程序和接口库,那么您可以使用以下命令:
make -C src/bin installmake -C src/include installmake -C src/interfaces installmake -C doc install

编译中遇到的几个小错误

错误一:缺少 ICU 包,error: ICU library not found

解决办法:安装 ICU 包或者编译时 --without-icu

[postgres@JiekeXu-Lix8 postgres]$ ./configure --prefix=/home/postgres/postgres  --with-perl  --with-python --with-pgport=54321 --with-opensslchecking build system type... x86_64-pc-linux-gnuchecking host system type... x86_64-pc-linux-gnu

checking whether we are cross compiling... nochecking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking for gcc option to accept ISO C99... none neededchecking for g++... g++checking whether we are using the GNU C++ compiler... yeschecking whether g++ accepts -g... yes
checking whether g++ supports -fvisibility=hidden, for CXXFLAGS_SL_MODULE... yeschecking whether g++ supports -fvisibility-inlines-hidden, for CXXFLAGS_SL_MODULE... yeschecking whether the C compiler still works... yeschecking how to run the C preprocessor... gcc -Echecking for pkg-config... /usr/bin/pkg-configchecking pkg-config is at least version 0.9.0... yeschecking whether to build with ICU support... yeschecking for icu-uc icu-i18n... noconfigure: error: ICU library not foundIf you have ICU already installed, see config.log for details on thefailure. It is possible the compiler isn't looking in the proper directory.Use --without-icu to disable ICU support.

[root@JiekeXu-Lix8 ~]# icu-config --versionbash: icu-config: command not found...Install package 'libicu-devel' to provide command 'icu-config'? [N/y] y

* Waiting in queue... * Loading list of packages.... The following packages have to be installed: libicu-devel-60.3-2.el8_1.x86_64 Development files for International Components for UnicodeProceed with changes? [N/y] y
* Waiting in queue... * Waiting for authentication... * Waiting in queue... * Loading list of packages.... * Downloading packages... * Requesting data... * Testing changes... * Installing packages... 60.3

错误二:缺少 bison 包 error: bison not found

解决办法:安装  bison 包

checking for strip... stripchecking whether it is possible to strip libraries... yeschecking for ar... archecking for a BSD-compatible install... /usr/bin/install -cchecking for tar... /usr/bin/tarchecking whether ln -s works... yeschecking for a thread-safe mkdir -p... /usr/bin/mkdir -pchecking for bison... noconfigure: error: bison not found
[root@JiekeXu-Lix8 ~]# yum install bison -y

错误三: 缺少 flex 包 error: flex not found

解决办法:安装  flex 包

checking whether to build with ZSTD support... nochecking for strip... stripchecking whether it is possible to strip libraries... yeschecking for ar... archecking for a BSD-compatible install... /usr/bin/install -cchecking for tar... /usr/bin/tarchecking whether ln -s works... yeschecking for a thread-safe mkdir -p... /usr/bin/mkdir -pchecking for bison... /usr/bin/bisonconfigure: using bison (GNU Bison) 3.0.4checking for flex... noconfigure: error: flex not found
[root@JiekeXu-Lix8 ~]# yum install flex -y

五、配置环境变量

vi .bashrcexport PGPORT=54321 export PGDATA=/home/postgres/pgdata export PGHOME=/home/postgres/postgresexport LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH export PATH=$PGHOME/bin:$PATH:. export DATE=`date +"%Y%m%d%H%M"` export MANPATH=$PGHOME/share/man:$MANPATH export PGHOST=$PGDATA export PGUSER=postgres export PGDATABASE=postgres export LANG='en_US.UTF-8'alias rm='rm -i' alias ll='ls -lh' 

六、初始化PG实例

initdb -D  $PGDATA -E UTF8 --locale=C -U postgres
[postgres@JiekeXu-Lix8 ~]$ initdb -D $PGDATA -E UTF8 --locale=C -U postgresThe files belonging to this database system will be owned by user "postgres".This user must also own the server process.
The database cluster will be initialized with locale "C".The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /home/postgres/pgdata ... okcreating subdirectories ... okselecting dynamic shared memory implementation ... posixselecting default "max_connections" ... 100selecting default "shared_buffers" ... 128MBselecting default time zone ... Asia/Shanghaicreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... oksyncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connectionsinitdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /home/postgres/pgdata -l logfile start

七、启动PG数据库实例

首先编辑参数文件 postgresql.conf

[root@JiekeXu-Lix8 ~]# su - postgres[postgres@JiekeXu-Lix8 ~]$ cd $PGDATA
vi postgresql.conf
listen_addresses = '0.0.0.0' port = 54321 max_connections = 2000 unix_socket_directories = '/home/postgres/pgdata' tcp_keepalives_idle = 60 tcp_keepalives_interval = 10 tcp_keepalives_count = 10 shared_buffers = 512MB dynamic_shared_memory_type = posix vacuum_cost_delay = 0 bgwriter_delay = 10ms bgwriter_lru_maxpages = 1000 bgwriter_lru_multiplier = 10.0 bgwriter_flush_after = 0 backend_flush_after = 0 wal_level=logicalarchive_mode=alwaysarchive_command='cp %p /home/postgres/pgdata/archive/%f'min_wal_size=128MB max_wal_size=1GB
max_wal_senders=10hot_standby=onlog_filename='pg_log_%u.log'log_file_mode=0600log_truncate_on_rotation=onlog_rotation_age=1dlog_min_messages=warninglog_min_duration_statement=30ssynchronous_commit = off full_page_writes = on wal_buffers = 16MB wal_writer_delay = 10ms wal_writer_flush_after = 0 checkpoint_timeout = 30min checkpoint_completion_target = 0.05 checkpoint_flush_after = 0 random_page_cost = 1.3 log_directory='pg_log' log_destination = 'csvlog' logging_collector = on log_truncate_on_rotation = on log_checkpoints = on log_connections = on log_disconnections = on log_error_verbosity = verbose log_duration=onlog_lock_waits=onlog_statement='mod'autovacuum = on log_autovacuum_min_duration = 0 autovacuum_naptime = 20s autovacuum_vacuum_scale_factor = 0.05 autovacuum_freeze_max_age = 1500000000 autovacuum_multixact_freeze_max_age = 1600000000 autovacuum_vacuum_cost_delay = 0 vacuum_freeze_table_age = 1400000000 vacuum_multixact_freeze_table_age = 1500000000 datestyle = 'iso, mdy' timezone = 'PRC' lc_messages = 'C' lc_monetary = 'C' lc_numeric = 'C' lc_time = 'C' default_text_search_config = 'pg_catalog.english'

然后配置 pg_hba.conf,数据库防火墙文件名字 pg_hba.conf,将以下内容追加到文件末尾,表示允许网络用户使用用户密码连接到你的 postgresql 数据库.

[postgres@JiekeXu-Lix8 pgdata]$ vim /home/postgres/pgdata/pg_hba.confhost      all          all             0.0.0.0/0               md5

启动数据库

[postgres@JiekeXu-Lix8 pgdata]$ pg_ctl -D /home/postgres/pgdata start &[1] 91484[postgres@JiekeXu-Lix8 pgdata]$ waiting for server to start....2024-12-12 00:18:57.221 CST [91486] LOG:  00000: redirecting log output to logging collector process2024-12-12 00:18:57.221 CST [91486] HINT:  Future log output will appear in directory "pg_log".2024-12-12 00:18:57.221 CST [91486] LOCATION:  SysLogger_Start, syslogger.c:733 doneserver started
[1]+ Done pg_ctl -D /home/postgres/pgdata start[postgres@JiekeXu-Lix8 pgdata]$ ### 查看状态[postgres@JiekeXu-Lix8 pgdata]$ ps -ef | grep postgresroot 75920 3774 0 Dec11 pts/1 00:00:00 su - postgrespostgres 75921 75920 0 Dec11 pts/1 00:00:00 -bashroot 91346 3834 0 00:13 pts/2 00:00:00 su - postgrespostgres 91347 91346 0 00:13 pts/2 00:00:00 -bashpostgres 91486 1 1 00:18 ? 00:00:00 /home/postgres/postgresql-17.2/bin/postgres -D /home/postgres/pgdatapostgres 91487 91486 0 00:18 ? 00:00:00 postgres: logger postgres 91488 91486 0 00:18 ? 00:00:00 postgres: checkpointer postgres 91489 91486 0 00:18 ? 00:00:00 postgres: background writer postgres 91491 91486 0 00:18 ? 00:00:00 postgres: walwriter postgres 91492 91486 0 00:18 ? 00:00:00 postgres: autovacuum launcher postgres 91493 91486 0 00:18 ? 00:00:00 postgres: archiver postgres 91494 91486 0 00:18 ? 00:00:00 postgres: logical replication launcher postgres 91506 75921 0 00:19 pts/1 00:00:00 ps -efpostgres 91507 75921 0 00:19 pts/1 00:00:00 grep --color=auto postgres[postgres@JiekeXu-Lix8 pgdata]$ pg_ctl statuspg_ctl: server is running (PID: 91486)/home/postgres/postgresql-17.2/bin/postgres "-D" "/home/postgres/pgdata"

八、登录测试

--查看并启动 PG 实例[postgres@JiekeXu-Lix8 ~]$ pg_ctl statuspg_ctl: no server running[postgres@JiekeXu-Lix8 ~]$ pg_ctl start pg_ctl: another server might be running; trying to start server anywaywaiting for server to start....2024-12-17 23:43:51.023 CST [29226] LOG:  00000: redirecting log output to logging collector process2024-12-17 23:43:51.023 CST [29226] HINT:  Future log output will appear in directory "pg_log".2024-12-17 23:43:51.023 CST [29226] LOCATION:  SysLogger_Start, syslogger.c:733 doneserver started[postgres@JiekeXu-Lix8 ~]$ pg_ctl statuspg_ctl: server is running (PID: 29226)/home/postgres/postgresql-17.2/bin/postgres
[postgres@JiekeXu-Lix8 pgdata]$ psql -U postgres -p54321psql (17.2)Type "help" for help.
postgres=# \l List of databases Name | Owner | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules | Access privileges -----------+----------+----------+-----------------+---------+-------+--------+-----------+----------------------- postgres | postgres | UTF8 | libc | C | C | | | template0 | postgres | UTF8 | libc | C | C | | | =c/postgres + | | | | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | libc | C | C | | | =c/postgres + | | | | | | | | postgres=CTc/postgres(3 rows) postgres=# create database jiekexu;CREATE DATABASEpostgres=# \l
postgres=# \c jiekexuYou are now connected to database "jiekexu" as user "postgres".jiekexu=# \l List of databases Name | Owner | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules | Access privileges -----------+----------+----------+-----------------+---------+-------+--------+-----------+----------------------- jiekexu | postgres | UTF8 | libc | C | C | | | postgres | postgres | UTF8 | libc | C | C | | | template0 | postgres | UTF8 | libc | C | C | | | =c/postgres + | | | | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | libc | C | C | | | =c/postgres + | | | | | | | | postgres=CTc/postgres(4 rows)jiekexu=# create table test (id int,name varchar(30));CREATE TABLEjiekexu=# jiekexu=# insert into test values(1,'jieke'),(2,'DBA');INSERT 0 2jiekexu=# select * from test; id | name ----+------- 1 | jieke 2 | DBA(2 rows)

九、配置开机自启动

以前都是通过 contrib 目录下的 Linux 脚本设置开机自启动,也是很方便,仅需要修改 prefix 和 PGDATA 两处即可,今天我们通过配置成服务名的方式来设置开机自启动。

# cp /home/postgres/postgres/contrib/start-scripts/linux /etc/init.d/postgres-14# chmod +x /etc/init.d/postgres-14# vi /etc/init.d/postgres-14--修改如下两处prefix=/home/postgres/postgresPGDATA="/home/postgres/pgdata"
# chkconfig postgres-14 on # chkconfig --list | grep postgres

使用 root 用户,先关闭数据库实例,在进行配置

[root@JiekeXu-Lix8 ~]# su - postgres[postgres@JiekeXu-Lix8 ~]$ pg_ctl stopwaiting for server to shut down.... doneserver stopped[postgres@JiekeXu-Lix8 ~]$ exitlogout[root@JiekeXu-Lix8 ~]# cat > /usr/lib/systemd/system/postgres.service << "EOF"cat > /usr/lib/systemd/system/postgres.service << "EOF"[Unit]Description=PostgreSQL database serverAfter=network.target[Service]Type=forkingUser=postgresGroup=postgresEnvironment=PGPORT=54321Environment=PGDATA=/home/postgres/pgdataOOMScoreAdjust=-1000ExecStart=/home/postgres/postgres/bin/pg_ctl start -D $PGDATAExecStop=/home/postgres/postgres/bin/pg_ctl stop -D $PGDATA -s -m fastExecReload=/home/postgres/postgres/bin/pg_ctl reload -D $PGDATA -sTimeoutSec=300[Install]WantedBy=multi-user.targetEOF[root@JiekeXu-Lix8 ~]# chmod +x /usr/lib/systemd/system/postgres.service[root@JiekeXu-Lix8 ~]# systemctl daemon-reload[root@JiekeXu-Lix8 ~]# systemctl enable --now postgres.serviceCreated symlink from /etc/systemd/system/multi-user.target.wants/postgres.service to /usr/lib/systemd/system/postgres.service.[root@JiekeXu-Lix8 ~]# systemctl status postgres.service
[root@JiekeXu-Lix8 ~]# systemctl start postgres.service [root@JiekeXu-Lix8 ~]# systemctl status postgres.service● postgres.service - PostgreSQL database server Loaded: loaded (/usr/lib/systemd/system/postgres.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2024-12-18 00:05:22 CST; 4s ago Process: 29722 ExecStart=/home/postgres/postgres/bin/pg_ctl start -D $PGDATA (code=exited, status=0/SUCCESS) Main PID: 29724 (postgres) Tasks: 8 (limit: 22838) Memory: 96.8M CGroup: /system.slice/postgres.service ├─29724 /home/postgres/postgresql-17.2/bin/postgres -D /home/postgres/pgdata ├─29725 postgres: logger ├─29726 postgres: checkpointer ├─29727 postgres: background writer ├─29729 postgres: walwriter ├─29730 postgres: autovacuum launcher ├─29731 postgres: archiver └─29732 postgres: logical replication launcher
Dec 18 00:05:22 JiekeXu-Lix8 systemd[1]: Starting PostgreSQL database server...Dec 18 00:05:22 JiekeXu-Lix8 pg_ctl[29722]: waiting for server to start....Dec 18 00:05:22 JiekeXu-Lix8 pg_ctl[29724]: waiting for server to start....Dec 18 00:05:22 JiekeXu-Lix8 pg_ctl[29724]: 024-12-18 00:05:22.931 CST [29724] LOG: 00000: redirecting log output to>Dec 18 00:05:22 JiekeXu-Lix8 pg_ctl[29724]: 2024-12-18 00:05:22.931 CST [29724] HINT: Future log output will appear >Dec 18 00:05:22 JiekeXu-Lix8 pg_ctl[29724]: 2024-12-18 00:05:22.931 CST [29724] LOCATION: SyDec 18 00:05:22 JiekeXu-Lix8 systemd[1]: Started PostgreSQL database server.

十、参考链接

https://www.modb.pro/db/1783744765954707456https://www.postgresql.org/support/versioning/https://en.wikipedia.org/wiki/PostgreSQLhttps://www.postgresql.org/support/security/https://www.postgresql.org/ftp/source/v17.2/

全文完,希望可以帮到正在阅读的你,如果觉得有帮助,可以分享给你身边的朋友,同事,你关心谁就分享给谁,一起学习共同进步~~~

欢迎关注我的公众号【JiekeXu DBA之路】,一起学习新知识!
—————————————————————
公众号:JiekeXu DBA之路
墨天轮:https://www.modb.pro/u/4347
CSDN :https://blog.csdn.net/JiekeXu
ITPUB:https://blog.itpub.net/69968215
腾讯云:https://cloud.tencent.com/developer/user/5645107
—————————————————————



分享几个数据库备份脚本

一文搞懂 Oracle 统计信息

我的 Oracle ACE 心路历程

MOP 系列|MOP 三种主流数据库索引简介

Oracle 主流版本不同架构下的静默安装指南

关机重启导致 ASM 磁盘丢失数据库无法启动

Oracle SQL 性能分析(SPA)原理与实战演练

Oracle 11g 升级到 19c 需要关注的几个问题

Windows 10 环境下 MySQL 8.0.33 安装指南

SQL 大全(四)|数据库迁移升级时常用 SQL 语句

OGG|使用 OGG19c 迁移 Oracle11g 到 19C(第二版)

Oracle 大数据量导出工具——sqluldr2 的安装与使用

Oracle ACE 视角下的国产数据库现状与选型及应对策略

从国产数据库调研报告中你都能了解哪些信息及我的总结建议

使用数据泵利用 rowid 分片导出导入 lob 大表及最佳实践

在归档模式下直接 rm dbf 数据文件并重启数据库还有救吗?

欢迎关注我的公众号【JiekeXu DBA之路】,一起学习新知识!


JiekeXu DBA之路
JiekeXu:Oracle ACE-Pro,获 Oracle OCP/OCM 及 MySQL OCP 认证,墨天轮 MVP,利用闲时间记录菜鸟 DBA 学习成长之路,所发布文字属于个人观点和学习笔记,如有错误及不当之处,敬请批评指正!
 最新文章