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

以上 就安装完成

相关推荐
Decay__16 小时前
PostgreSQL 内存与锁调优 —— shared_buffers、work_mem、MVCC 与锁等待排查
运维·数据库·sql·postgresql
满小满m2 天前
一次审计问答后的恢复点复盘:全备在,WAL 断了
数据库·postgresql·dba·数据库运维
aifannihao3 天前
ON CONFLICT 冲突后返回空:sqlite3 实测 get-or-create
数据库·python·postgresql·sqlite3·标准库
Decay__4 天前
PostgreSQL 用户权限与安全 —— 角色体系、GRANT 授权、pg_hba.conf 认证、行级安全与审计
运维·数据库·sql·postgresql
zhangjw344 天前
2-4 集合运算 union /union all /intersect/except
数据库·postgresql
Decay__4 天前
PostgreSQL DBA 日常运维手册 —— 会话、锁阻塞、慢查询、膨胀与每日巡检
运维·数据库·sql·postgresql
Decay__5 天前
PostgreSQL 安装部署实战 —— PGDG yum 源安装、initdb 初始化与 postgresql.conf 参数调优
运维·数据库·sql·postgresql
她的男孩5 天前
状态默认填了 DRAFT,同步后却变成 '''DRAFT'':Forge Admin 清洗 PG 的 COLUMN_DEFAULT
spring boot·低代码·postgresql
Flynt5 天前
Postgres 19 实测:表膨胀清理,VACUUM FULL 锁到读写归零,REPACK 没停一秒
数据库·postgresql·性能优化
ZhengEnCi6 天前
覆盖索引是什么:用借书和外卖看懂回表这件事
sql·mysql·postgresql