CentOS7安装PostgresSQL和PGVector

一、PostgresSQL下载

官方网站:https://www.postgresql.org/

打开PostgreSQL官网,点击下载按钮:

可以根据系统选择对应的版本下载,因为我们是使用源码安装,所以这里选择下载源码:

我使用的是 17.7

二、编译安装PostgresSQL

1.创建用户

出于安全考虑,一般情况下PostgresSQL数据库不允许运行在root用户下,所以我们先来创建一个普通用户postgres:

bash 复制代码
#创建应用目录
mkdir app
#创建用户组
groupadd -g 1101 postgres
#创建用户并指定用户目录
useradd -u 1101 -g postgres -d /app/postgres -c "postgres." -m -s /bin/bash postgres

2.安装依赖包

bash 复制代码
useradd -u 1101 -g postgres -d /app/postgres -c "postgres." -m -s /bin/bash postgres

3.上传解压PostgresSQL

上传上面下载的安装包到 app目录

bash 复制代码
tar -zxvf postgresql-17.7.tar.gz

4.配置编译项目

bash 复制代码
cd postgresql-17.7
./configure --prefix=/app/postgres/pgsql

5.编译安装

bash 复制代码
make
sudo make install

6.设置用户目录权限

bash 复制代码
chown -R postgres:postgres /app/postgres
chmod -R 755 /app/postgres

7.设置环境变量

bash 复制代码
sed -i '$a PGHOME=/app/postgres/pgsql' /etc/profile
sed -i '$a export PATH=$PATH:$PGHOME/bin' /etc/profile
source /etc/profile

三、修改配置文件

1.切换到postgres用户

bash 复制代码
su - postgres

2.创建数据与日志目录

bash 复制代码
mkdir -p /app/postgres/pgsql/data
mkdir -p /app/postgres/pgsql/log

3.初始化数据目录

bash 复制代码
initdb /app/postgres/pgsql/data

4.修改postgresql.conf文件

bash 复制代码
vi /app/postgres/pgsql/data/postgresql.conf

找到以下行取消注释,并修改参数值:

bash 复制代码
listen_addresses = '*'     #允许远程连接
port = 5432                #默认端口
max_connections = 1000     #最大连接数
logging_collector = on     #启用日志
log_directory = '/app/postgres/pgsql/log'    #调整日志目录


5.修改pg_hba.conf文件

bash 复制代码
vi /app/postgres/pgsql/data/pg_hba.conf

添加以下行允许所有ip访问:

bash 复制代码
host    all             all             0.0.0.0/0            md5
host    all             all             ::/0                 md5

四、启动数据库

1.启动数据库

bash 复制代码
pg_ctl start -D /app/postgres/pgsql/data -l /app/postgres/pgsql/log/start.log

2.修改数据库密码

使用psql命令进入pg命令行环境,输入\password修改密码:

这里PostgresSQL数据库就安装完成了。

PGVector安装

下载源码文件: https://github.com/pgvector/pgvector/tags

我这安装的是 0.81版本

上传解压:

bash 复制代码
cd /tmp
cd pgvector
#没有对应目录就新建 也可自定义 
# 上传文件到 pgvector 解压
tar -zxvf
# make
make
make install # may need sudo

以上 就安装完成

相关推荐
2301_8002561118 小时前
R-Tree创建与遍历,R-Tree在4类空间查询中的应用,实现4类空间查询的各类算法[第8章]
数据库·算法·机器学习·postgresql·r-tree
梦想画家1 天前
实战优化:基于 pgvector 的向量存储与检索效率提升全攻略
postgresql·pgvector·语义检索
千百元1 天前
centos如何删除恶心定时任务
linux·运维·centos
AC赳赳老秦1 天前
Python 爬虫进阶:DeepSeek 优化反爬策略与动态数据解析逻辑
开发语言·hadoop·spring boot·爬虫·python·postgresql·deepseek
horizon72741 天前
Windows安装pgvector
postgresql·pgvector
l1t1 天前
DeepSeek辅助编写的利用唯一可选数求解数独SQL
数据库·sql·算法·postgresql
XMYX-01 天前
CentOS 7 搭建 PostgreSQL 14 实战指南
linux·postgresql·centos
丁丁丁梦涛1 天前
TencentOS Server 4.4(兼容centos 9 stream)部署KKFileView
linux·运维·centos·kkfileview
白驹过隙不负青春2 天前
Docker-compose部署java服务及前端服务
java·运维·前端·docker·容器·centos