Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What's the use of PostgreSQL program version number?

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about the use of the version number of the PostgreSQL program. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Many people have checked the version number of the program:

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

It seems that these are just for us to see, there is no other use, in fact, this is not the case.

1. Put initdb in another version of bin directory for a try (don't forget to back up, and don't forget to restore the original state after trying):

Quanzl-mac:bin quanzl$. / initdb-D.. / dataThe 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$

A clear error indicates that the versions of initdb and postgres are not consistent.

2. How to locate the code according to the error prompt

When you encounter an error message, if you are not familiar with the code, how do you know which code is reporting an error? Like the example above, you can search for "but was not the same version" in the code, or "The program\" postgres\ "was found by", which can be quickly located. If you don't understand why the latter is so searched, you need to fix the C language basics. If you can't find a string in this format, you should try searching for "The program\"% s\ "was found by".

Search the latter and you can see that there are several other programs doing the same check: pg_ctl, pg_dumpall, pg_rewind.

3 、 initdb

Let's take a look at the error report part of initdb.

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

Enter error handling when the return value is less than 0.

Several parameters of find_other_exec: the value of variable argv0 is "initdb", the constant "postgres", and the definition of constant PG_BACKEND_VERSIONSTR is:

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

The last parameter, backend_exec, will be assigned within the find_other_exec function.

4. Function find_other_exec

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

In the above example, the first three string parameters it receives are "initdb", "postgres", and "postgres (PostgreSQL) 11beta2\ n".

First of all, find the directory where initdb is located, and confirm whether target, that is, postgres exists, and if the permissions are sufficient, execute postgres [.exe]-V if everything is normal:

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

Compare whether the output is the same as "postgres (PostgreSQL) 11beta2\ n":

If (strcmp (line, versionstr)! = 0) return-2; this is what is the use of the PostgreSQL program version number shared by the editor. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 248

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report