暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

PostgreSQL插件安装方法及pgvector插件安装教程

原创 张鹏 2023-06-28
2578

PostgreSQL插件安装方法及pgvector插件安装教程
安装 PostgreSQL 插件的通用方法
准备工作
PostgreSQL 源码的安装流程看这篇博文:
Linux环境PostgreSQL源码编译安装

在我们的虚拟机中已经安装了 PostgreSQL 的情况下,
应该有下面这两个目录:
pgsql : PostgreSQL 的应用程序
postgresql-14.4 : PostgreSQL 的源码

[root@localhost module]# ls
pgsql postgresql-14.4
安装插件
进入postgresql源码目录

[root@localhost module]# cd /opt/module/postgresql-14.4/
[root@localhost postgresql-14.4]# ls
aclocal.m4 config.status contrib GNUmakefile INSTALL src
config configure COPYRIGHT GNUmakefile.in Makefile
config.log configure.ac doc HISTORY README

进入其中的contrib目录,可以看到其中有很多插件
[root@localhost postgresql-14.4]# cd contrib/
[root@localhost contrib]# ls
adminpack dict_int jsonb_plpython pg_prewarm sslinfo
amcheck dict_xsyn lo pgrowlocks start-scripts
auth_delay earthdistance ltree pg_stat_statements tablefunc
auto_explain file_fdw ltree_plpython pgstattuple tcn
bloom fuzzystrmatch Makefile pg_surgery test_decoding
bool_plperl hstore oid2name pg_trgm tsm_system_rows
btree_gin hstore_plperl old_snapshot pg_visibility tsm_system_time
btree_gist hstore_plpython pageinspect postgres_fdw unaccent
citext intagg passwordcheck README uuid-ossp
contrib-global.mk intarray pg_buffercache seg vacuumlo
cube isn pgcrypto sepgsql xml2
dblink jsonb_plperl pg_freespacemap spi

pg的bin目录里有pg_config,通过pg_config可以看到相应的配置信息,pg安装插件时一般要在安装用户下安装,通过系统变量可以自动找到对应的安装配置信息

例如,我们要安装pg_prewarm插件:
① 进入pg_prewarm目录;
② make
③ make install

[root@localhost contrib]# cd pg_prewarm/
[root@localhost pg_prewarm]# make

[root@localhost pg_prewarm]# make install

2 使用插件
创建扩展:create extension 【extension name】;
create extension pg_prewarm;
删除扩展:drop extension 【extension name】;
drop extension pg_prewarm;
————————————————
版权声明:本文为CSDN博主「MarcyTheLibrarian」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/twi_twi/article/details/127087353

Linux环境PostgreSQL源码编译安装
一、pg数据库安装包下载
下载地址:http://www.postgresql.org/ftp/source/

下载tar.gz版

二、安装依赖包
由于是centOS7,所以使用yum来安装

yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake
三、安装postgres
进入/opt目录,新建两个包,其中software放压缩包,module放解压和安装后的软件

[root@localhost opt]# mkdir software
[root@localhost opt]# mkdir module
然后加入到software中,将下载下来的压缩包传上去

[root@localhost opt]# cd software

然后解压缩

[root@localhost software]# tar -zxvf postgresql-14.4.tar.gz

然后将解压缩得到的postgresql-14.4移动到module中
[root@localhost software]# mv postgresql-14.4 /opt/module/

进入postgresql-14.4

[root@localhost software]# cd /opt/module/postgresql-14.4
1
[root@localhost postgresql-14.4]# ls
aclocal.m4 config.status contrib GNUmakefile INSTALL src
config configure COPYRIGHT GNUmakefile.in Makefile
config.log configure.ac doc HISTORY README
编译postgresql源码,报错

[root@localhost postgresql-14.4]# ./configure --prefix=/opt/module/pgsql
-bash: ./configure: Permission denied
解决此报错的方法是改为输入下面语句:

[root@localhost postgresql-14.4]# bash ./configure --prefix=/opt/module/pgsql

再先后执行make和make install

