postgresql 10.9 源码安装

    了解一个产品的最好方式就是熟练使用它。

    postgresql:世界上最先进的开源关系型数据库,为了熟练使用它,我们必须先安装它。

一、安装需求

    1.1,要求GNU make版本3.80或以上;其他的make程序或更老的GNU make版本将不会工作。

[root@oracle11g postgre]# make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

    1.2,你需要一个ISO/ANSI C 编译器(至少是 C89兼容的)

[root@oracle11g postgre]# rpm -qa | grep gcc
libgcc-4.4.7-3.el6.i686
gcc-c++-4.4.7-3.el6.i686
gcc-4.4.7-3.el6.i686

    1.3,pg安装时默认时将自动使用GNU Readline库,用来记忆历史命令。所以需要readline包支持,如果不想使用,可以通过configure声明--without-readline选项

[root@oracle11g Packages]# rpm -iveh readline-6.0-4.el6.i686.rpm 
warning: readline-6.0-4.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ########################################### [100%]
        package readline-6.0-4.el6.i686 is already installed

[root@oracle11g Packages]# rpm -iveh readline-devel-6.0-4.el6.i686.rpm 
warning: readline-devel-6.0-4.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ########################################### [100%]
   1:readline-devel         ########################################### [100%]

    1.4,pg安装时默认的时候将使用zlib压缩库,所以需要zlib包支持,如果不想使用,可以通过configure声明--without-zlib选项(使用这个选项关闭了在pg_dump和pg_restore中对压缩归档的支持)。

[root@oracle11g Packages]# rpm -ivh zlib-1.2.3-29.el6.i686.rpm 
warning: zlib-1.2.3-29.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ########################################### [100%]
        package zlib-1.2.3-29.el6.i686 is already installed
[root@oracle11g Packages]# rpm -ivh zlib-devel-1.2.3-29.el6.i686.rpm 
warning: zlib-devel-1.2.3-29.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ########################################### [100%]
   1:zlib-devel             ########################################### [100%]

