1. 下載源代碼
- 首先在https://github.com/上找到postgre項(xiàng)目源碼,我?guī)湍阏业搅耍?/li>
-
clone 源代碼:點(diǎn)擊下圖位置乞旦,copy倉(cāng)庫(kù)URL贼穆。
- 在Linux下clone代碼。
git clone https://github.com/postgres/postgres.git
2. 配置
如果不熟悉源代碼目錄結(jié)構(gòu)兰粉,可以看文章:《第 3 課 PostgreSQL代碼結(jié)構(gòu)》故痊,我這里就不贅述了。
進(jìn)入根目錄下玖姑,執(zhí)行下面命令:
$./configure --prefix=`pwd`/release --with-openssl --without-ldap --with-libxml --enable-thread-safety --enable-debug
--prefix=`pwd`/release: 指定安裝目錄為當(dāng)前目錄下的release愕秫。
--enable-debug : 保留語(yǔ)法符號(hào),避免install時(shí)目標(biāo)文件被strip掉了符號(hào)焰络,調(diào)試時(shí)無(wú)法看到堆棧函數(shù)和變量名戴甩。
configure 過(guò)程中會(huì)出現(xiàn)很多依賴(lài)包找不到,如果你連了網(wǎng)闪彼,你可以自己安裝需要包甜孤。
$yum install xxxx协饲;
如果不知道全名和選擇那個(gè)平臺(tái)可以查找:
$yum search xxxx;
如果你先前已經(jīng)執(zhí)行./configure過(guò),但是你想重新來(lái)過(guò)缴川,你可以使用下面的命令恢復(fù)原狀:
$ make distclean
$make clean只是清除編譯產(chǎn)生的中間和目標(biāo)文件茉稠,make distclean可以清除configure產(chǎn)生的文件和安裝目錄,反正就是恢復(fù)到初始狀態(tài)把夸。
./configrue完成后而线,在目錄下會(huì)產(chǎn)生一些新的文件文件。
- configure前:
$ ls
aclocal.m4 config configure configure.in contrib COPYRIGHT doc GNUmakefile.in HISTORY Makefile README README.git src
- configure后:
$ ls
aclocal.m4 config config.log config.status configure configure.in contrib COPYRIGHT doc GNUmakefile GNUmakefile.in HISTORY Makefile README README.git src
我們關(guān)注需要的文件:GNUmakefile, src/Makefile.global恋日。GNUmakefile是由GNUmakefile.in模板生成膀篮。Makefile.global是由Makefile.global.in模板文件生成而來(lái)。
修改Makefile.global中的編譯選項(xiàng):O2改為O0岂膳,這樣編譯出來(lái)未優(yōu)化誓竿,方便調(diào)試代碼。
- 修改前:
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
3. 編譯代碼
在根目錄下闷营,執(zhí)行:
$ make -j4
如果你是多核虛擬機(jī),你可以-jx, x就是你的核數(shù)知市,可以加快編譯速度傻盟,第一次編譯大約需要3~5分鐘。
4. 安裝
$make install
會(huì)安裝到你configure配置的--prefix指定的目錄嫂丙,我是在當(dāng)前目錄的release下:
$ ls
bin include lib share
進(jìn)入bin目錄娘赴,初始化服務(wù):
$ ./initdb -D ../data -Uwangwei -W
Enter new superuser password:
啟動(dòng):
$ ./pg_ctl start -D ../data
查看進(jìn)程:
$ ps -ef|grep postgres
image.png
5. 連接服務(wù)器
>$ ./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)
發(fā)現(xiàn)更多寶藏
我在喜馬拉雅上分享聲音
《PostgreSQL數(shù)據(jù)庫(kù)內(nèi)核分析》,點(diǎn)開(kāi)鏈接可以聽(tīng)聽(tīng)跟啤,有點(diǎn)意思诽表。
《數(shù)據(jù)庫(kù)系統(tǒng)概論(第4版)》,點(diǎn)開(kāi)鏈接可以聽(tīng)聽(tīng)隅肥,有點(diǎn)意思竿奏。
更多IT有聲課程,點(diǎn)我發(fā)現(xiàn)更多
其他相關(guān)文章分享列表:
第 23 課 PostgreSQL 創(chuàng)建自己的數(shù)據(jù)庫(kù)腥放、模式泛啸、用戶(hù)
第 22 課 PostgreSQL 控制文件
第 21 課 PostgreSQL 日志系統(tǒng)
第 16 課 查詢(xún)過(guò)程源碼分析
第 15 課 PostgreSQL 系統(tǒng)參數(shù)配置
第 14 課 PostgreSQL 數(shù)據(jù)存儲(chǔ)結(jié)構(gòu)
第 13 課 PostgreSQL 存儲(chǔ)之Page(頁(yè)面)源碼分析
第 12 課 PostgreSQL 認(rèn)證方式
第 11 課 PostgreSQL 增加一個(gè)內(nèi)核C函數(shù)
第 10 課 PostgreSQL 在內(nèi)核增加一個(gè)配置參數(shù)
第 09 課 PostgreSQL 4種進(jìn)程啟動(dòng)方式
第 08 課 PostgreSQL 事務(wù)介紹
第 07 課 PostgreSQL 數(shù)據(jù)庫(kù)、模式秃症、表候址、空間、用戶(hù)間的關(guān)系
第 06 課 PostgreSQL 系統(tǒng)表介紹
第 05 課 PostgreSQL 編譯源代碼進(jìn)行開(kāi)發(fā)
第 04 課 PostgreSQL 安裝最新的版本
第 03 課 PostgreSQL 代碼結(jié)構(gòu)
第 02 課 PostgreSQL 的特性种柑、應(yīng)用岗仑、安裝
第 01 課 PostgreSQL 簡(jiǎn)介及發(fā)展歷程
上面文章都在專(zhuān)輯中:PostgreSQL專(zhuān)輯鏈接,點(diǎn)我查看
如果有用聚请,可以收藏這篇文件荠雕,隨時(shí)在更新....
更多交流加群: PostgreSQL內(nèi)核開(kāi)發(fā)群 876673220
親,記得點(diǎn)贊、留言舞虱、打賞額;都省!矾兜!