1.9 KiB
1.9 KiB
从源码安装 PostgreSQL
编译安装
解压缩后配置安装路径:
./configure --prefix=/usr/local/pg14
视安装路径是否需要高权限,执行 install:
make
sudo make install
用户设置
自己从源码安装,需要创建 postgres 用户:
sudo useradd -r -s /usr/sbin/nologin postgres
参数说明:
- -r 表示创建系统用户
- -s 指定登陆 shell,使用 nologin 表示禁止用户登陆交互式 shell
使用 createuser
创建 postgres
超级用户。
$ createuser -s postgres -p 5532
删除用户:
$ dropuser postgres -p 5532
更新 /etc/passwd 文件,为 postgres 用户设置家目录 /data/pg。
启动实例
初始化数据库:
sudo -u postgres initdb /data/pg/master
启动服务:
sudo -u postgres pg_ctl -D master -l master.log start
从 16 版本起,pg 编译需要 icu 支持,也可以忽略 icu:
./configure --prefix=xxxx --without-icu
TODO: Debian 12 已经安装了 libicu
但是不起作用。
pg17
在 Debian 12 中编译 pg17 需要安装 bison 和 flex:
sudo apt install bison flex
安装插件
pg 源码的 contrib 目录中,有很多官方提供的插件,进入插件目录,用 make 进行编译安装。
$ make install
进入 pg 后,用 create extension
命令激活插件。
create extension pg_walinspect;
查看加载的插件列表:
select * from pg_extension;
oid extname extowner extnamespace extrelocatable extversion extconfig extcondition
----- ------------- -------- ------------ -------------- ---------- --------- ------------
14417 plpgsql 10 11 False 1.0 <null> <null>
16389 pg_walinspect 10 2200 True 1.1 <null> <null>
SELECT 2