(一)RedHat 7.9 安装PostgreSQL 16.2

RedHat 7.9 安装PostgreSQL 16.2

软件下载

到官网下载:
https://www.postgresql.org/ftp/source/
当前最新版本为16.2。下载最新版本16.2,后续将用这个版本来学习。
在这里插入图片描述

1 基础信息

OS版本:Red Hat Enterprise Linux Server release 7.9 (Maipo)
DB版本:16.2
pg软件目录:/home/pg16/soft
pg数据目录:/home/pg16/data
端口:5777

2 创建用户pg16

创建用户pg16,用于安装pg。

[root@test soft]# useradd pg16
[root@test soft]# passwd pg16 
Changing password for user pg16.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.

3 configure

--解压安装包
[pg16@test ~]$ cd resource/
[pg16@test resource]$ tar -zxvf postgresql-16.2.tar.gz
[pg16@test resource]$ cd postgresql-16.2/

--执行configure
[pg16@test postgresql-16.2]$ ./configure --prefix=/home/pg16/soft/
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... 5432
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... -std=gnu99
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 -std=gnu99 supports -Wdeclaration-after-statement, for CFLAGS... yes
checking whether gcc -std=gnu99 supports -Werror=vla, for CFLAGS... yes
checking whether gcc -std=gnu99 supports -Werror=unguarded-availability-new, for CFLAGS... no
checking whether g++ supports -Werror=unguarded-availability-new, for CXXFLAGS... no
checking whether gcc -std=gnu99 supports -Wendif-labels, for CFLAGS... yes
checking whether g++ supports -Wendif-labels, for CXXFLAGS... yes
checking whether gcc -std=gnu99 supports -Wmissing-format-attribute, for CFLAGS... yes
checking whether g++ supports -Wmissing-format-attribute, for CXXFLAGS... yes
checking whether gcc -std=gnu99 supports -Wimplicit-fallthrough=3, for CFLAGS... no
checking whether g++ supports -Wimplicit-fallthrough=3, for CXXFLAGS... no
checking whether gcc -std=gnu99 supports -Wcast-function-type, for CFLAGS... no
checking whether g++ supports -Wcast-function-type, for CXXFLAGS... no
checking whether gcc -std=gnu99 supports -Wshadow=compatible-local, for CFLAGS... no
checking whether g++ supports -Wshadow=compatible-local, for CXXFLAGS... no
checking whether gcc -std=gnu99 supports -Wformat-security, for CFLAGS... yes
checking whether g++ supports -Wformat-security, for CXXFLAGS... yes
checking whether gcc -std=gnu99 supports -fno-strict-aliasing, for CFLAGS... yes
checking whether g++ supports -fno-strict-aliasing, for CXXFLAGS... yes
checking whether gcc -std=gnu99 supports -fwrapv, for CFLAGS... yes
checking whether g++ supports -fwrapv, for CXXFLAGS... yes
checking whether gcc -std=gnu99 supports -fexcess-precision=standard, for CFLAGS... yes
checking whether g++ supports -fexcess-precision=standard, for CXXFLAGS... no
checking whether gcc -std=gnu99 supports -funroll-loops, for CFLAGS_UNROLL_LOOPS... yes
checking whether gcc -std=gnu99 supports -ftree-vectorize, for CFLAGS_VECTORIZE... yes
checking whether gcc -std=gnu99 supports -Wunused-command-line-argument, for NOT_THE_CFLAGS... no
checking whether gcc -std=gnu99 supports -Wcompound-token-split-by-macro, for NOT_THE_CFLAGS... no
checking whether gcc -std=gnu99 supports -Wformat-truncation, for NOT_THE_CFLAGS... no
checking whether gcc -std=gnu99 supports -Wstringop-truncation, for NOT_THE_CFLAGS... no
checking whether gcc -std=gnu99 supports -Wcast-function-type-strict, for NOT_THE_CFLAGS... no
checking whether gcc -std=gnu99 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 -std=gnu99 -E
checking for pkg-config... /bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking allow thread-safe client libraries... 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... no
checking whether to build Python modules... no
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... /bin/install -c
checking for tar... /bin/tar
checking whether ln -s works... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for bison... /bin/bison
configure: using bison (GNU Bison) 3.0.4
checking for flex... /bin/flex
configure: using flex 2.5.37
checking for perl... /bin/perl
configure: using perl 5.16.3
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /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 -std=gnu99 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 fdatasync... 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 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... /bin/lz4
checking for zstd... no
checking for openssl... /bin/openssl
configure: using openssl: OpenSSL 1.0.2k-fips  26 Jan 2017
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 for z_streamp... 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 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 -std=gnu99 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... no
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... no
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 __cpuid... no
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 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... /dev/urandom
checking for /dev/urandom... yes
checking for xmllint... /bin/xmllint
checking for xsltproc... /bin/xsltproc
checking for fop... no
checking for dbtoepub... no
checking whether gcc -std=gnu99 supports -Wl,--as-needed, for LDFLAGS... yes
checking whether gcc -std=gnu99 supports -Wl,--export-dynamic, for LDFLAGS_EX_BE... yes
configure: using compiler=gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
configure: using CFLAGS=-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -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

第一次执行configure的时候报错:

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.

下载 libicu-devel

--先确认是否有libicu-devel
[root@test ~]# icu-config --version
bash: icu-config: command not found...

--下载
[root@test ~]# yum install libicu-devel
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Resolving Dependencies
--> Running transaction check
---> Package libicu-devel.x86_64 0:50.2-4.el7_7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================
 Package                                          Arch                                       Version                                          Repository                               Size
============================================================================================================================================================================================
Installing:
 libicu-devel                                     x86_64                                     50.2-4.el7_7                                     iso                                     703 k

Transaction Summary
============================================================================================================================================================================================
Install  1 Package

Total download size: 703 k
Installed size: 3.9 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libicu-devel-50.2-4.el7_7.x86_64                                                                                                                                         1/1 
  Verifying  : libicu-devel-50.2-4.el7_7.x86_64                                                                                                                                         1/1 

Installed:
  libicu-devel.x86_64 0:50.2-4.el7_7                                                                                                                                                        

Complete!

3 make && make install

–加12并行编译

make -j 12 && make install
make world -j 12 && make install-world

4 配置环境变量

配置用户pg16的环境变量。

cat >>  ~/.bash_profile <<"EOF"

export PGHOME=/home/pg16/soft
export PGDATA=/home/pg16/data
export PGUSER=postgres
export PGPORT=5777
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib
export PATH=$PGHOME/bin:$PATH

EOF

source  ~/.bash_profile

5 初始化数据库

[pg16@test ~]$ initdb -D /home/pg16/data -U postgres -k
The files belonging to this database system will be owned by user "pg16".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are enabled.

creating directory /home/pg16/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... America/Los_Angeles
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/pg16/data -l logfile start

6 配置postgresql.conf和pg_hba.conf

6.1 配置postgresql.conf文件

listen_addresses = '*'         
port = 5777 

6.2 配置pg_hba.conf文件

添加一行:
host all all 0.0.0.0/0 trust

7 启动数据库

[pg16@test ~]$ pg_ctl start
waiting for server to start....2024-04-08 23:50:58.314 PDT [49881] LOG:  starting PostgreSQL 16.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
2024-04-08 23:50:58.314 PDT [49881] LOG:  listening on IPv4 address "0.0.0.0", port 5777
2024-04-08 23:50:58.314 PDT [49881] LOG:  listening on IPv6 address "::", port 5777
2024-04-08 23:50:58.316 PDT [49881] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5777"
2024-04-08 23:50:58.319 PDT [49884] LOG:  database system was shut down at 2024-04-08 23:46:20 PDT
2024-04-08 23:50:58.322 PDT [49881] LOG:  database system is ready to accept connections
 done
server started
[pg16@test ~]$ pg_ctl status
pg_ctl: server is running (PID: 49881)
/home/pg16/soft/bin/postgres

--登录数据库
[pg16@test ~]$ psql -p 5777
psql (16.2)
Type "help" for help.

postgres=# \l
                                                       List of databases
   Name    |  Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   
-----------+----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
 postgres  | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           | 
 template0 | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           | =c/postgres          +
           |          |          |                 |             |             |            |           | postgres=CTc/postgres
 template1 | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           | =c/postgres          +
           |          |          |                 |             |             |            |           | postgres=CTc/postgres
(3 rows)

postgres=# \q
[pg16@test ~]$ 

查看目录内容

软安装目录:/home/pg16/soft
在这里插入图片描述
数据目录:/home/pg16/data
在这里插入图片描述

目前16.2的库已经安装完成。后续将在这个环境上进行pg的学习。

谨记:心存敬畏,行有所止。

相关推荐

  1. postgresql 12 安装

    2024-04-14 02:32:03       36 阅读
  2. Docker安装Postgresql12

    2024-04-14 02:32:03       25 阅读
  3. PostgreSQL16.2安装文档

    2024-04-14 02:32:03       10 阅读
  4. 010_redhat安装zookeeper

    2024-04-14 02:32:03       10 阅读
  5. 012_redhat安装activemq

    2024-04-14 02:32:03       6 阅读
  6. PostgreSQL】- 1.1 在 Debian 12安装 PostgreSQL 15

    2024-04-14 02:32:03       23 阅读
  7. RedHat 9.3 安装 Oracle 11GR2 单机

    2024-04-14 02:32:03       5 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-14 02:32:03       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-14 02:32:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-14 02:32:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-14 02:32:03       18 阅读

热门阅读

  1. 如何在Linux中查找名为`mysql_backup.sh`的文件

    2024-04-14 02:32:03       15 阅读
  2. 使用Python实现支持向量机算法

    2024-04-14 02:32:03       12 阅读
  3. 力扣经典150题第二十题:最长公共前缀

    2024-04-14 02:32:03       11 阅读
  4. 谷歌推出无限上下文的新Transformer

    2024-04-14 02:32:03       12 阅读
  5. 制导武器的发展趋势

    2024-04-14 02:32:03       26 阅读
  6. Apache Spark

    2024-04-14 02:32:03       12 阅读
  7. 爬虫ip被限制了怎么解决

    2024-04-14 02:32:03       13 阅读
  8. MVC设计模式的思想

    2024-04-14 02:32:03       14 阅读