1.3,源码包(我已解压)(下载地址为https://www.postgresql.org/ftp/source/v10.9/

[root@oracle11g soft]# ls
postgresql-10.9  postgresql-10.9.tar

二、安装流程

    2.1,创建用户

[root@oracle11g soft]# useradd postgres

    2.2,解压源码包

[root@oracle11g soft]#gunzip postgresql-10.9.tar.gz
[root@oracle11g soft]#tar -xf postgresql-10.9.tar
[root@oracle11g soft]#ls
postgresql-10.9  postgresql-10.9.tar

    2.3,安装目录配置

[root@oracle11g soft]#mkdir -p /postgre/pgsql
[root@oracle11g soft]#mkdir -p /postgre/data
[root@oracle11g soft]#chown postgres /postgre/data

    2.4,安装(在此我configure的时候通过指定--prefiex参数,来指定pg安装目录,而不是使用默认的安装路径/usr/local/pgsql)

[root@oracle11g postgresql-10.9]# ./configure --prefix=/postgre/pgsql
checking build system type... i686-pc-linux-gnu
checking host system type... i686-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 WAL segment size... 16MB
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 whether gcc supports -Wdeclaration-after-statement... yes
checking whether gcc supports -Wendif-labels... yes
checking whether gcc supports -Wmissing-format-attribute... yes
checking whether gcc supports -Wformat-security... yes
checking whether gcc supports -fno-strict-aliasing... yes
checking whether gcc supports -fwrapv... yes
checking whether gcc supports -fexcess-precision=standard... no
checking whether gcc supports -funroll-loops... yes
checking whether gcc supports -ftree-vectorize... yes
checking whether gcc supports -Wunused-command-line-argument... no
checking whether gcc supports -Wformat-truncation... no
checking whether gcc supports -Wstringop-truncation... no
checking whether the C compiler still works... yes
checking how to run the C preprocessor... gcc -E
checking allow thread-safe client libraries... yes
checking whether to build with ICU support... no
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 OpenSSL support... no
checking whether to build with SELinux support... no
checking whether to build with systemd support... no
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ld used by GCC... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for ranlib... ranlib
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... /bin/tar
checking whether ln -s works... yes
checking for gawk... gawk
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for bison... no
configure: WARNING:
*** Without Bison you will not be able to build PostgreSQL from Git nor
*** change any of the parser definition files.  You can obtain Bison from
*** a GNU mirror site.  (If you are using the official distribution of
*** PostgreSQL then you do not need to worry about this, because the Bison
*** output is pre-generated.)
checking for flex... no
configure: WARNING:
*** Without Flex you will not be able to build PostgreSQL from Git nor
*** change any of the scanner definition files.  You can obtain Flex from
*** a GNU mirror site.  (If you are using the official distribution of
*** PostgreSQL then you do not need to worry about this because the Flex
*** output is pre-generated.)
checking for perl... /usr/bin/perl
configure: using perl 5.10.1
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 if compiler needs certain flags to reject unknown flags... no
checking for the pthreads library -lpthreads... no
checking whether pthreads work without any flags... no
checking whether pthreads work with -Kthread... no
checking whether pthreads work with -kthread... no
checking for the pthreads library -llthread... no
checking whether pthreads work with -pthread... yes
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking if 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 for getpwuid_r... yes
checking for gethostbyname_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 dlopen... -ldl
checking for library containing socket... none required
checking for library containing shl_load... no
checking for library containing getopt_long... none required
checking for library containing crypt... -lcrypt
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 sched_yield... none required
checking for library containing gethostbyname_r... none required
checking for library containing shmget... none required
checking for library containing readline... -lreadline
checking for inflate in -lz... yes
checking atomic.h usability... no
checking atomic.h presence... no
checking for atomic.h... no
checking crypt.h usability... yes
checking crypt.h presence... yes
checking for crypt.h... yes
checking dld.h usability... no
checking dld.h presence... no
checking for dld.h... no
checking fp_class.h usability... no
checking fp_class.h presence... no
checking for fp_class.h... no
checking getopt.h usability... yes
checking getopt.h presence... yes
checking for getopt.h... yes
checking ieeefp.h usability... no
checking ieeefp.h presence... no
checking for ieeefp.h... no
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 poll.h usability... yes
checking poll.h presence... yes
checking for poll.h... yes
checking sys/epoll.h usability... yes
checking sys/epoll.h presence... yes
checking for sys/epoll.h... yes
checking sys/ipc.h usability... yes
checking sys/ipc.h presence... yes
checking for sys/ipc.h... yes
checking sys/pstat.h usability... no
checking sys/pstat.h presence... no
checking for sys/pstat.h... no
checking sys/resource.h usability... yes
checking sys/resource.h presence... yes
checking for sys/resource.h... yes
checking sys/select.h usability... yes
checking sys/select.h presence... yes
checking for sys/select.h... yes
checking sys/sem.h usability... yes
checking sys/sem.h presence... yes
checking for sys/sem.h... yes
checking sys/shm.h usability... yes
checking sys/shm.h presence... yes
checking for sys/shm.h... yes
checking sys/sockio.h usability... no
checking sys/sockio.h presence... no
checking for sys/sockio.h... no
checking sys/tas.h usability... no
checking sys/tas.h presence... no
checking for sys/tas.h... no
checking sys/un.h usability... yes
checking sys/un.h presence... yes
checking for sys/un.h... yes
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 utime.h usability... yes
checking utime.h presence... yes
checking for utime.h... yes
checking wchar.h usability... yes
checking wchar.h presence... yes
checking for wchar.h... yes
checking wctype.h usability... yes
checking wctype.h presence... yes
checking for wctype.h... yes
checking for net/if.h... yes
checking for sys/ucred.h... no
checking for netinet/tcp.h... yes
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 whether byte ordering is bigendian... no
checking for inline... inline
checking for printf format archetype... gnu_printf
checking for flexible array members... yes
checking for signed types... yes
checking for __func__... yes
checking for _Static_assert... no
checking for typeof... typeof
checking for __builtin_types_compatible_p... yes
checking for __builtin_bswap32... yes
checking for __builtin_bswap64... yes
checking for __builtin_constant_p... yes
checking for __builtin_unreachable... yes
checking for computed goto support... yes
checking for __VA_ARGS__... yes
checking whether struct tm is in sys/time.h or time.h... time.h
checking for struct tm.tm_zone... yes
checking for tzname... yes
checking for union semun... no
checking for struct sockaddr_un... yes
checking for struct sockaddr_storage... yes
checking for struct sockaddr_storage.ss_family... yes
checking for struct sockaddr_storage.__ss_family... no
checking for struct sockaddr_storage.ss_len... no
checking for struct sockaddr_storage.__ss_len... no
checking for struct sockaddr.sa_len... no
checking for struct addrinfo... yes
checking for intptr_t... yes
checking for uintptr_t... yes
checking for unsigned long long int... yes
checking for long long int... yes
checking for locale_t... yes
checking for struct cmsgcred... no
checking for struct option... yes
checking for z_streamp... yes
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... 64
checking size of off_t... 8
checking for int timezone... yes
checking types of arguments for accept()... int, int, struct sockaddr *, size_t *
checking whether gettimeofday takes only one argument... no
checking for wcstombs_l declaration... no
checking for cbrt... yes
checking for clock_gettime... yes
checking for dlopen... yes
checking for fdatasync... yes
checking for getifaddrs... yes
checking for getpeerucred... no
checking for getrlimit... yes
checking for mbstowcs_l... no
checking for memmove... yes
checking for poll... yes
checking for posix_fallocate... yes
checking for pstat... no
checking for pthread_is_threaded_np... no
checking for readlink... yes
checking for setproctitle... no
checking for setsid... yes
checking for shm_open... yes
checking for symlink... yes
checking for sync_file_range... yes
checking for towlower... yes
checking for uselocale... yes
checking for utime... yes
checking for utimes... yes
checking for wcstombs... yes
checking for wcstombs_l... no
checking for fseeko... 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 F_FULLFSYNC is declared... no
checking for struct sockaddr_in6... yes
checking for PS_STRINGS... no
checking for snprintf... yes
checking for vsnprintf... yes
checking whether snprintf is declared... yes
checking whether vsnprintf is declared... yes
checking for isinf... yes
checking for crypt... yes
checking for fls... no
checking for getopt... yes
checking for getrusage... yes
checking for inet_aton... yes
checking for mkdtemp... yes
checking for random... yes
checking for rint... yes
checking for srandom... yes
checking for strerror... yes
checking for strlcat... no
checking for strlcpy... no
checking for unsetenv... yes
checking for getpeereid... no
checking for getaddrinfo... yes
checking for getopt_long... yes
checking whether sys_siglist is declared... 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 for strtoll... yes
checking for strtoull... yes
checking whether strtoll is declared... yes
checking whether strtoull is declared... yes
checking for rl_completion_append_character... yes
checking for rl_completion_matches... yes
checking for rl_filename_completion_function... yes
checking for rl_reset_screen_size... yes
checking for append_history... yes
checking for history_truncate_file... yes
checking test program... ok
checking whether long int is 64 bits... no
checking whether long long int is 64 bits... yes
checking snprintf length modifier for long long int... ll
checking whether snprintf supports the %z modifier... yes
checking size of void *... 4
checking size of size_t... 4
checking size of long... 4
checking whether to build with float4 passed by value... yes
checking whether to build with float8 passed by value... no
checking alignment of short... 2
checking alignment of int... 4
checking alignment of long... 4
checking alignment of long long int... 4
checking alignment of double... 4
checking for int8... no
checking for uint8... no
checking for int64... no
checking for uint64... no
checking for __int128... no
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... no
checking for builtin __atomic int64 atomic operations... no
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 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 for /dev/urandom... yes
checking which random number source to use... /dev/urandom
checking for onsgmls... no
checking for nsgmls... no
checking for DocBook V4.2... no
checking for dbtoepub... no
checking for xmllint... /usr/bin/xmllint
checking for xsltproc... /usr/bin/xsltproc
checking for osx... no
checking for sgml2xml... no
checking for sx... no
checking for fop... no
checking thread safety of required library functions... yes
checking whether gcc supports -Wl,--as-needed... yes
configure: using compiler=gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3)
configure: using CFLAGS=-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -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/dynloader/linux.c to src/backend/port/dynloader.c
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/backend/port/dynloader/linux.h to src/include/dynloader.h
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


