postgresql 源码安装

  • A+
所属分类:数据库

=== 安装postgresql ===

【清理老版本】

lsof -i:5432
$ kill -9 *** (删除老的进程)
find / -name 'postgres' 2>/dev/null
删除相关目录

【安装python3】

[如已装,略过,建议源码安装]

  • [Mac]
    brew install python3
  • [Ubuntu]
    apt-get install python3
  • [源码] 请自行切换版本
#!usr/bin/bash
cd soft
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
tar -zxvf Python-3.6.1.tgz
cd Python-3.6.1
./configure --enable-shared --enable-optimizations
make && sudo make install

【测试python3】

#!usr/bin/bash
$ python3

如出现以下错误:
[error] python3.6: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory

则需要从解压后的路径复制文件的依赖库目录

#!usr/bin/bash
cp libpython3.6m.so.1.0 /usr/local/lib64/
cp libpython3.6m.so.1.0 /usr/lib/
cp libpython3.6m.so.1.0 /usr/lib64/

【安装postgresql】

[如已编译过可直接使用编译后的版本,使用前make uninstall && make clean]

#!usr/bin/bash
cd soft
wget https://ftp.postgresql.org/pub/source/v9.6.5/postgresql-9.6.5.tar.gz
tar -zxvf postgresql-9.6.5.tar.gz

cd postgresql-9.6.5
# [特别注意python3的路径要对]
./configure --prefix=/usr/local/pgsql --with-python PYTHON=/usr/local/bin/python3

# 如果提示readline未安装, 先安装readline-devel
make world
sudo make install-world

【设置路径环境变量】

#!usr/bin/bash
vi ~/.bash_profile
# 添加一行: 
export PATH=$PATH:/usr/local/pgsql/bin
source ~/.bash_profile

vi ~/.config/fish/config.fish
# 添加一行: 
set -x PATH $PATH /usr/local/pgsql/bin

sudo rm /usr/bin/psql
sudo ln -s /usr/local/pgsql/bin/psql /usr/bin/psql

【启动服务】

initdb -D ~/pgdata
pg_ctl -D ~/pgdata -l ~/logfile start

【创建user】

createuser *** superuser login password '****'

【设置数据库环境变量】[可选]

vi ~/.bash_profile export PGHOST=localhost export PGPORT=5432 export PGUSER=***

【安装插件】

[plv8]:

#!usr/bin/bash
cd soft
wget http://updates.xtuple.com/updates/plv8/{mac|linux64}/xtuple_plv8.tgz
tar -zxvf xtuple_plv8.tgz
cd xtuple_plv8.tgz
sudo sh -x install_plv8.sh

# 如果提示没有文件, 先复制这些文件:
cp./plv8.control/usr/local/pgsql/share/extension/plv8.control
cp./plv8--2.2.0.sql/usr/local/pgsql/share/extension/plv8--2.2.0.sql
# 如果提示ould not load library "/usr/local/pgsql/lib/plv8.so": libc++.so.1: cannot open shared object file: No such file or directory 则需要安装libc++.so
yuminstalllibcxx.x86_64

测试plv8有没有安装好:  psql -d yks -c 'create extension plv8'

[pgjwt]

#!usr/bin/bash
cd soft
git clone https://github.com/michelp/pgjwt
cd pgjwt
sudo make install

=== 附:其他工具安装 ===

【sqitch】

[linux]

#!usr/bin/bash
sudo yum install perl-devel perl-CPAN && curl -L http://cpanmin.us | perl - --sudo App::cpanminus
cpanm --quiet --notest App::Sqitch
yum install perl-DBD-Pg

postgrest


3. postgrest
$ wget https://github.com/begriffs/postgrest/releases/download/v0.4.2.0/postgrest-0.4.2.0-centos.tar.xz
$ tar Jxf postgrest-0.4.2.0-centos.tar.xz
$ ~/postgrest code/crm/crm-db/postgrest.conf < /dev/null > postgrest.log 2>&1 &

-- sudo ln -s ./postgrest /usr/bin/postgrest
楚廉

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: