研发有需要,要使用PGVector做向量。简单记录安装postgresql和PGVector过程。
postgresql官方下载连接
postgresql官方linux yum安装
PostgreSQL的安装、配置与使用指南
PostgreSQL向量数据插件–pgvector安装
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
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
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
su - postgres
cd /var/lib/pgsql/14/data/
vim postgresql.conf
listen_addresses = '*' # what IP address(es) to listen on;
max_connections = 5000 # (change requires restart)
# 这里取了服务器内存的25%
shared_buffers = 32000MB # min 128kB
work_mem = 32MB # min 64kB
maintenance_work_mem = 128MB # min 1MB
# 开启ssl,配置自签名证书和key,注意文件的权限是600,属主是postgres:postgres
ssl = on
ssl_cert_file = '/path/postgresql/data/postgresql-crt.pem'
ssl_key_file = '/path/postgresql/data/postgresql-key.pem'
vim pg_hba.conf
# IPv4 local connections:
hostssl all all 172.31.0.0/16 scram-sha-256
host all all 0.0.0.0/0 scram-sha-256
安装PGVector,需要采用编译安装postgresql方式
rpm -qa|grep postgresql
yum remove postgresql*
yum install -y perl-ExtUtils-Embed python-devel bison flex readline-devel zlib-devel gcc gcc-c++ wget libicu-devel
wget https://ftp.postgresql.org/pub/source/v16.3/postgresql-16.3.tar.gz
tar -zxvf postgresql-16.3.tar.gz && cd postgresql-16.3
./configure --prefix=/usr/local/pgsql --enable-debug
sudo make && sudo make install
cd contrib/
make && sudo make install
useradd postgres
mkdir -p /public/postgresql/data
chown postgres:postgres /public/postgresql -R
chown postgres:postgres /usr/local/pgsql -R
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
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 ... ok
initdb: 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
cd /public/postgresql/data
vim postgresql.conf
vim pg_hba.conf
pg_ctl -D /public/postgresql/data -l logfile start
psql (16.3)
Type "help" for help.
postgres=# ALTER USER postgres WITH PASSWORD 'yourpassword';
ALTER ROLE
postgres=# \q
[postgres@localhost data]$
psql -h 192.168.X.X -p 5432 -U postgres -W
yum install -y git
下载网址:https://github.com/pgvector/pgvector/tags
# gitcode镜像站
git clone --branch v0.7.4 https://gitcode.com/gh_mirrors/pg/pgvector.git
tar -zxvf pgvector-0.7.4.tar.gz && cd pgvector-0.7.4
sudo make PG_CONFIG=/usr/local/pgsql/bin/pg_config
sudo make PG_CONFIG=/usr/local/pgsql/bin/pg_config install
su - postgres
[postgres@localhost ~]$ psql
postgres=# CREATE EXTENSION vector;
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;
详见 问题记录:Navicat连接postgresql时出现‘datlastsysoid does not exist‘报错的问题