温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

PostgreSQL程序版本号有什么用

发布时间:2021-06-22 17:59:11 来源:亿速云 阅读:257 作者:Leah 栏目:大数据

这期内容当中小编将会给大家带来有关PostgreSQL程序版本号有什么用,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

很多人查看过程序的版本号:

quanzl-mac:bin quanzl$ ./postgres -Vpostgres (PostgreSQL) 11beta2
quanzl-mac:bin quanzl$ ./initdb -Vinitdb (PostgreSQL) 11beta2
quanzl-mac:bin quanzl$

似乎这些也就是给我们看看,没有其他用处,其实并非如此。

1、把initdb 放到其他版本bin目录下试试看(别忘记备份,尝试完之后别忘记恢复原状):

quanzl-mac:bin quanzl$ ./initdb -D ../data
The program "postgres" was found by "/Users/quanzl/build/flyingdb-v10bin/bin/initdb"
but was not the same version as initdb.
Check your installation.
quanzl-mac:bin quanzl$

很清楚的错误提示,initdb和postgres版本不一致。

2、如何根据错误提示定位代码位置

遇到错误信息时,如果对代码不够熟悉,怎么知道哪段代码在报错呢?就像上边的例子,可以在代码中搜索“but was not the same version”,或者 “The program \"postgres\" was found by”,可以很快定位。如果不明白后者为什么这么搜,需要补一下C语言基础,这种格式的字符串如果搜不到那么应该试试搜索 “The program \"%s\" was found by”。

搜后者可以看到还有其他几个程序在做同样的检查:pg_ctl、pg_dumpall、pg_rewind。


3、initdb

来看initdb的报错部分

if ((ret = find_other_exec(argv0, "postgres", PG_BACKEND_VERSIONSTR,
   backend_exec)) < 0)
{

当返回值小于0时进入错误处理。

find_other_exec 的几个参数:变量 argv0 的值是 "initdb"、常量 "postgres"、常量 PG_BACKEND_VERSIONSTR定义是:

#define PG_BACKEND_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"

而最后一个参数 backend_exec 将在 find_other_exec 函数内赋值。

4、函数 find_other_exec

intfind_other_exec(const char *argv0, const char *target,const char *versionstr, char *retpath)

在上边的例子里,它接收到的前三个字符串参数分别是:"initdb"、"postgres"、"postgres (PostgreSQL)  11beta2\n"

首先找initdb所在目录,确认 target 也就是 postgres 是否存在,权限够不够,一切正常就执行 postgres[.exe] -V

snprintf(cmd, sizeof(cmd), "\"%s\" -V", retpath);if (!pipe_read_line(cmd, line, sizeof(line)))return -1;

比较其输出是不是与 "postgres (PostgreSQL)  11beta2\n" 相同:

if (strcmp(line, versionstr) != 0)return -2;

上述就是小编为大家分享的PostgreSQL程序版本号有什么用了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI