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

以上 就安装完成

相关推荐
xuefuhe16 小时前
RHEL9 yum install etcd Error: Unable to find a match: etcd
linux·运维·centos
顾西爵霞18 小时前
远程访问centos7并连接Mariadb
数据库·centos·mariadb
小二·21 小时前
Go 语言系统编程与云原生开发实战(第4篇):数据持久化深度实战 —— PostgreSQL、GORM 与 Repository 模式
postgresql·云原生·golang
码农不惑1 天前
systemd升级造成的centos-bootc系统的内核故障
linux·centos·bootc
__风__1 天前
PostgreSQL timestamp类型说明
数据库·postgresql
hunter14501 天前
docker 在centos和ubuntu的安装
linux·docker·centos
xuefuhe1 天前
Patroni 配置生成与验证命令
postgresql
数据知道1 天前
PostgreSQL 实战:如何优雅高效地进行全文检索
大数据·数据库·postgresql·全文检索
dingdingfish1 天前
PostgreSQL 16 Administration Cookbook 读书笔记:第9章 Regular Maintenance
postgresql·database·maintenance·cookbook
IvorySQL2 天前
PostgreSQL 18 RETURNING 增强:现代应用的重要进展
数据库·postgresql