PostgreSQL编译安装

PostgreSQL编译安装

  • 安装语言包
### PostgreSQL 初始化过程中,会读取操作系统字符编码,
### 若程序需要使用zh_CN.utf-8字符编码,需要在PostgreSQL 初始化之前安装中文包,再初始化PostgreSQL,
### 否则未安装中文包初始化数据库,会导致数据库字符编码格式没有h_CN.utf-8字符编码格式,影响程序后期使用

# sudo apt-get install language-pack-zh*
# sudo apt-get install language-pack-en*
  • 安装编译所需依赖包:
# sudo apt-get install -y libtool libapr1 make gcc libexpat1-dev
# sudo apt install libreadline5-dev 
# sudo apt install libreadline-gplv2-dev
# sudo apt install zlib1g-dev
# sudo apt install uuid-dev libossp-uuid-dev
  • 编译PostgreSQL:
# cd /Sioeye/SioApps/Environment/
# wget https://ftp.postgresql.org/pub/source/v10.6/postgresql-10.6.tar.gz

# tar -zxvf postgresql-10.6.tar.gz
# cd postgresql-10.6/

# ./configure --prefix=/Sioeye/SioApps/Environment/postgresql --with-ossp-uuid
# make
# make install

# cd contrib/
# make
# make install
  • 创建postgres用户
### 创建postgres用户
# groupadd postgres
# useradd -g postgres -m postgres

### 设置用户密码
# passwd postgres

### 创建数据存储目录,并授权postgres用户所属权限
# mkdir -pv /Sioeye/Data/postgresql/data
# chown postgres:postgres /Sioeye/SioApps/Environment/postgresql -R
# chown postgres:postgres /Sioeye/Data/postgresql/data -R
  • 初始化PostgreSQL
### 切换用户,并设置基础环境变量。
# su - postgres
# vim ~/.bash_profile

### 在其文件最底下追加以下配置
export PGHOME=/Sioeye/SioApps/Environment/postgresql
export PGDATA=/Sioeye/Data/postgresql/data/
export PATH=$PGHOME/bin:$PATH
export MANPATH=$PGHOME/share/man:$MANPATH
export LANG=en_US.utf8
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH

# source ~/.bash_profile

### 初始化数据库
# initdb -D /Sioeye/Data/postgresql/data

### 创建日志存储目录,启动数据库
# mkdir /Sioeye/Data/logs/postgresql
# pg_ctl -D /Sioeye/Data/postgresql/data -l /Sioeye/Data/logs/postgresql/start_logs.log start
  • 设置postgres用户密码
### 此处设置数据库用户密码,而非操作系统用户密码
# psql
postgres=# alter user postgres with password '123456';
  • 设置开机启动
### 从源码中拷贝启动脚本到/etc/init.d/目录
# cd /Sioeye/SioApps/Environment/postgresql-10.6/start-scripts/
# cp linux /etc/init.d/postgresql

### 修改默认配置
# vim /etc/init.d/postgresql

##############################################
# Installation prefix
prefix=/Sioeye/SioApps/Environment/postgresql

# Data directory
PGDATA="/Sioeye/Data/postgresql/data/"

# Who to run the postmaster as, usually "postgres".  (NOT "root")
PGUSER=postgres

PGLOG="/Sioeye/Data/logs/postgresql/"

# Where to keep a log file
PGLOG="$PGLOG/serverlog"
##############################################

# chmod a+x /etc/init.d/postgresql
# chkconfig  --add postgresql
# update-rc.d postgresql defaults 98
  • 按需修改pg_hba.conf,postgresql.conf文件
### /Sioeye/Data/postgresql/data/pg_hba.conf 文件最后追加
host all all 0.0.0.0 0.0.0.0 md5
### /Sioeye/Data/postgresql/data/postgresql.conf 文件修改
listen_addresses = '0.0.0.0'
port = 5432
    原文作者:PostgreSQL
    原文地址: https://www.cnblogs.com/python-gm/p/10692327.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