暂无图片
暂无图片
6
暂无图片
暂无图片
暂无图片

Linux 8 快速安装 PostgreSQL 17.2

695

目录

前 言
一、查看操作系统信息
二、操作系统相关设置
三、下载软件包并解压
四、编译安装
    编译安装要求
    配置参数选项
    配置
    编译安装
    编译中遇到的几个小错误
五、配置环境变量
六、初始化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 日

facebook_pro_light_1920 × 1080  副本.png

下面我们来看一下如何在 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.7 ORACLE_SUPPORT_PRODUCT="Oracle Linux" ORACLE_SUPPORT_PRODUCT_VERSION=8.7 [root@JiekeXu-Lix8 ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.8G 0 1.8G 0% /dev tmpfs 1.8G 1.4M 1.8G 1% /dev/shm tmpfs 1.8G 34M 1.8G 2% /run tmpfs 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% /boot tmpfs 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 available Mem: 3627 1475 113 136 2039 1724 Swap: 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 =4294967296 kernel.shmmax=135497418752 kernel.shmmni =4096 kernel.sem = 50100 64128000 50100 1280 fs.file-max =7672460 fs.aio-max-nr =1048576 net.ipv4.ip_local_port_range= 9000 65000 net.core.rmem_default= 262144 net.core.rmem_max= 4194304 net.core.wmem_default= 262144 net.core.wmem_max= 4194304 net.ipv4.tcp_max_syn_backlog= 4096 net.core.netdev_max_backlog= 10000 net.ipv4.tcp_timestamps= 0 #net.ipv4.tcp_tw_recycle=1 net.ipv4.tcp_timestamps=1 net.ipv4.tcp_keepalive_time= 72 net.ipv4.tcp_keepalive_probes= 9 net.ipv4.tcp_keepalive_intvl= 7 vm.zone_reclaim_mode=0 vm.dirty_background_bytes= 40960000 vm.dirty_ratio =80 vm.dirty_expire_centisecs= 6000 vm.dirty_writeback_centisecs= 50 vm.swappiness=0 vm.overcommit_memory= 0 vm.overcommit_ratio= 90 EOF 使用 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 500000000 EOF 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 firewalld systemctl disable firewalld systemctl status firewalld 4)配置网络 yum 源或者本地 yum 源 mkdir -p /etc/yum.repos.d/bak mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo dnf clean all dnf 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 -t package mpstat is not installed package dstatsysstat is not installed package e4fsprogs is not installed package ntp is not installed package openssl-develpam-devel is not installed package libxml2-devel is not installed package libxslt-devel is not installed package python-devel is not installed package makesmartmontools is not installed package perl-Ext is not installed package Utils* is not installed package openldap-devel is not installed package jadetex is not installed package openjade is not installed 6)创建用户密码 groupadd postgres useradd -g postgres postgres echo "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]# ll total 4 drwxrwxr-x 2 postgres postgres 6 Dec 11 23:44 pgdata drwxrwxr-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]# ll total 4 drwxrwxr-x 2 postgres postgres 6 Dec 11 23:44 pgdata drwxrwxr-x 6 postgres postgres 4096 Nov 19 04:32 postgresql-17.2 [root@JiekeXu-Lix8 postgres]# su - postgres [postgres@JiekeXu-Lix8 ~]$ ll total 4 drwxrwxr-x 2 postgres postgres 6 Dec 11 23:44 pgdata drwxrwxr-x 6 postgres postgres 4096 Nov 19 04:32 postgresql-17.2 [postgres@JiekeXu-Lix8 ~]$ ln -s postgresql-17.2 postgres [postgres@JiekeXu-Lix8 ~]$ ll total 4 drwxrwxr-x 2 postgres postgres 6 Dec 11 23:44 pgdata lrwxrwxrwx 1 postgres postgres 16 Dec 11 23:47 postgres -> postgresql-17.2 drwxrwxr-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 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'. --几个选项的简单说明: --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 ~]# python3 Python 3.6.8 (default, Oct 5 2022, 16:22:51) [GCC 8.5.0 20210514 (Red Hat 8.5.0-15.0.1)] on linux Type "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-openssl checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking which template to use... linux checking whether NLS is wanted... no checking for default port number... 54321 checking for block size... 8kB checking for segment size... 1GB checking for WAL block size... 8kB checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking for gcc option to accept ISO C99... none needed checking for g++... g++ checking whether we are using the GNU C++ compiler... yes checking whether g++ accepts -g... yes checking for gawk... gawk checking whether gcc supports -Wdeclaration-after-statement, for CFLAGS... yes checking whether gcc supports -Werror=vla, for CFLAGS... yes checking whether gcc supports -Werror=unguarded-availability-new, for CFLAGS... no checking whether g++ supports -Werror=unguarded-availability-new, for CXXFLAGS... no checking whether gcc supports -Wendif-labels, for CFLAGS... yes checking whether g++ supports -Wendif-labels, for CXXFLAGS... yes checking whether gcc supports -Wmissing-format-attribute, for CFLAGS... yes checking whether g++ supports -Wmissing-format-attribute, for CXXFLAGS... yes checking whether gcc supports -Wimplicit-fallthrough=3, for CFLAGS... yes checking whether g++ supports -Wimplicit-fallthrough=3, for CXXFLAGS... yes checking whether gcc supports -Wcast-function-type, for CFLAGS... yes checking whether g++ supports -Wcast-function-type, for CXXFLAGS... yes checking whether gcc supports -Wshadow=compatible-local, for CFLAGS... yes checking whether g++ supports -Wshadow=compatible-local, for CXXFLAGS... yes checking whether gcc supports -Wformat-security, for CFLAGS... yes checking whether g++ supports -Wformat-security, for CXXFLAGS... yes checking whether gcc supports -fno-strict-aliasing, for CFLAGS... yes checking whether g++ supports -fno-strict-aliasing, for CXXFLAGS... yes checking whether gcc supports -fwrapv, for CFLAGS... yes checking whether g++ supports -fwrapv, for CXXFLAGS... yes checking whether gcc supports -fexcess-precision=standard, for CFLAGS... yes checking whether g++ supports -fexcess-precision=standard, for CXXFLAGS... no checking whether gcc supports -funroll-loops, for CFLAGS_UNROLL_LOOPS... yes checking whether gcc supports -ftree-vectorize, for CFLAGS_VECTORIZE... yes checking whether gcc supports -Wunused-command-line-argument, for NOT_THE_CFLAGS... no checking whether gcc supports -Wcompound-token-split-by-macro, for NOT_THE_CFLAGS... no checking whether gcc supports -Wformat-truncation, for NOT_THE_CFLAGS... yes checking whether gcc supports -Wstringop-truncation, for NOT_THE_CFLAGS... yes checking whether gcc supports -Wcast-function-type-strict, for NOT_THE_CFLAGS... no checking whether gcc supports -fvisibility=hidden, for CFLAGS_SL_MODULE... yes checking whether g++ supports -fvisibility=hidden, for CXXFLAGS_SL_MODULE... yes checking whether g++ supports -fvisibility-inlines-hidden, for CXXFLAGS_SL_MODULE... yes checking whether the C compiler still works... yes checking how to run the C preprocessor... gcc -E checking for pkg-config... /usr/bin/pkg-config checking pkg-config is at least version 0.9.0... yes checking whether to build with ICU support... yes checking for icu-uc icu-i18n... yes checking whether to build with Tcl... no checking whether to build Perl modules... yes checking whether to build Python modules... yes checking whether to build with GSSAPI support... no checking whether to build with PAM support... no checking whether to build with BSD Authentication support... no checking whether to build with LDAP support... no checking whether to build with Bonjour support... no checking whether to build with SELinux support... no checking whether to build with systemd support... no checking whether to build with XML support... no checking whether to build with LZ4 support... no checking whether to build with ZSTD support... no checking for strip... strip checking whether it is possible to strip libraries... yes checking for ar... ar checking for a BSD-compatible install... /usr/bin/install -c checking for tar... /usr/bin/tar checking whether ln -s works... yes checking for a thread-safe mkdir -p... /usr/bin/mkdir -p checking for bison... /usr/bin/bison configure: using bison (GNU Bison) 3.0.4 checking for flex... /usr/bin/flex configure: using flex 2.6.1 checking for perl... /usr/bin/perl configure: using perl 5.26.3 checking for Perl archlibexp... /usr/lib64/perl5 checking for Perl privlibexp... /usr/share/perl5 checking for Perl useshrplib... true checking for CFLAGS recommended by Perl... -D_REENTRANT -D_GNU_SOURCE -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fwrapv -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 checking for CFLAGS to compile embedded Perl... checking for flags to link embedded Perl... -L/usr/lib64/perl5/CORE -lperl -lpthread -lresolv -ldl -lm -lcrypt -lutil -lc checking for python3... /usr/bin/python3 configure: using python 3.6.8 (default, Oct 5 2022, 16:22:51) checking for Python sysconfig module... yes checking Python configuration directory... /usr/lib64/python3.6/config-3.6m-x86_64-linux-gnu checking Python include directory... -I/usr/include/python3.6m checking how to link an embedded Python application... -L/usr/lib64 -lpython3.6m -lpthread -ldl -lutil -lm checking for a sed that does not truncate output... /usr/bin/sed checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking whether gcc is Clang... no checking whether pthreads work with -pthread... yes checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE checking whether more special flags are required for pthreads... no checking for PTHREAD_PRIO_INHERIT... yes checking pthread.h usability... yes checking pthread.h presence... yes checking for pthread.h... yes checking for strerror_r... yes checking whether strerror_r returns int... no checking for main in -lm... yes checking for library containing setproctitle... no checking for library containing dlsym... -ldl checking for library containing socket... none required checking for library containing getopt_long... none required checking for library containing shm_open... -lrt checking for library containing shm_unlink... none required checking for library containing clock_gettime... none required checking for library containing shmget... none required checking for library containing backtrace_symbols... none required checking for library containing pthread_barrier_wait... -lpthread checking for library containing readline... -lreadline checking for inflate in -lz... yes checking for CRYPTO_new_ex_data in -lcrypto... yes checking for SSL_new in -lssl... yes checking for SSL_CTX_set_cert_cb... yes checking for OPENSSL_init_ssl... yes checking for BIO_meth_new... yes checking for ASN1_STRING_get0_data... yes checking for HMAC_CTX_new... yes checking for HMAC_CTX_free... yes checking for CRYPTO_lock... no checking for X509_get_signature_info... yes checking for SSL_CTX_set_num_tickets... yes checking for stdbool.h that conforms to C99... yes checking for _Bool... yes checking atomic.h usability... no checking atomic.h presence... no checking for atomic.h... no checking copyfile.h usability... no checking copyfile.h presence... no checking for copyfile.h... no checking execinfo.h usability... yes checking execinfo.h presence... yes checking for execinfo.h... yes checking getopt.h usability... yes checking getopt.h presence... yes checking for getopt.h... yes checking ifaddrs.h usability... yes checking ifaddrs.h presence... yes checking for ifaddrs.h... yes checking langinfo.h usability... yes checking langinfo.h presence... yes checking for langinfo.h... yes checking mbarrier.h usability... no checking mbarrier.h presence... no checking for mbarrier.h... no checking sys/epoll.h usability... yes checking sys/epoll.h presence... yes checking for sys/epoll.h... yes checking sys/event.h usability... no checking sys/event.h presence... no checking for sys/event.h... no checking sys/personality.h usability... yes checking sys/personality.h presence... yes checking for sys/personality.h... yes checking sys/prctl.h usability... yes checking sys/prctl.h presence... yes checking for sys/prctl.h... yes checking sys/procctl.h usability... no checking sys/procctl.h presence... no checking for sys/procctl.h... no checking sys/signalfd.h usability... yes checking sys/signalfd.h presence... yes checking for sys/signalfd.h... yes checking sys/ucred.h usability... no checking sys/ucred.h presence... no checking for sys/ucred.h... no checking termios.h usability... yes checking termios.h presence... yes checking for termios.h... yes checking ucred.h usability... no checking ucred.h presence... no checking for ucred.h... no checking readline/readline.h usability... yes checking readline/readline.h presence... yes checking for readline/readline.h... yes checking readline/history.h usability... yes checking readline/history.h presence... yes checking for readline/history.h... yes checking zlib.h usability... yes checking zlib.h presence... yes checking for zlib.h... yes checking for lz4... /usr/bin/lz4 checking for zstd... /usr/bin/zstd checking for openssl... /usr/bin/openssl configure: using openssl: OpenSSL 1.1.1k FIPS 25 Mar 2021 checking openssl/ssl.h usability... yes checking openssl/ssl.h presence... yes checking for openssl/ssl.h... yes checking openssl/err.h usability... yes checking openssl/err.h presence... yes checking for openssl/err.h... yes checking whether byte ordering is bigendian... no checking for inline... inline checking for printf format archetype... gnu_printf checking for _Static_assert... yes checking for typeof... typeof checking for __builtin_types_compatible_p... yes checking for __builtin_constant_p... yes checking for __builtin_unreachable... yes checking for computed goto support... yes checking for struct tm.tm_zone... yes checking for union semun... no checking for socklen_t... yes checking for struct sockaddr.sa_len... no checking for locale_t... yes checking for C/C++ restrict keyword... __restrict checking for struct option... yes checking whether assembler supports x86_64 popcntq... yes checking for special C compiler options needed for large files... no checking for _FILE_OFFSET_BITS value needed for large files... no checking size of off_t... 8 checking size of bool... 1 checking for int timezone... yes checking for wcstombs_l declaration... no checking for backtrace_symbols... yes checking for copyfile... no checking for copy_file_range... yes checking for getifaddrs... yes checking for getpeerucred... no checking for inet_pton... yes checking for kqueue... no checking for mbstowcs_l... no checking for memset_s... no checking for posix_fallocate... yes checking for ppoll... yes checking for pthread_is_threaded_np... no checking for setproctitle... no checking for setproctitle_fast... no checking for strchrnul... yes checking for strsignal... yes checking for syncfs... yes checking for sync_file_range... yes checking for uselocale... yes checking for wcstombs_l... no checking for __builtin_bswap16... yes checking for __builtin_bswap32... yes checking for __builtin_bswap64... yes checking for __builtin_clz... yes checking for __builtin_ctz... yes checking for __builtin_popcount... yes checking for __builtin_frame_address... yes checking for _LARGEFILE_SOURCE value needed for large files... no checking how gcc reports undeclared, standard C functions... error checking for posix_fadvise... yes checking whether posix_fadvise is declared... yes checking whether fdatasync is declared... yes checking whether strlcat is declared... no checking whether strlcpy is declared... no checking whether strnlen is declared... yes checking whether preadv is declared... yes checking whether pwritev is declared... yes checking whether F_FULLFSYNC is declared... no checking for explicit_bzero... yes checking for getopt... yes checking for getpeereid... no checking for inet_aton... yes checking for mkdtemp... yes checking for strlcat... no checking for strlcpy... no checking for strnlen... yes checking for pthread_barrier_wait... yes checking for getopt_long... yes checking for syslog... yes checking syslog.h usability... yes checking syslog.h presence... yes checking for syslog.h... yes checking for opterr... yes checking for optreset... no checking unicode/ucol.h usability... yes checking unicode/ucol.h presence... yes checking for unicode/ucol.h... yes checking for rl_completion_suppress_quote... yes checking for rl_filename_quote_characters... yes checking for rl_filename_quoting_function... yes checking for append_history... yes checking for history_truncate_file... yes checking for rl_completion_matches... yes checking for rl_filename_completion_function... yes checking for rl_reset_screen_size... yes checking for rl_variable_bind... yes checking test program... ok checking whether long int is 64 bits... yes checking for __builtin_mul_overflow... yes checking size of void *... 8 checking size of size_t... 8 checking size of long... 8 checking alignment of short... 2 checking alignment of int... 4 checking alignment of long... 8 checking alignment of double... 8 checking for int8... no checking for uint8... no checking for int64... no checking for uint64... no checking for __int128... yes checking for __int128 alignment bug... ok checking alignment of PG_INT128_TYPE... 16 checking for builtin __sync char locking functions... yes checking for builtin __sync int32 locking functions... yes checking for builtin __sync int32 atomic operations... yes checking for builtin __sync int64 atomic operations... yes checking for builtin __atomic int32 atomic operations... yes checking for builtin __atomic int64 atomic operations... yes checking for __get_cpuid... yes checking for __get_cpuid_count... yes checking for __cpuid... no checking for __cpuidex... no checking for _xgetbv with CFLAGS=... no checking for _xgetbv with CFLAGS=-mxsave... no checking for _mm512_popcnt_epi64 with CFLAGS=... no checking for _mm512_popcnt_epi64 with CFLAGS=-mavx512vpopcntdq -mavx512bw... yes checking for _mm_crc32_u8 and _mm_crc32_u32 with CFLAGS=... no checking for _mm_crc32_u8 and _mm_crc32_u32 with CFLAGS=-msse4.2... yes checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=... no checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc... no checking 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... no checking which CRC-32C implementation to use... SSE 4.2 with runtime check checking for library containing sem_init... none required checking which semaphore API to use... unnamed POSIX checking which random number source to use... OpenSSL checking for perl.h... yes checking for libperl... yes checking Python.h usability... yes checking Python.h presence... yes checking for Python.h... yes checking for xmllint... /usr/bin/xmllint checking for xsltproc... /usr/bin/xsltproc checking for fop... no checking for dbtoepub... no checking whether gcc supports -Wl,--as-needed, for LDFLAGS... yes checking whether gcc supports -Wl,--export-dynamic, for LDFLAGS_EX_BE... yes configure: 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 -O2 configure: using CPPFLAGS= -D_GNU_SOURCE configure: using LDFLAGS= -Wl,--as-needed configure: creating ./config.status config.status: creating GNUmakefile config.status: creating src/Makefile.global config.status: creating src/include/pg_config.h config.status: creating src/include/pg_config_ext.h config.status: creating src/interfaces/ecpg/include/ecpg_config.h config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s config.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_sema.c config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c config.status: linking src/include/port/linux.h to src/include/pg_config_os.h config.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.c 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 specscanner.o specscanner.c rm -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_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 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 isolationtester gmake[2]: Leaving directory '/home/postgres/postgresql-17.2/src/test/isolation' gmake -C test/perl all gmake[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 install gmake[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 --version postgres (PostgreSQL) 17.2
复制

仅客户端安装

--仅客户端安装: 如果您只想安装客户端应用程序和接口库,那么您可以使用以下命令: make -C src/bin install make -C src/include install make -C src/interfaces install make -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-openssl checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking for gcc option to accept ISO C99... none needed checking for g++... g++ checking whether we are using the GNU C++ compiler... yes checking whether g++ accepts -g... yes checking whether g++ supports -fvisibility=hidden, for CXXFLAGS_SL_MODULE... yes checking whether g++ supports -fvisibility-inlines-hidden, for CXXFLAGS_SL_MODULE... yes checking whether the C compiler still works... yes checking how to run the C preprocessor... gcc -E checking for pkg-config... /usr/bin/pkg-config checking pkg-config is at least version 0.9.0... yes checking whether to build with ICU support... yes checking for icu-uc icu-i18n... no configure: error: ICU library not found If you have ICU already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-icu to disable ICU support. [root@JiekeXu-Lix8 ~]# icu-config --version bash: 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 Unicode Proceed 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... strip checking whether it is possible to strip libraries... yes checking for ar... ar checking for a BSD-compatible install... /usr/bin/install -c checking for tar... /usr/bin/tar checking whether ln -s works... yes checking for a thread-safe mkdir -p... /usr/bin/mkdir -p checking for bison... no configure: error: bison not found [root@JiekeXu-Lix8 ~]# yum install bison -y
复制

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

解决办法:安装 flex 包

checking whether to build with ZSTD support... no checking for strip... strip checking whether it is possible to strip libraries... yes checking for ar... ar checking for a BSD-compatible install... /usr/bin/install -c checking for tar... /usr/bin/tar checking whether ln -s works... yes checking for a thread-safe mkdir -p... /usr/bin/mkdir -p checking for bison... /usr/bin/bison configure: using bison (GNU Bison) 3.0.4 checking for flex... no configure: error: flex not found [root@JiekeXu-Lix8 ~]# yum install flex -y
复制

五、配置环境变量

vi .bashrc export PGPORT=54321 export PGDATA=/home/postgres/pgdata export PGHOME=/home/postgres/postgres export 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 postgres The 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 ... ok creating subdirectories ... ok selecting dynamic shared memory implementation ... posix selecting default "max_connections" ... 100 selecting default "shared_buffers" ... 128MB selecting default time zone ... Asia/Shanghai creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... ok syncing data to disk ... ok initdb: warning: enabling "trust" authentication for local connections initdb: 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=logical archive_mode=always archive_command='cp %p /home/postgres/pgdata/archive/%f' min_wal_size=128MB max_wal_size=1GB max_wal_senders=10 hot_standby=on log_filename='pg_log_%u.log' log_file_mode=0600 log_truncate_on_rotation=on log_rotation_age=1d log_min_messages=warning log_min_duration_statement=30s synchronous_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=on log_lock_waits=on log_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'
复制

启动数据库

[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 process 2024-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 done server started [1]+ Done pg_ctl -D /home/postgres/pgdata start [postgres@JiekeXu-Lix8 pgdata]$ ### 查看状态 [postgres@JiekeXu-Lix8 pgdata]$ ps -ef | grep postgres root 75920 3774 0 Dec11 pts/1 00:00:00 su - postgres postgres 75921 75920 0 Dec11 pts/1 00:00:00 -bash root 91346 3834 0 00:13 pts/2 00:00:00 su - postgres postgres 91347 91346 0 00:13 pts/2 00:00:00 -bash postgres 91486 1 1 00:18 ? 00:00:00 /home/postgres/postgresql-17.2/bin/postgres -D /home/postgres/pgdata postgres 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 -ef postgres 91507 75921 0 00:19 pts/1 00:00:00 grep --color=auto postgres [postgres@JiekeXu-Lix8 pgdata]$ pg_ctl status pg_ctl: server is running (PID: 91486) /home/postgres/postgresql-17.2/bin/postgres "-D" "/home/postgres/pgdata"
复制

八、登录测试

--查看并启动 PG 实例 [postgres@JiekeXu-Lix8 ~]$ pg_ctl status pg_ctl: no server running [postgres@JiekeXu-Lix8 ~]$ pg_ctl start pg_ctl: another server might be running; trying to start server anyway waiting for server to start....2024-12-17 23:43:51.023 CST [29226] LOG: 00000: redirecting log output to logging collector process 2024-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 done server started [postgres@JiekeXu-Lix8 ~]$ pg_ctl status pg_ctl: server is running (PID: 29226) /home/postgres/postgresql-17.2/bin/postgres [postgres@JiekeXu-Lix8 pgdata]$ psql -U postgres -p54321 psql (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 DATABASE postgres=# \l postgres=# \c jiekexu You 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 TABLE jiekexu=# jiekexu=# insert into test values(1,'jieke'),(2,'DBA'); INSERT 0 2 jiekexu=# select * from test; id | name ----+------- 1 | jieke 2 | DBA (2 rows)
复制

图片.png

九、配置开机自启动

以前都是通过 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/postgres PGDATA="/home/postgres/pgdata" # chkconfig postgres-14 on # chkconfig --list | grep postgres
复制

先关闭数据库实例

[root@JiekeXu-Lix8 ~]# su - postgres [postgres@JiekeXu-Lix8 ~]$ pg_ctl stop waiting for server to shut down.... done server stopped [postgres@JiekeXu-Lix8 ~]$ exit logout [root@JiekeXu-Lix8 ~]# cat > /usr/lib/systemd/system/postgres.service << "EOF" cat > /usr/lib/systemd/system/postgres.service << "EOF" [Unit] Description=PostgreSQL database server After=network.target [Service] Type=forking User=postgres Group=postgres Environment=PGPORT=54321 Environment=PGDATA=/home/postgres/pgdata OOMScoreAdjust=-1000 ExecStart=/home/postgres/postgres/bin/pg_ctl start -D $PGDATA ExecStop=/home/postgres/postgres/bin/pg_ctl stop -D $PGDATA -s -m fast ExecReload=/home/postgres/postgres/bin/pg_ctl reload -D $PGDATA -s TimeoutSec=300 [Install] WantedBy=multi-user.target EOF [root@JiekeXu-Lix8 ~]# chmod +x /usr/lib/systemd/system/postgres.service [root@JiekeXu-Lix8 ~]# systemctl daemon-reload [root@JiekeXu-Lix8 ~]# systemctl enable --now postgres.service Created 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: Sy Dec 18 00:05:22 JiekeXu-Lix8 systemd[1]: Started PostgreSQL database server.
复制

图片.png

十、参考链接

https://www.modb.pro/db/1783744765954707456 https://www.postgresql.org/support/versioning/ https://en.wikipedia.org/wiki/PostgreSQL https://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
—————————————————————
facebook_pro_light_1920 × 1080  副本.png

最后修改时间:2024-12-19 09:55:14
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论

星星之火
暂无图片
2月前
评论
暂无图片 0
使用 configure 命令便可以进行相关的配置操作,可以 -h 查看相关的帮助命令进行配置
2月前
暂无图片 点赞
评论
吼吼哈嘿
暂无图片
2月前
评论
暂无图片 0
Linux 8 快速安装 PostgreSQL 17.2
2月前
暂无图片 点赞
评论
筱悦星辰
暂无图片
2月前
评论
暂无图片 0
埋首书中,为自己筑起一个精神殿堂。一椅一茶几、一灯一本书,便足以丰盈头脑、安顿身心。
2月前
暂无图片 点赞
评论