当前位置: 首页 > news >正文

安装postgresql和PGVector

1. 概述

研发有需要,要使用PGVector做向量。简单记录安装postgresql和PGVector过程。

2. 参考

postgresql官方下载连接
postgresql官方linux yum安装
PostgreSQL的安装、配置与使用指南
PostgreSQL向量数据插件–pgvector安装

3. 安装

3.1 只安装postgresql,不安装PGVector

  1. postgresql可以直接从官网下载仓库源,然后直接安装。
  2. 如果不想升级CentOS7,可以直接安装postgresql14。
    注意:这种方式无法安装PGVector。安装PGVector必须编译安装postgresql
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql16-server
sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
sudo systemctl enable postgresql-16
sudo systemctl start postgresql-16
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql14-server
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
sudo systemctl enable postgresql-14
sudo systemctl start postgresql-14
  1. postgresql安装完成后,查看端口(5432)
netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      69818/redis-server  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      11566/sshd          
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      66829/postmaster    
tcp6       0      0 192.168.8.63:9200       :::*                    LISTEN      79905/java          
tcp6       0      0 192.168.8.63:9300       :::*                    LISTEN      79905/java          
tcp6       0      0 :::22                   :::*                    LISTEN      11566/sshd          
tcp6       0      0 ::1:5432                :::*                    LISTEN      66829/postmaster    
tcp6       0      0 :::5666                 :::*                    LISTEN      58730/xinetd        
  1. 默认系统限制本地登录,密码为空
    注意!请登录后修改密码
sudo -u postgres psql
[root@localhost public]# sudo -u postgres psql
psql (14.12)
输入 "help" 来获取帮助信息.postgres=# ALTER USER postgres WITH PASSWORD 'yourpassword';
postgres-# exit
使用\q 退出.
postgres-# \q
  1. 切换到postgres账号下编辑配置文件,避免权限出错
su - postgres
cd /var/lib/pgsql/14/data/
  1. 编辑postgresql.conf,修改以下内容
vim postgresql.conf
listen_addresses = '*'          # what IP address(es) to listen on;max_connections = 5000                  # (change requires restart)# 这里取了服务器内存的25%
shared_buffers = 32000MB                        # min 128kBwork_mem = 32MB                         # min 64kBmaintenance_work_mem = 128MB            # min 1MB
  1. 编辑pg_hba.conf,修改以下内容
vim pg_hba.conf 
  • 增加允许网络连接。注意需要加在IPv4 local connections 下第一条
# IPv4 local connections:
host    all             all             0.0.0.0/0               scram-sha-256

3.2 安装postgresql和PGVector

安装PGVector,需要采用编译安装postgresql方式

3.2.1 安装postgresql 16

  1. 移除系统中的postgresql(系统中没有安装过,可以忽略)
rpm -qa|grep postgresql
yum remove postgresql*
  1. 准备安装环境
yum install -y perl-ExtUtils-Embed python-devel bison flex readline-devel zlib-devel gcc gcc-c++ wget libicu-devel
  1. 下载需要的安装源码
    下载网址:https://www.postgresql.org/ftp/source/v16.3/
  • 下载并解压
tar -zxvf postgresql-16.3.tar.gz  && cd postgresql-16.0
  • 指定安装目录编译安装
./configure --prefix=/usr/local/pgsql --enable-debug
sudo make && sudo make install
cd contrib/
make && sudo make install
  1. 创建postgresql数据目录
  • 创建账号
useradd postgres
  • 创建目录
mkdir -p /public/postgresql/data
  • 目录赋权
chown postgres:postgres /public/postgresql -R
chown postgres:postgres /usr/local/pgsql -R
  1. 添加环境变量
vim /etc/profile
export PGHOME=/usr/local/pgsql
export PGDATA=/public/postgresql/data
export PATH=$PGHOME/bin:$PATH
export MANPATH=$PGHOME/share/man:$MANPATH
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
  1. 初始化数据库
su postgres
source /etc/profile
initdb -D /public/postgresql/data
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 "zh_CN.UTF-8".
The default database encoding has accordingly been set to "UTF8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".Data page checksums are disabled.fixing permissions on existing directory /public/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
syncing data to disk ... okinitdb: 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 /public/postgresql/data -l logfile start
  1. 编辑配置文件(同上)
cd /public/postgresql/datavim postgresql.confvim pg_hba.conf 
  1. 启动数据库
pg_ctl -D /public/postgresql/data -l logfile start
  1. 修改密码
    postgres@localhost data]$ psql