#此处编译过程太长,不再贴上,只贴上结果一部分结果
[root@oracle11g postgresql-10.9]# make
。。。。。。。。。。。。。。。。。。。。
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 isolation_main.o pg_regress.o -L../../../src/port -L../../../src/common   -Wl,--as-needed -Wl,-rpath,'/postgre/pgsql/lib',--enable-new-dtags  -lpgcommon -lpgport -lz -lreadline -lrt -lcrypt -ldl -lm  -o pg_isolation_regress
make[2]: Leaving directory `/postgre/soft/postgresql-10.9/src/test/isolation'
make -C test/perl all
make[2]: Entering directory `/postgre/soft/postgresql-10.9/src/test/perl'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/postgre/soft/postgresql-10.9/src/test/perl'
make[1]: Leaving directory `/postgre/soft/postgresql-10.9/src'
make -C config all
make[1]: Entering directory `/postgre/soft/postgresql-10.9/config'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/postgre/soft/postgresql-10.9/config'
All of PostgreSQL successfully made. Ready to install.


#此处安装过程同上,不再贴上,只贴上结果一部分结果
[root@oracle11g postgresql-10.9]# make
。。。。。。。。。。。。。。。。。。。。。。。
make[1]: Leaving directory `/postgre/soft/postgresql-10.9/src'
make -C config install
make[1]: Entering directory `/postgre/soft/postgresql-10.9/config'
/bin/mkdir -p '/postgre/pgsql/lib/pgxs/config'
/usr/bin/install -c -m 755 ./install-sh '/postgre/pgsql/lib/pgxs/config/install-sh'
/usr/bin/install -c -m 755 ./missing '/postgre/pgsql/lib/pgxs/config/missing'
make[1]: Leaving directory `/postgre/soft/postgresql-10.9/config'
PostgreSQL installation complete.

    2.5,安装后配置

    配置环境变量(root和postgres用户都配置)

[root@oracle11g ~]# vi ~/.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/postgre/pgsql/bin

export PATH
MANPATH=/postgre/pgsql/share/man:$MANPATH
export MANPATH

    2.6,初始化数据库

[root@oracle11g ~]# su - postgres
[postgres@oracle11g data]$ initdb -D /postgre/pgsql/data
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 "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 disabled.

fixing permissions on existing directory /postgre/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... US/Pacific
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
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 /postgre/pgsql/data -l logfile start

    2.7,启动数据库服务

[postgres@oracle11g data]$ pg_ctl -D /postgre/pgsql/data -l logfile start
waiting for server to start.... done
server started
[postgres@oracle11g data]$ ps -ef | grep post
root      2101     1  0 07:48 ?        00:00:00 /usr/libexec/postfix/master
postfix   2107  2101  0 07:48 ?        00:00:00 qmgr -l -t fifo -u
postfix  14593  2101  0 19:12 ?        00:00:00 pickup -l -t fifo -u
root     29930 14850  0 20:42 pts/1    00:00:00 su - postgres
postgres 29931 29930  0 20:42 pts/1    00:00:00 -bash
postgres 30028     1  0 20:47 pts/1    00:00:00 /postgre/pgsql/bin/postgres -D /postgre/pgsql/data
postgres 30030 30028  0 20:47 ?        00:00:00 postgres: checkpointer process                    
postgres 30031 30028  0 20:47 ?        00:00:00 postgres: writer process                          
postgres 30032 30028  0 20:47 ?        00:00:00 postgres: wal writer process                      
postgres 30033 30028  0 20:47 ?        00:00:00 postgres: autovacuum launcher process             
postgres 30034 30028  0 20:47 ?        00:00:00 postgres: stats collector process                 
postgres 30035 30028  0 20:47 ?        00:00:00 postgres: bgworker: logical replication launcher   
postgres 30037 29931  2 20:47 pts/1    00:00:00 ps -ef
postgres 30038 29931  0 20:47 pts/1    00:00:00 grep post

    2.8,测试

[postgres@oracle11g data]$ createdb test
[postgres@oracle11g data]$ 
[postgres@oracle11g data]$ 
[postgres@oracle11g data]$ psql test
psql (10.9)
Type "help" for help.

test=# 
test=# 
test=# 

至此整个pg10.9源码安装完成。

                                                  欢迎大家关注以下公众号进行数据库方面知识探讨:

                                                           

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值