[root@localhost postgresql-14.4]# make
[root@localhost postgresql-14.4]# make install
四、创建用户组postgres并创建用户postgres
[root@localhost postgresql-14.4]# groupadd postgres
[root@localhost postgresql-14.4]# useradd -g postgres postgres
[root@localhost postgresql-14.4]# id postgres
五、创建postgresql数据库的数据主目录并修改文件所有者
[root@localhost postgresql-14.4]# cd /opt/module/pgsql/
[root@localhost pgsql]# ls
bin include lib share
[root@localhost pgsql]# mkdir data
[root@localhost pgsql]# chown postgres:postgres data
[root@localhost pgsql]# ls
bin data include lib share
六、配置环境变量
[root@localhost pgsql]# cd /home/postgres/
[root@localhost postgres]# ls -al
total 28
drwx------. 5 postgres postgres 165 Aug 4 21:07 .
drwxr-xr-x. 4 root root 35 Aug 4 19:41 …
-rw-------. 1 postgres postgres 1014 Aug 4 22:20 .bash_history
-rw-r–r--. 1 postgres postgres 18 Apr 10 2018 .bash_logout
-rw-r–r--. 1 postgres postgres 300 Aug 4 19:42 .bash_profile
-rw-r–r--. 1 postgres postgres 231 Apr 10 2018 .bashrc
drwxrwxr-x. 3 postgres postgres 18 Aug 4 19:42 .cache
drwxrwxr-x. 3 postgres postgres 18 Aug 4 19:42 .config
drwxr-xr-x. 4 postgres postgres 39 Aug 4 19:19 .mozilla
-rw-------. 1 postgres postgres 42 Aug 4 21:03 .psql_history
-rw-------. 1 postgres postgres 5275 Aug 4 21:07 .viminfo
[root@localhost postgres]# vim .bash_profile
在.bash_profile中插入如下内容

export PGHOME=/opt/module/pgsql

export PGDATA=/opt/module/pgsql/data

PATH=PATH:PATH:HOME/bin:$PGHOME/bin
再执行下列语句使其生效

source .bash_profile

七、切换用户到postgres并使用initdb初使用化数据库
[root@localhost postgres]# su - postgres
Last login: Thu Aug 4 22:16:27 PDT 2022 on pts/0
[postgres@localhost ~]$ initdb
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 “en_US.UTF-8”.
The default database encoding has accordingly been set to “UTF8”.
The default text search configuration will be set to “english”.

Data page checksums are disabled.

fixing permissions on existing directory /opt/module/pgsql/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 … America/Los_Angeles
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
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 /opt/module/pgsql/data -l logfile start

可以看到/opt/module/pgsql/data中已经有数据了

[postgres@localhost data]$ ls
base pg_ident.conf pg_serial pg_tblspc postgresql.auto.conf
global pg_logical pg_snapshots pg_twophase postgresql.conf
pg_commit_ts pg_multixact pg_stat PG_VERSION test.txt
pg_dynshmem pg_notify pg_stat_tmp pg_wal
pg_hba.conf pg_replslot pg_subtrans pg_xact

八、配置服务
修改/opt/module/pgsql/data目录下的两个文件。
postgresql.conf 配置PostgreSQL数据库服务器的相应的参数。
pg_hba.conf 配置对数据库的访问权限。

[postgres@localhost data]$ vim postgresql.conf

将listen_addresses和port前的注释去掉,并修改listen_addresses的值为*

#------------------------------------------------------------------------------

CONNECTIONS AND AUTHENTICATION

#------------------------------------------------------------------------------

- Connection Settings -

listen_addresses = ‘’ # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to ‘localhost’; use '
’ for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directories = ‘/tmp’ # comma-separated list of directories
进入pg_hba.conf

[postgres@localhost data]$ vim pg_hba.conf
在IPv4中添加一条语句

IPv4 local connections:

host all all 0.0.0.0/0 trust
host all all 127.0.0.1/32 trust

九、设置PostgreSQL开机自启动
找到postgresql-14.4

[postgres@localhost postgresql-14.4]$ pwd
/opt/module/postgresql-14.4
[postgres@localhost postgresql-14.4]$ cd contrib/start-scripts/
[postgres@localhost start-scripts]$ ls
freebsd linux macos
切换为root用户

[root@localhost start-scripts]# chmod a+x linux
[root@localhost start-scripts]# cp linux /etc/init.d/postgresql
修改/etc/init.d/postgresql文件的两个变量

Installation prefix

prefix=/opt/module/pgsql

Data directory

PGDATA="/opt/module/pgsql/data"
设置postgresql服务开机自启动

[root@localhost init.d]# chkconfig --add postgresql
[root@localhost init.d]# chkconfig

postgresql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
然后将5432端口开启(或直接把防火墙给关了https://blog.csdn.net/twi_twi/article/details/126176793?spm=1001.2014.3001.5501)
执行service postgresql start,启动PostgreSQL服务

[root@localhost init.d]# service postgresql start
Starting PostgreSQL: ok
十、开始测试
默认的用户是postgres,密码和linux系统中所设的postgres用户的密码一样

[root@localhost init.d]# su - postgres
Last login: Thu Aug 4 23:08:40 PDT 2022 on pts/0
[postgres@localhost ~]$ psql
psql (14.4)
Type “help” for help.

postgres=#
————————————————
版权声明:本文为CSDN博主「MarcyTheLibrarian」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/twi_twi/article/details/126176036

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论