前言
因為工作需要最近在研究 postgresql DB,postgresql DB 是一個 Open Source RDBMS,所以有任何問題疑問都可以把 source code 下載並 debug 了解原因,本篇希望可以快速幫助想要透過 source code 安裝 postgresql DB 的人
Install Postgresl
假如你跟我一樣是 Ubuntu 在安裝前需要先把開發環境設定完畢,詳細資訊可參考 Postgresql Compile_and_Install_from_source_code
1 | sudo apt-get update |
我們可以透過 FTP Source Code 要安裝 postgres source code 版本
假如我是要安裝 v12.9 的 postgres 版本,我會跑下面命令下載 source code & 解壓縮
解壓縮完畢後,應該會在該目錄看到一個該版號資料夾裡面存放的就是該版本使用 Postgresql source code.
1 | wget https://ftp.postgresql.org/pub/source/v12.9/postgresql-12.9.tar.gz |
利用 source code 安裝 postgres
configure
:透過參數設定 postgres 相關設定 & 安裝位置….make
:透過 Makefile 安裝 postgres db
1 | ./configure |
PostgreSQL ./configure options
- –prefix=PREFIX install architecture-independent files in PREFIX. Default installation location is /usr/local/pgsql
- –enable-integer-datetimes enable 64-bit integer date/time support
- –enable-nls[=LANGUAGES] enable Native Language Support
- –disable-shared do not build shared libraries
- –disable-rpath do not embed shared library search path in executables
- –disable-spinlocks do not use spinlocks
- –enable-debug build with debugging symbols (-g)
- –enable-profiling build with profiling enabled
- –enable-dtrace build with DTrace support
- –enable-depend turn on automatic dependency tracking
- –enable-cassert enable assertion checks (for debugging)
- –enable-thread-safety make client libraries thread-safe
- –enable-thread-safety-force force thread-safety despite thread test failure
- –disable-largefile omit support for large files
- –with-docdir=DIR install the documentation in DIR [PREFIX/doc]
- –without-docdir do not install the documentation
- –with-includes=DIRS look for additional header files in DIRS
- –with-libraries=DIRS look for additional libraries in DIRS
- –with-libs=DIRS alternative spelling of –with-libraries
- –with-pgport=PORTNUM change default port number [5432]
- –with-tcl build Tcl modules (PL/Tcl)
- –with-tclconfig=DIR tclConfig.sh is in DIR
- –with-perl build Perl modules (PL/Perl)
- –with-python build Python modules (PL/Python)
- –with-gssapi build with GSSAPI support
- –with-krb5 build with Kerberos 5 support
- –with-krb-srvnam=NAME default service principal name in Kerberos [postgres]
- –with-pam build with PAM support
- –with-ldap build with LDAP support
- –with-bonjour build with Bonjour support
- –with-openssl build with OpenSSL support
- –without-readline do not use GNU Readline nor BSD Libedit for editing
- –with-libedit-preferred prefer BSD Libedit over GNU Readline
- –with-ossp-uuid use OSSP UUID library when building contrib/uuid-ossp
- –with-libxml build with XML support
- –with-libxslt use XSLT support when building contrib/xml2
- –with-system-tzdata=DIR use system time zone data in DIR
- –without-zlib do not use Zlib
- –with-gnu-ld assume the C compiler uses GNU ld [default=no]
假如在 ./configure
沒有特別設定 –prefix
檔案位置預設為 /usr/local/pgsql/
所以我們可以透過下面命令查看安裝結果是否正確
1 | # ls -l /usr/local/pgsql/ |
建立 postgres user
建立一個 postgres user 並給密碼
1 | # adduser postgres |
初始化 postgres data 路徑
建立一個資料夾並把權限設定給剛剛建立 postgres user
因為該使用者需要有權限寫入此資料夾
1 | mkdir /usr/local/pgsql/data |
user mode 切換成 postgres user,並利用 initdb
初始化資料庫
1 | # su - postgres |
查看 /usr/local/pgsql/data
資料夾應該會有如下檔案
1 | ls -l /usr/local/pgsql/data |
啟動 postgres db
最後利用 postgres user 執行 postmaster
啟動 postgres db
1 | $ /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data >logfile 2>&1 & |
啟動完畢後可以利用 psql
進入 postgres 操作 db
1 | #/usr/local/pgsql/bin/psql |
小結
希望透過這邊文章可以幫助大家,利用 postgres source code 安裝 db 環境,並進行 debug & 調式,詳細文章可以參考官網 Installation from Source Code
此文作者:Daniel Shih(石頭)
此文地址: https://isdaniel.github.io/postgresql-debug-source-code/
版權聲明:本博客所有文章除特別聲明外,均採用 CC BY-NC-SA 3.0 TW 許可協議。轉載請註明出處!