PostgreSQL16源码包编译安装

2023-09-21 09:48:34

一、安装环境

操作系统:CentOS Linux release 7.8.2003 (Core)
PostgreSQL版本:16
服务器IP地址:192.168.0.244
Firewalld关闭、selinux关闭
笔者本次选用最新v16版本进行部署

二、pg数据库安装包下载

下载地址:https://www.postgresql.org/ftp/source/

有些小伙伴下载困难,可以直接去百度网盘下载链接
链接:https://pan.baidu.com/s/1CMXDD9nuqRXmaYJ3zyQuJQ?pwd=ovqx
提取码:ovqx
在这里插入图片描述

三、安装依赖包

执行以下命令安装所需依赖包:

yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake

四、安装postgreSQL

1)、在根目录下新建pgsql文件夹,并将pgsql的压缩包放入里边。
# 笔者在这里把文件夹创建到root下了,建议创建到根目录
mkdir /pgsql
[root@bogon pgsql]# ls
postgresql-16.0  postgresql-16.0.tar.gz
[root@bogon pgsql]# pwd
/root/pgsql
2)、解压压缩包
tar -zxvf postgresql-16.0.tar.gz
3)、进入加压后的文件夹
[root@bogon ~]# cd pgsql/postgresql-16.0
[root@bogon postgresql-16.0]# ls
aclocal.m4  config.log     configure     contrib    doc          GNUmakefile.in  INSTALL   meson.build        README
config      config.status  configure.ac  COPYRIGHT  GNUmakefile  HISTORY         Makefile  meson_options.txt  src
4、编译postgresql源码
./configure --prefix=/pgsql/postgresql --without-icu

注意:笔者在这里碰到编译报错,由于版本比较新也没有查到相关处理方法,索性就按照提示操作,禁用icu模块支持。–without-icu
在这里插入图片描述

选项描述
–prefix=prefix安装到prefix指定目录;默认为/usr/local/pgsql
–bindir=dir安装应用程序到dir;默认为prefix/bin
–with-docdir=dir安装文档到dir;默认为prefix/doc
–with-pgport=port设置默认服务端网络连接服务TCP端口号
–with-tcl服务端提供Tcl存储过程支持
–with-perl服务端提供perl存储过程支持
–with-python服务端提供Python存储过程支持
5、编译安装
root@bogon postgresql-16.0]# make && make install
编译安装结束没有报错证明安装成功;至此已完成postgresql的安装。进入/pgsql/postgresql目录可以看到安装后的postgresql文件。
[root@bogon postgresql-16.0]# cd /pgsql/postgresql/
[root@bogon postgresql]# ls
bin  include  lib  share

五、创建用户组postgre并创建用户postgre

[root@bogon postgresql]# groupadd postgres
[root@bogon postgresql]# useradd -g postgres postgres
[root@bogon postgresql]# id postgres
uid=1001(postgres) gid=1001(postgres) groups=1001(postgres)

六、创建postgresql数据库的数据主目录并修改文件所有者

数据库主目录可根据实际情况而创建,这里我们把主目录放在

/pgsql/postgresql/data/目录下:
[root@bogon postgresql]# mkdir data
[root@bogon postgresql]# chown postgres:postgres data
[root@bogon postgresql]# ls -al
total 16
drwxr-xr-x 7 root     root       68 Sep 19 16:23 .
drwxr-xr-x 3 root     root       24 Sep 19 16:20 ..
drwxr-xr-x 2 root     root     4096 Sep 19 16:20 bin
drwxr-xr-x 2 postgres postgres    6 Sep 19 16:23 data
drwxr-xr-x 6 root     root     4096 Sep 19 16:20 include
drwxr-xr-x 4 root     root     4096 Sep 19 16:20 lib
drwxr-xr-x 6 root     root     4096 Sep 19 16:20 share

七、配置环境变量

进入home/postgre目录可以看到.bash_profile文件。
编辑修改.bash_profile文件。
[root@bogon postgres]# vi .bash_profile 

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PGHOME=/pgsql/postgresql
export PGDATA=/pgsql/postgresql/data
PATH=$PATH:$HOME/bin:$PGHOME/bin
export PATH
~        


在.bash_profile文件中新增加内容如下:
export PGHOME=/pgsql/postgresql
export PGDATA=/pgsql/postgresql/data
PATH=$PATH:$HOME/bin:$PGHOME/bin

编辑修改.bash_profile文件然后保存。执行以下命令,使环境变量生效
[root@bogon postgres]# source .bash_profile

八、切换到postgre用户,并使用initdb初始化数据库

[root@bogon postgres]# su - postgres
[postgres@bogon ~]$ initdb
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /pgsql/postgresql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /pgsql/postgresql/data -l logfile start

可以看到/pgsql/postgresql/data

