前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用pgenv搭建单机PG测试环境

使用pgenv搭建单机PG测试环境

作者头像
保持热爱奔赴山海
发布2022-09-28 10:01:01
1820
发布2022-09-28 10:01:01
举报
文章被收录于专栏:饮水机管理员饮水机管理员

说明:

pgenv只能做到单机单实例PG。如果你要搞PG流复制等环境,需要多台机器上部署pgenv,然后各自启动一个PG实例。

它做不到单机启动多个PG实例(从这点看的话 不如自行编译的PG 可以改改路径和端口随便启动多个实例出来)

适用于临时起个测试实例。

仓库地址:​​https://github.com/theory/pgenv​

部署很简单:

代码语言:javascript
复制
su - postgres  (不支持用root启动)

git clone https://github.com/theory/pgenv.git ~/.pgenv


echo 'export PATH="$HOME/.pgenv/bin:$HOME/.pgenv/pgsql/bin:$PATH"' >> ~/.bash_profile

source  ~/.bash_profile

常用命令:

代码语言:javascript
复制
$ pgenv 
Usage: pgenv <command> [<args>]

The pgenv commands are:
    use        Set and start the current PostgreSQL version
    start      Start the current PostgreSQL server
    stop       Stop the current PostgreSQL server
    restart    Restart the current PostgreSQL server
    switch     Set the current PostgreSQL version
    clear      Stop and unset the current PostgreSQL version
    build      Build a specific version of PostgreSQL
    rebuild    Re-build a specific version of PostgreSQL
    remove     Remove a specific version of PostgreSQL
    version    Show the current PostgreSQL version
    current    Same as 'version'
    versions   List all PostgreSQL versions available to pgenv
    help       Show this usage statement and command summary
    available  Show which versions can be downloaded
    check      Check all program dependencies
    config     View, edit, delete the program configuration
    log        Inspects the log of the cluster, if exist.

For full documentation, see: https://github.com/theory/pgenv#readme

This is 'pgenv' version 1.3.1 


$ pgenv available  列出远程仓库可用的pg 源码包的版本

# 下载不同版本的pg,并进行编译安装
$ pgenv build 13.8
$ pgenv build 15beta4

# 编译完成后,会自动部署在下面的目录下
$ pwd
/home/postgres/.pgenv

$ pgenv current  显示当前所在的版本
15beta4

$ pgenv switch 15beta4  切换到摸个版本(该操作会先停止之前的版本的运行) 


$ pgenv use   列出当前可用的本地版本
Which version of PostgreSQL do you want?
      13.8      pgsql-13.8
  *   15beta4    pgsql-15beta4

$ pgenv use 15beta4  切到15beta4,并启动进程
Already using PostgreSQL 15beta4
PostgreSQL 15beta4 started
Logging to /home/postgres/.pgenv/pgsql/data/server.log

然后可以自行去修改pg的配置文件,例如改下shared_preload_libraries
shared_preload_libraries = 'pg_stat_statements'


$ pgenv restart           重启下pg进程         
PostgreSQL 15beta4 restarted
Logging to /home/postgres/.pgenv/pgsql/data/server.log


$ pgenv log -n 20  查看最近20行的pg日志
PostgreSQL in use: 15beta4
Dumping the content of /home/postgres/.pgenv/pgsql/data/server.log 



$  ps auxf  看到的进程如下
postgres  60056  0.0  0.0 335968 22564 ?        Ss   10:50   0:00 /home/postgres/.pgenv/pgsql-15beta4/bin/postgres -D /home/postgres/.pgenv/pgsql/data
postgres  60057  0.0  0.0 336100  3320 ?        Ss   10:50   0:00  \_ postgres: checkpointer 
postgres  60058  0.0  0.0 336132  3320 ?        Ss   10:50   0:00  \_ postgres: background writer 
postgres  60060  0.0  0.0 336132  8520 ?        Ss   10:50   0:00  \_ postgres: walwriter 
postgres  60061  0.0  0.0 337576  5796 ?        Ss   10:50   0:00  \_ postgres: autovacuum launcher 
postgres  60064  0.0  0.0 337596  5840 ?        Ss   10:50   0:00  \_ postgres: logical replication launcher 




pgenv还有些其它的命令,更复杂的操作,具体可以参考官方文档。
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022-09-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
腾讯云服务器利旧
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档