linux下源码安装postgresql

软件下载:
下载地址https://www.postgresql.org/ftp/source/
1

官网安装文档:https://www.postgresql.org/docs/16/installation.html

以下安装环境在centos7 x86_64平台上
数据库版本为16.3

1、安装make

yum install -y make
make --version

2、创建安装目录和安装用户

adduser postgres
mkdir -p /data/postgres/pg16
chown postgres:postgres /data/postgres/pg16

3、解压安装包并编译安装

su - postgres
tar -zxvf postgresql-16.3.tar.gz
2
./configure --prefix=/data/postgres/pg16
3
编译报错缺少icu:
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.

检查icu是否没有安装
icu-config --version

安装icu
yum install libicu-devel -y

安装完成后再重新编译
再次编译报错缺少readline,readline 的作用是能够在 pg 控制台读取历史命令,就像在 linux shell 中按上下键读取历史命令,不需要再手动输入重复的命令
checking for library containing readline… no
configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure. It is possible the compiler isn’t looking in the proper directory.
Use --without-readline to disable readline support.

安装readline
yum install -y readline-devel

再次编译报错:
checking for inflate in -lz… no
configure: error: zlib library not found
If you have zlib already installed, see config.log for details on the
failure. It is possible the compiler isn’t looking in the proper directory.
Use --without-zlib to disable zlib support.

安装zlib
yum install zlib-devel -y

再次编译成功
4

5

[postgres@node1 postgresql-16.3]$ ./configure --prefix=/data/postgres/pg16
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) 2.7
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… no
checking for zstd… no
checking for openssl… /bin/openssl
configure: using openssl: OpenSSL 1.0.1e-fips 11 Feb 2013
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-4)
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
[postgres@node1 postgresql-16.3]$

make
6

7
make install
cd /data/postgres/pg16
ll
8

4、初始化数据库实例

mkdir pgdata
/data/postgres/pg16/bin/initdb -D /data/postgres/pg16/data
9

5、启动数据库

/data/postgres/pg16/bin/pg_ctl -D /data/postgres/pg16/data -l logfile start
ps -xf|grep postgres
10

6、配置环境变量

vi ~/.bash_profile
export PGHOME=/data/postgres/pg16
export PGDATA=/data/postgres/pg16/data
PATH= P A T H : PATH: PATH:HOME/bin:$PGHOME/bin
source .bash_profile
11

7、配置监听连接

允许所有ip和用户访问数据库
vi pg_hba.conf
添加
host all all 0.0.0.0/0 md5
12
vi postgresql.conf 文件末尾添加
listen_addresses=‘*’

参数“listen_addresses”表示监听的IP地址,默认是在localhost处监听,也就是127.0.0.1的ip地址上监听,只接受来自本机localhost的连接请求,这会让远程的主机无法登陆这台数据库,如果想从其他的机器上登陆这台数据库,需要把监听地址改为实际网络的地址,把这个地址改为*,表示在本地的所有地址上监听

pg_ctl restart 重启数据库生效
13
登录数据库并修改管理员用户密码
psql
alter user postgres password ‘postgres’;
psql -h192.168.40.120 -p5432 -dpostgres -Upostgres
14

8、打开数据库日志

vi postgresql.conf 文件末尾添加
logging_collector=on
pg_ctl restart 重启数据库生效

9、设置开机自启动

PostgreSQL的开机自启动脚本位于PostgreSQL源码目录的contrib/start-scripts路径下
切换为root用户,添加linux文件X属性
复制linux文件到/etc/init.d目录下,更名为postgresql
cp /home/postgres/postgresql-16.3/contrib/start-scripts/linux /etc/init.d/postgresql
chmod a+x /etc/init.d/postgresql
ll /etc/init.d/postgresql
15
修改/etc/init.d/postgresql文件的两个变量
 prefix设置为postgresql的安装路径:/data/postgres/pg16
PGDATA设置为postgresql的数据目录路径:/data/postgres/pg16/data
设置postgresql服务开机自启动
chkconfig --add postgresql
chkconfig
16
systemctl status postgresql
systemctl stop postgresql
systemctl start postgresql
17
18

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值