[root@bogon opt]# cd /pgsql/postgresql/
[root@bogon postgresql]# ls
bin  data  include  lib  share
[root@bogon postgresql]# cd data/
[root@bogon data]# ls
base    pg_commit_ts  pg_hba.conf    pg_logical    pg_notify    pg_serial     pg_stat      pg_subtrans  pg_twophase  pg_wal   postgresql.auto.conf
global  pg_dynshmem   pg_ident.conf  pg_multixact  pg_replslot  pg_snapshots  pg_stat_tmp  pg_tblspc    PG_VERSION   pg_xact  postgresql.conf

九、配置服务

修改/pgsql/postgresql/data/目录下的两个问价
Postgresql.conf 配置postgreSQL数据库服务的相应参数
pg_hba.conf  配置对数据库的访问权限
listen_addresses = '*'      # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
#port = 5432               # (change requires restart)
max_connections = 100                   # (change requires resta

其中,参数“listen_addresses”表示监听的IP地址,默认是在localhost处监听,也就是127.0.0.1的IP地址上监听,只接受来自本机的localhost的连接请求,这会让远程的主机无法登陆这台数据库,如果想从其他的机器上登陆这台数据库,需要把监听地址改为实际网络的地址,一种简单的方法是,将行开头的#号去掉,把这个地址改为*,表示在本地的所有地址上监听。

[root@bogon data]# vim pg_hba.conf
找到最下面这一行,这样局域网的人才能访问,红色为新添加内容。
# IPv4 local connections:
host    all      all             0.0.0.0/0               trust
host    all     all             127.0.0.1/32            trust
``
pg_hba.conf文件新增内容如下:
host    all      all             0.0.0.0/0               trust

十、设置postgresql开机自启动

PostgreSQL的开机自启动脚本位于postgreSQL源码目录的contrib/start-scripts路径下。
Linux文件即为Linux系统上的启动脚本

[root@bogon start-scripts]# pwd
/root/pgsql/postgresql-16.0/contrib/start-scripts
[root@bogon start-scripts]# ls
freebsd  linux  macos
1)	切换为root用户,修改Linux文件属性,添加X属性
[root@bogon start-scripts]# chmod a+x linux
2)	复制Linux文件到/etc/init.d目录下,更名为postgresql
[root@bogon start-scripts]# cp linux /etc/init.d/postgresql
3)	修改/etc/init.d/postgresql文件的两个变量
Prefix设置为postgresql的安装路径:/pgsql/postgresql
PGDATA设置为postgresql的数据目录路径:"/pgsql/postgresql/data"
4)	设置postgresql服务开启自启动
[root@bogon start-scripts]# chkconfig --add postgresql
查看开机自启服务设置成功
[root@bogon start-scripts]# chkconfig 
postgresql     	0:off	1:off	2:on	3:on	4:on	5:on	6:off
5)执行service postgresql start,启动postgreSQL服务
[root@bogon start-scripts]# service postgresql start
Starting PostgreSQL: ok
查看postgresql服务监听
[root@bogon start-scripts]# ps -elf |grep postgres
4 S root      17527   7286  0  80   0 - 47969 do_wai 16:26 pts/0    00:00:00 su - postgres
4 S postgres  17528  17527  0  80   0 - 28886 n_tty_ 16:26 pts/0    00:00:00 -bash
0 S postgres  17653      1  0  80   0 - 68572 ep_pol 16:35 ?        00:00:00 /pgsql/postgresql/bin/postgres -D /pgsql/postgresql/data
1 S postgres  17654  17653  0  80   0 - 68607 ep_pol 16:35 ?        00:00:00 postgres: checkpointer 
1 S postgres  17655  17653  0  80   0 - 68605 ep_pol 16:35 ?        00:00:00 postgres: background writer 
1 S postgres  17657  17653  0  80   0 - 68605 ep_pol 16:35 ?        00:00:00 postgres: walwriter 
1 S postgres  17658  17653  0  80   0 - 68974 ep_pol 16:35 ?        00:00:00 postgres: autovacuum launcher 
1 S postgres  17659  17653  0  80   0 - 68969 ep_pol 16:35 ?        00:00:00 postgres: logical replication launcher 
0 S root      17663  17574  0  80   0 - 28202 pipe_w 16:36 pts/1    00:00:00 grep --color=auto postgres

十一、开始测试

[root@bogon postgres]# su – postgres
[postgres@bogon ~]$ psql

1. 创建数据库用户
2. 赋予账号权限
3. 新建数据库
4. 退出

postgres=# create user pg password 'pg';
CREATE ROLE
postgres=# ALTER ROLE pg SUPERUSER;
ALTER ROLE
postgres=# create database pg;
CREATE DATABASE
postgres=# \q
  1. 重新登陆数据库
  2. 输入密码
  3. 显示数据库
[postgres@bogon ~]$ psql -U pg -d pg -h 192.168.0.244
pg=# \l
                         List of databases
 Name    |  Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   
-----------+----------+----------+-----------------+----- 

在这里插入图片描述
至此数据库安装成功。
参考大佬链接:
https://blog.csdn.net/weixin_43230682/article/details/108403642

更多推荐

【C语言趣味教程】(1) 深入浅出 HelloWorld:通过 HelloWorld 展开教学 | 头文件详解 | main 函数详解