psql (16.3)
Type "help" for help.postgres=# ALTER USER postgres WITH PASSWORD 'yourpassword';
ALTER ROLE
postgres=# \q
[postgres@localhost data]$ 

3.2.1 安装pgvector 0.7.4

  1. 安装git
yum install -y git
  1. 下载pgvector

下载网址:https://github.com/pgvector/pgvector/tags

  1. 解压源码
tar -zxvf pgvector-0.7.4.tar.gz && cd pgvector-0.7.4
  1. 在命令行export设置临时环境变量
sudo make PG_CONFIG=/usr/local/pgsql/bin/pg_config 
sudo make PG_CONFIG=/usr/local/pgsql/bin/pg_config install
  1. 登录数据库安装vector 插件
su - postgres
[postgres@localhost ~]$ psql
postgres=# CREATE EXTENSION vector;
  1. 测试向量
postgres=# CREATE TABLE sj_test (id bigserial PRIMARY KEY, embedding vector(3));
postgres=# INSERT INTO sj_test (embedding) VALUES ('[1,2,3]'), ('[4,5,6]');
postgres=# select * from sj_test;

4 Navicat连接

详见 问题记录:Navicat连接postgresql时出现‘datlastsysoid does not exist‘报错的问题

在这里插入图片描述

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • Linux线程基础学习记录(线程的创建、回收以及结束)
  • C#中的S7协议
  • 【计算机网络】应用层自定义协议与序列化
  • 批量查询全国快递单号:高效追踪物流信息
  • HarmonyOS应用开发学习-ArkUI-容器组件
  • springboot的学习(二):常用配置
  • 【算法 04】汉诺塔递归求解和通式求解
  • 【Linux基础】Linux中的开发工具(1)--yum和vim
  • 【学习笔记】Day 11
  • C++11中的左右值引用(略带复习)
  • PyTorch 基础学习(1) - 快速入门
  • 从零开始搭建 LVS 高性能集群 (DR模式)
  • JAVA中的对象流ObjectInputStream
  • uniapp实现自定义弹窗组件,支持富文本传入内容
  • Linux:Linux环境基础开发工具使用
  • [笔记] php常见简单功能及函数
  • 【React系列】如何构建React应用程序
  • 【许晓笛】 EOS 智能合约案例解析(3)
  • Docker入门(二) - Dockerfile
  • E-HPC支持多队列管理和自动伸缩
  • ES10 特性的完整指南
  • JavaScript 是如何工作的:WebRTC 和对等网络的机制!
  • java架构面试锦集:开源框架+并发+数据结构+大企必备面试题
  • Perseus-BERT——业内性能极致优化的BERT训练方案
  • Python - 闭包Closure
  • 从0实现一个tiny react(三)生命周期
  • 开源地图数据可视化库——mapnik
  • 那些被忽略的 JavaScript 数组方法细节
  • 那些年我们用过的显示性能指标
  • 排序算法学习笔记
  • 批量截取pdf文件
  • 使用 QuickBI 搭建酷炫可视化分析
  • 数据结构java版之冒泡排序及优化
  • ​【已解决】npm install​卡主不动的情况
  • #LLM入门|Prompt#1.8_聊天机器人_Chatbot
  • #NOIP 2014# day.1 T3 飞扬的小鸟 bird
  • #VERDI# 关于如何查看FSM状态机的方法
  • (27)4.8 习题课
  • (k8s)Kubernetes 从0到1容器编排之旅
  • (LNMP) How To Install Linux, nginx, MySQL, PHP
  • (ZT)一个美国文科博士的YardLife
  • (六)c52学习之旅-独立按键
  • (论文阅读11/100)Fast R-CNN
  • (转)创业家杂志:UCWEB天使第一步
  • (转)淘淘商城系列——使用Spring来管理Redis单机版和集群版
  • *Algs4-1.5.25随机网格的倍率测试-(未读懂题)
  • .net 7和core版 SignalR
  • .net Application的目录
  • .NET CF命令行调试器MDbg入门(二) 设备模拟器
  • .Net 中的反射(动态创建类型实例) - Part.4(转自http://www.tracefact.net/CLR-and-Framework/Reflection-Part4.aspx)...
  • .Net插件开发开源框架
  • .NET教程 - 字符串 编码 正则表达式(String Encoding Regular Express)
  • .NET设计模式(7):创建型模式专题总结(Creational Pattern)
  • .net实现客户区延伸至至非客户区
  • .NET文档生成工具ADB使用图文教程