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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程