🔗《C语言趣味教程》👈猛戳订阅!!!💭写在前面:这是一套C语言趣味教学专栏,目前正在火热连载中,欢迎猛戳订阅!本专栏保证篇篇精品,继续保持本人一贯的幽默式写作风格,当然,在有趣的同时也同样会保证文章的质量,旨在能够产出"有趣的干货"!本系列教程不管是零基础还是有基础的读者都可以阅读,可以先看看目录!标题前带星号(

第二证券:什么是a股b股?

在我国的股市中,我们经常会听到“A股”和“B股”这两个名词。那么,终究什么是A股和B股呢?首先,A股全称为“A股票”,是指在我国境内上市的以人民币计价的股票。A股首要面向国内出资者,只要具有必定条件的内地居民和安排出资者才可出资A股。此外,A股还分为两种:人民币A股和港币A股。前者是在我国境内发行的A股,后者则是在香港

Redis 面试题——缓存穿透、缓存击穿和缓存雪崩

目录1.缓存穿透2.缓存击穿3.缓存雪崩4.总结参考文章:缓存实战(1)缓存雪崩、缓存击穿和缓存穿透入门简介及解决方案1.缓存穿透(1)问题描述:缓存穿透是指在高并发场景下,大量的请求访问一个不存在于缓存中也不存在于数据库中的数据,导致每次请求都要查询数据库,增加了数据库的负载。通常发生在恶意攻击、频繁访问不存在的数据

OSCP系列靶场-Esay-Moneybox保姆级

OSCP系列靶场-Esay-Moneybox目录OSCP系列靶场-Esay-Moneybox总结准备工作信息收集-端口扫描目标开放端口收集目标端口对应服务探测信息收集-端口测试21-FTP端口的信息收集21-FTP版本版本信息21-FTP端口匿名登录测试(存在)21-FTP端口-文件GET收集21-FTP端口-PUT上

微服务 第一章 Java线程池技术应用

系列文章目录第一章Java线程池技术应用文章目录系列文章目录@[TOC](文章目录)前言1、Java创建线程方式回顾1.1、继承Thread类(只运行一次)1.1.1、改造成主线程常驻,每秒开启新线程运行1.1.2、匿名内部类1.1.3、缺点1.1.4、扩展知识:Java内部类1.1.4.1、静态内部类1.1.4.2、

机器学习实战:Python基于Ridge岭回归进行正则化(十三)

文章目录1.前言1.1岭回归的介绍1.2岭回归的应用2.自定义数据集实战演示2.1导入函数2.2创建数据集2.3alpha=0、1、10、100的分别情况3.Dushanbe_house数据集实战演示3.1导入函数和数据3.2剔除空值及可视化3.3整理数据3.4训练和测试数据集3.5评估数据集4.讨论1.前言1.1岭回

Python 04 之变量【列表,元组,集合,字典,字符串】

😀前言在Python编程语言中,我们经常会遇到各种数据类型和相应的操作方法。理解和掌握这些基本构造是进行有效编程的前提。在本文中,我们将介绍两种非常重要的数据结构-集合和字典,然后我们将深入探讨字符串及其相关的操作和处理方法,包括格式化和切片。我们还将通过示例来详细解释如何使用这些结构和方法,以便你可以在实际编程中轻

yolov5的使用

目录本地的标注数据集工具推荐如下:在线标注工具COCO训练模型用PyTorch训练一个简单的多层感知器(MLP)进行手写数字识别(MNIST数据集)。YOLOv5是一种流行的目标检测算法,可以用于识别和定位图像中的对象。要使用YOLOv5识别老鼠,您需要执行以下步骤:YOLOv5是一种流行的深度学习算法,用于目标检测和

金融业需要的大模型,是一个系统化工程

今年年初,在AIGC刚刚开始爆火的时候,我们曾经采访过一位AI领域的专家。当我们提问哪个行业将率先落地大模型时,他毫不犹豫地说道:“金融。”金融行业场景多、数据多、知识多,这样的“三多”特点让其成为AI大模型发挥价值的天选。与此同时,金融场景专业度高,业务复杂,在风控、安全、效率等方面有着严格的要求,初出茅庐的大模型,

GaussDB数据库SQL系列-数据去重

目录一、前言二、数据去重应用场景三、数据去重案例(GaussDB)1、示例场景描述2、定义重复数据3、制定去重规则4、创建测试数据(GaussDB)5、编写去重方法(GaussDB)6、附:全字段去重四、数据去重效率提升建议五、总结一、前言数据去重在数据库中是比较常见的操作。复杂的业务场景、多业务线的数据来源等等,都会

【深度学习】Pytorch 系列教程(十):PyTorch数据结构:2、张量操作(Tensor Operations):(4)索引和切片详解

目录一、前言二、实验环境三、PyTorch数据结构0、分类1、张量(Tensor)2、张量操作(TensorOperations)1.数学运算2.统计计算3.张量变形4.索引和切片使用索引访问单个元素使用切片访问子集使用索引和切片进行修改布尔索引(Booleanindexing)高级切片(Advancedslicing

热文推荐