Обсуждение: “Core” function in Postgres

Поиск
Список
Период
Сортировка

“Core” function in Postgres

От
Mingzhe Li
Дата:

Hi experts,

I want to know what's the "core" function used in Postgres server? I am looking for something corresponding to main() in a simple C program. I want to know the file path and the function name. I am using Postgres 9.3.5, however I assume the "core" function will be unchanged between different revisions.

Please let me know if you are confused by my question.

Thanks

Zack

PS: I have the same post on stackoverflow. Since no one answered there, I just report here. 

Re: [HACKERS] “Core” function in Postgres

От
Peter Geoghegan
Дата:
On Tue, Sep 23, 2014 at 4:29 PM, Mingzhe Li <mingzhe0908@gmail.com> wrote:
> I want to know what's the "core" function used in Postgres server? I am
> looking for something corresponding to main() in a simple C program. I want
> to know the file path and the function name. I am using Postgres 9.3.5,
> however I assume the "core" function will be unchanged between different
> revisions.
>
> Please let me know if you are confused by my question.

I think that the tcop is the closest thing to what you're looking for
(which includes postgres.c/PostgresMain()). There is a very simple
stub entry point ("main(int argc, char *argv[])") within main.c, too,
which is the real entry point.

Why not just set some breakpoints in a place that seems interesting
from within GDB, and inspect the call stack? That can be a useful
technique for gaining understanding of the structure of complicated
codebases that you're totally unfamiliar with.

--
Peter Geoghegan



Re: "Core" function in Postgres

От
Michael Paquier
Дата:
On Wed, Sep 24, 2014 at 8:29 AM, Mingzhe Li <mingzhe0908@gmail.com> wrote:
> Hi experts,
>
> I want to know what's the "core" function used in Postgres server? I am
> looking for something corresponding to main() in a simple C program. I want
> to know the file path and the function name. I am using Postgres 9.3.5,
> however I assume the "core" function will be unchanged between different
> revisions.
Er... Your question is rather unclear by using the term "core", making
it difficult to answer actually. Now, on this mailing list, you may
find Postgres "core" as defined as what is roughly produced by the
PostgreSQL central git repository in terms of binaries and libraries
for a huge set of platforms:
http://git.postgresql.org/gitweb/?p=postgresql.git. This "core" is
divided into many things:
- backend, the part postgres server itself is run
- contrib, a set of extra utilities not mandatory for the backend
- client utilities, like pg_dump, etc.
- common libraries shared between backend and client.

In your question, it seems that you are looking for the main() call
for the binary postgres, which is located in src/backend/main/main.c.
At the bottom of main() you'll see as well a set of functions like
PostmasterMain or PostgresMain that really define the startup path
used. PostmasterMain for example starts the postmaster, that is then
able to itself start backend process through PostgresMain()...

pgsql-hackers is as well a mailing list where people have technical
discussions about features and patches, hence your question would be
more adapted for pgsql-novice or pgsql-general.

Thanks,
-- 
Michael



Re: "Core" function in Postgres

От
Gregory Smith
Дата:
On 9/23/14, 8:02 PM, Michael Paquier wrote:
> pgsql-hackers is as well a mailing list where people have technical 
> discussions about features and patches, hence your question would be 
> more adapted for pgsql-novice or pgsql-general.

Let's be fair and get the details perfect if we're going to advise 
people on list policy, and that's not quite right if you compare against 
http://www.postgresql.org/list/

The official description says you consider trying elsewhere first, and " 
If your question cannot be answered by people in the other lists, and it 
is likely that only a developer will know the answer, you may re-post 
your question in this list".
From that, it's completely reasonable that Mingzhe guessed how main() 
is used in PostgreSQL is something only a developer would know the 
answer to, and therefore should go here instead of pgsql-general.

My feedback would be to point out that that pgsql-general is also a list 
where " many of the developers monitor" traffic, and that's the right 
place to post first for this sort of question.  The mailing list page 
does not make that completely obvious though, so this is an 
understandable thing to be unsure about.  This is definitely not a 
pgsql-novice question.

The mailing list page could probably use an explicit clarification that 
pgsql-general *is* an appropriate venue for simpler questions "that only 
a developer will know the answer".

-- 
Greg Smith greg.smith@crunchydatasolutions.com
Chief PostgreSQL Evangelist - http://crunchydatasolutions.com/



Re: “Core” function in Postgres

От
Mark Kirkwood
Дата:
On 24/09/14 11:29, Mingzhe Li wrote:
> Hi experts,
>
> I want to know what's the "core" function used in Postgres server? I am
> looking for something corresponding to main() in a simple C program. I
> want to know the file path and the function name. I am using Postgres
> 9.3.5, however I assume the "core" function will be unchanged between
> different revisions.
>

I suspect you want to start looking at
PostgresMain in src/backend/tcop/postgres.c

and ServerLoop in src/backend/postmaster/postmaster.c

Regards

Mark

P.s: FWIW I think this *is* the right list to ask this type of question...



Re: "Core" function in Postgres

От
Merlin Moncure
Дата:
On Tue, Sep 23, 2014 at 7:02 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:
> On Wed, Sep 24, 2014 at 8:29 AM, Mingzhe Li <mingzhe0908@gmail.com> wrote:
>> Hi experts,
>>
>> I want to know what's the "core" function used in Postgres server? I am
>> looking for something corresponding to main() in a simple C program. I want
>> to know the file path and the function name. I am using Postgres 9.3.5,
>> however I assume the "core" function will be unchanged between different
>> revisions.
>
> In your question, it seems that you are looking for the main() call
> for the binary postgres, which is located in src/backend/main/main.c.
> At the bottom of main() you'll see as well a set of functions like
> PostmasterMain or PostgresMain that really define the startup path
> used. PostmasterMain for example starts the postmaster, that is then
> able to itself start backend process through PostgresMain()...

As noted main is in main.c.  Most of the interesting stuff that
happens in the main execution loop for the backend is in
tcop/postgres.c (tcop being shorthand for 'traffic cop' -- probably
not a great name but it hails from the very early days of the
project).  That kinda answers your other question: these function
names rarely change except as needed to meet new requirements.

merlin



Re: “Core” function in Postgres

От
Craig Ringer
Дата:
On 09/24/2014 07:29 AM, Mingzhe Li wrote:

> PS: I have the same post on stackoverflow. Since no one answered there,
> I just report here.

Thanks for mentioning it. In future, please include a link.

You might want to wait more than a couple of hours too ;-)

For reference, the Stack Overflow post is

    http://stackoverflow.com/q/26005359/398670 .

where I answered in some detail.

--
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services