https://blog.homurax.com/2019/10/14/install-postgresql-and-postgis-from-the-source-code/
0.需求背景
内网机器安装postgre 12 数据库
- 机器 : SUSE 12 SP5 ,
- postgresql版本为 12.7
规划:
- tar包上传存放与解压根目录 :
/opt - pg 安装路径 :
/usr/local/pgsql12.7 - pg data 路径 :
/data/pg12.7_datas
1. 获取安装TAR包 && 上次内网机器
https://www.postgresql.org/ftp/source/
下载后,将 .tar.gz文件与对应的 .tar.gz.md5文件上传至/opt,校验文件指纹,解压
md5sum -c postgresql-12.7.tar.gz.md5tar xzvf postgresql-12.7.tar.gz
2. 配置 && 编译安装
进入 解压后的文件夹,配置命令
./configure --prefix=/usr/local/pgsql12.7
这个命令执行时我遇到了报错如下:
configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure. It is possible the compiler isn’t looking in the proper directory.
Use --without-readline to disable readline support.
缺了readline 包,联网机器简单yum install -y readline-devel
之类的就行了,内网机器只能想其他办法,查询suse 的zypper里也没有,rpm包安装看网上的经验还挺麻烦,pg doc
http://postgres.cn/docs/12/install-procedure.html
提到readline是pgsql命令行增强用的 :
readline用于记录你之前的输入记录,方便你可以通过方向键来进行之前输入的快速填充。 考虑到之前pgsql命令行用的不多,这里用--without-readline作为workaround了
修改后的的命令:
./configure --prefix=/usr/local/pgsql12.7 --without-readline
之后编译安装,成功后会在–prefix参数指定的目录下输出 bin/lib等目录
make && make install
3. 安装后的设置
创建data与log目录用于pg数据和日志相关
mkdir -p /data/pg12.7_datas/{data,log}
添加环境变量 :
vi /etc/profile
export PGHOME=/usr/local/pgsql12.7
export PGDATA=/data/pg12.7_datas/data
export PATH=$PATH:$JAVA_HOME/bin:$PGHOME/bin
记得 source生效:
source /etc/profile
4. postgres 用户
新增postgre用户专用于pg数据库
groupadd postgres
useradd -g postgres postgres
passwd postgres
pg文件夹换属主,
chown -R postgres:postgres /usr/local/pgsql12.7/
pg data 赋权,不然初始化会报错权限问题
chown -R postgres:postgres /data/pg12.7_datas/
chmod -R 755 /data/pg12.7_datas/
5. 初始化数据库 与 pg配置修改
# 切换为自己前面创建的用户
su postgres
# 初始化数据库操作
/usr/local/pgsql12.7/bin/initdb --locale=en_US.utf8 -E utf8 -D /data/pg12.7_datas/data
之后cd至/data/pg12.7_datas/data,postgresql.conf配置文件,修改or打开下列配置
listen_addresses = '*'
max_connections = 1000
log_destination = 'stderr'
logging_collector = on
log_directory = 'log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_rotation_age = 1d
log_rotation_size = 10MB
log_min_duration_statement = 3000
进入pg_hba.conf配置文件
找到如下内容:
host all all 127.0.0.1/32 trust
将其修改为:
host all all 0.0.0.0/0 trust
6.启动
/usr/local/pgsql12.7/bin/pg_ctl start -D /data/pg12.7_datas/data
参考文档:
http://postgres.cn/docs/12/install-procedure.html
https://www.modb.pro/db/1688442550292668416
https://blog.homurax.com/2019/10/14/install-postgresql-and-postgis-from-the-source-code/
https://www.modb.pro/db/1782217039913504768
97

被折叠的 条评论
为什么被折叠?



