這期內容當中小編將會給大家帶來有關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程序版本號有什么用了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。