1、安装
源码安装可以参考:https://segmentfault.com/a/1190000019928714
创建postgresql的安装目录
mkdir /home/xxx/code/pg15
cd /home/xxx/code
tar -xzvf postgresql-11.4.tar.gz
创建postgresql的安装目录
mkdir /home/xxx/code/pg15/pgsql
编译安装
#debug
./configure CFLAGS="-O0" --prefix=/home/postgresql/install --enable-debug
make && make install
./configure --prefix=/home/xxx/code/pg15/pgsql CFLAGS='-g -O0 -ggdb3 -fno-omit-frame-pointer' --enable-debug
#release
./configure --prefix=/home/xxx/code/pg15/pgsql CFLAGS='-O2 ' # yong
./configure --prefix=/home/xxx/code/pg15/pgsql CFLAGS='-g -O2 -ggdb3 -fomit-frame-pointer'
安装工具集
cd /home/xxx/code/pg15/contrib
make && make install
初始化data目录
$ ./initdb -D data_dir
配置数据库允许连接
# postgresql.conf
listen_addresses = '*'
port = 24000
# pg_hba.conf
# 1、指定整个网段不进行密码认证
host test pgtest 0.0.0.0/0 trust
启动连接
#启动
./pg_ctl start -D ../../data
#访问
./createdb -p 24000 test
./psql -p 24000 test
2、调试
postgresql会对每一个客户端维护一个进程所以要去先起客户端再去gdb。如下:
1.先创一个客户端:
psql -d postgres -p 3166
2.查到客户端的进程:
ps -ef | grep post
找到idle那一行对应的进程号
3.gdb调试:
gdb -a 进程号
gdb先设置断点,然后c,sql中输入语句,就会断到对应的位置,进行单步调试
3. 环境变量配置
alias pgcrete_test='./pgsql/bin/createdb -p 20000 test'
alias pgstart='./pgsql/bin/pg_ctl start -D /home/wch/code/pg15/data'
alias pgrestart='./pgsql/bin/pg_ctl restart -D /home/wch/code/pg15/data'
alias pgstop='./pgsql/bin/pg_ctl stop -D /home/wch/code/pg15/data'
alias pgclient_test='./pgsql/bin/psql -p 20000 test'
或者
export PGPORT=2000
export rootpath=$(pwd)
export installpath=$rootpath/pgsql
export PATH=$installpath/bin:${PATH}
alias pginit='initdb -D ./data'
alias pgstart='pg_ctl start -D ./data'
alias pgrestart='pg_ctl restart -D ./data'
alias pgstop='pg_ctl stop -D ./data'
alias pgclient='psql -p 24001 pg15test'
alias pgcreatedb='psql -p 24001 pg15test'
function pggdb
{
ps ux | grep gdb
ps ux | grep postgre
}
function fileclean
{
make clean
rm -rf pgsql
mkdir pgsql
}
function pg15install_release
{
fileclean
./configure --prefix=/home/xxx/code/pg15/pgsql CFLAGS='-g -O2 -ggdb3 -fomit-frame-pointer'
make -sj && make install -sj
}
function pg15install_debug
{
fileclean
./configure --prefix=/home/xxx/code/pg15/pgsql CFLAGS='-g -O0 -ggdb3 -fno-omit-frame-pointer' --enable-debug
make -sj && make install -sj
}