文章目录
PostgreSQL 向量扩展插件pgvector安装和使用
pgvector 是一个 PostgreSQL 扩展,能够让PostgreSQL 提供向量(vector)数据类型和相关操作功能。
参考:
https://github.com/pgvector/pgvector
安装postgresql
利用pgvector 前提是事先安装好postgresql,安装postgresql例可参考下文。
参考:
Linux(Ubuntu)源码安装postgresql16.3
https://editor.csdn.net/md/articleId=142500497
pgvector下载和安装
安装命令如下:
cd
git clone --branch v0.7.4 https://github.com/pgvector/pgvector.git
cd pgvector
make
make install # may need sudo
参考:
https://github.com/pgvector/pgvector
例:下载
root@autodl-container-616f40a3b3-41cb82d9:~# su - postgres
postgres@autodl-container-616f40a3b3-41cb82d9:~$ pwd
/var/lib/postgresql
postgres@autodl-container-616f40a3b3-41cb82d9:~$ ls
10 pgsql16 postgresql-16.3 postgresql-16.3.tar.gz
postgres@autodl-container-616f40a3b3-41cb82d9:~$ git clone --branch v0.7.4 https://github.com/pgvector/pgvector.git
Cloning into 'pgvector'...
remote: Enumerating objects: 10650, done.
remote: Counting objects: 100% (4165/4165), done.
remote: Compressing objects: 100% (954/954), done.
remote: Total 10650 (delta 3388), reused 3493 (delta 3193), pack-reused 6485 (from 1)
Receiving objects: 100% (10650/10650), 1.60 MiB | 544.00 KiB/s, done.
Resolving deltas: 100% (7952/7952), done.
Note: checking out '103ac50f1a90b47a72003e8e8628a55ec372f202'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
postgres@autodl-container-616f40a3b3-41cb82d9:~$
安装错误调试
错误调试1
尝试编译和安装
例:
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ make
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
cp sql/vector.sql sql/vector--0.7.4.sql
编译时候汇报如上错误可能是由于postgresql没有启动。
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ psql
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: Connection refused
Is the server running locally and accepting connections on that socket?
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$
postgres@autodl-container-616f40a3b3-41cb82d9:~$ ps -xf|grep postgres
1504 pts/3 S+ 0:00 _ grep postgres
postgres@autodl-container-616f40a3b3-41cb82d9:~$ pg_ctl -D /var/lib/postgresql/pgsql16/data status
pg_ctl: no server running
尝试解决 AP1 :启动postgresql
postgres@autodl-container-616f40a3b3-41cb82d9:~$ pg_ctl -D /var/lib/postgresql/pgsql16/data -l logfile start
pg_ctl: another server might be running; trying to start server anyway
waiting for server to start.... done
server started
postgres@autodl-container-616f40a3b3-41cb82d9:~$ ps -xf|grep postgres
1197 pts/0 S+ 0:00 _ grep postgres
1188 ? Ss 0:00 /var/lib/postgresql/pgsql16/bin/postgres -D /var/lib/postgresql/pgsql16/data
1189 ? Ss 0:00 _ postgres: checkpointer
1190 ? Ss 0:00 _ postgres: background writer
1192 ? Ss 0:00 _ postgres: walwriter
1193 ? Ss 0:00 _ postgres: autovacuum launcher
1194 ? Ss 0:00 _ postgres: logical replication launcher
postgres@autodl-container-616f40a3b3-41cb82d9:~$ psql
psql (16.3)
Type "help" for help.
postgres=# help
You are using psql, the command-line interface to PostgreSQL.
Type: copyright for distribution terms
h for help with SQL commands
? for help with psql commands
g or terminate with semicolon to execute query
q to quit
postgres=#
错误调试2
再次编译,出错。
postgres@autodl-container-616f40a3b3-41cb82d9:~$ pwd
/var/lib/postgresql
postgres@autodl-container-616f40a3b3-41cb82d9:~$ cd pgvector
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ make
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-si