git clone https://github.com/postgres/postgres.gitgit
若是不熟悉源代码目录结构,能够看文章:《第 3 课 PostgreSQL代码结构》,我这里就不赘述了。
进入根目录下,执行下面命令:github
$./configure --prefix=`pwd`/release --with-openssl --without-ldap --with-libxml --enable-thread-safety --enable-debugweb
–prefix=`pwd`/release: 指定安装目录为当前目录下的release。
–enable-debug : 保留语法符号,避免install时目标文件被strip掉了符号,调试时没法看到堆栈函数和变量名。sql
configure 过程当中会出现不少依赖包找不到,若是你连了网,你能够本身安装须要包。服务器
$yum install xxxx;svg
若是不知道全名和选择那个平台能够查找:函数
$yum search xxxx;oop
若是你先前已经执行./configure过,可是你想从新来过,你能够使用下面的命令恢复原状:源码分析
$ make distclean
$make clean只是清除编译产生的中间和目标文件,make distclean能够清除configure产生的文件和安装目录,反正就是恢复到初始状态。
./configrue完成后,在目录下会产生一些新的文件文件。
$ ls
aclocal.m4 config configure configure.in contrib COPYRIGHT doc GNUmakefile.in HISTORY Makefile README README.git src
$ ls
aclocal.m4 config config.log config.status configure configure.in contrib COPYRIGHT doc GNUmakefile GNUmakefile.in HISTORY Makefile README README.git src
咱们关注须要的文件:GNUmakefile, src/Makefile.global。GNUmakefile是由GNUmakefile.in模板生成。Makefile.global是由Makefile.global.in模板文件生成而来。
260 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 -g -O2 261 CFLAGS_VECTOR = -funroll-loops -ftree-vectorize 262 CFLAGS_SSE42 = -msse4.2 263 CFLAGS_ARMV8_CRC32C = 264 CXXFLAGS = -Wall -Wpointer-arith -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -g -O2
260 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 -g -O0 261 CFLAGS_VECTOR = -funroll-loops -ftree-vectorize 262 CFLAGS_SSE42 = -msse4.2 263 CFLAGS_ARMV8_CRC32C = 264 CXXFLAGS = -Wall -Wpointer-arith -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -g -O0
在根目录下,执行:
$ make -j4
若是你是多核虚拟机,你能够-jx, x就是你的核数,能够加快编译速度,第一次编译大约须要3~5分钟。
$make install
会安装到你configure配置的–prefix指定的目录,我是在当前目录的release下:
$ ls bin include lib share
进入bin目录,初始化服务:
$ ./initdb -D …/data -Uwangwei -W
Enter new superuser password:
启动:
$ ./pg_ctl start -D …/data
查看进程:
$ ps -ef|grep postgres
>$ ./psql -d postgres -Upostgres -W Password: postgres=# select version(); version ------------------------------------------------------------------------------------------------------------ PostgreSQL 12devel on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28), 64-bit (1 row) postgres=# \dn+ List of schemas Name | Owner | Access privileges | Description --------+----------+----------------------+------------------------ public | postgres | postgres=UC/postgres+| standard public schema | | =UC/postgres | (1 row) postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | template0 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres (3 rows)