getpid() function

Started by Bruce Momjianover 23 years ago46 messageshackersgeneral
Jump to latest
#1Bruce Momjian
bruce@momjian.us
hackersgeneral

I have implemented this TODO item:

* Add getpid() function to backend

There were a large number of pg_stat functions that access pids and
backends slots so I added it there:

test=> select pg_stat_get_backend_mypid();
pg_stat_get_backend_mypid
---------------------------
2757
(1 row)

Applied.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Attachments:

/bjm/difftext/plainDownload+10-0
#2Neil Conway
neilc@samurai.com
In reply to: Bruce Momjian (#1)
hackersgeneral
Re: getpid() function

On Tue, Jul 30, 2002 at 08:40:13PM -0400, Bruce Momjian wrote:

I have implemented this TODO item:

* Add getpid() function to backend

There were a large number of pg_stat functions that access pids and
backends slots so I added it there:

test=> select pg_stat_get_backend_mypid();

If we're going to add it to pg_stat_*, why is 'backend' part of the
name? All the existing backend_* function fetch some piece of data
about a given backend -- whereas this function does not (it takes
no arguments).

IMHO, a better name would be something like 'backend_process_id()',
or 'unix_pid', or 'backend_pid()'.

Also, can you add some documentation on this?

Cheers,

Neil

--
Neil Conway <neilconway@rogers.com>
PGP Key ID: DB3C29FC

#3Bruce Momjian
bruce@momjian.us
In reply to: Neil Conway (#2)
hackersgeneral
Re: getpid() function

OK, renamed to backend_pid() to match the libpq name. I was unsure
about merging it into the stats stuff myself.

setest=> select backend_pid();
backend_pid
-------------
12996
(1 row)

Where does the mention belong in the docs? I have it in the monitoring
section in the stats section right now.

---------------------------------------------------------------------------

Neil Conway wrote:

On Tue, Jul 30, 2002 at 08:40:13PM -0400, Bruce Momjian wrote:

I have implemented this TODO item:

* Add getpid() function to backend

There were a large number of pg_stat functions that access pids and
backends slots so I added it there:

test=> select pg_stat_get_backend_mypid();

If we're going to add it to pg_stat_*, why is 'backend' part of the
name? All the existing backend_* function fetch some piece of data
about a given backend -- whereas this function does not (it takes
no arguments).

IMHO, a better name would be something like 'backend_process_id()',
or 'unix_pid', or 'backend_pid()'.

Also, can you add some documentation on this?

Cheers,

Neil

--
Neil Conway <neilconway@rogers.com>
PGP Key ID: DB3C29FC

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Attachments:

/bjm/difftext/plainDownload+18-10
#4Neil Conway
neilc@samurai.com
In reply to: Bruce Momjian (#3)
hackersgeneral
Re: getpid() function

On Tue, Jul 30, 2002 at 09:48:42PM -0400, Bruce Momjian wrote:

OK, renamed to backend_pid() to match the libpq name.

Ok, thanks.

Where does the mention belong in the docs? I have it in the monitoring
section in the stats section right now.

I'd vote for User's Guide -> Functions & Operators -> Misc. Functions. I
don't think it belongs in the monitoring section, since it isn't part of
the stats collector and isn't really used for monitoring.

Cheers,

Neil

--
Neil Conway <neilconway@rogers.com>
PGP Key ID: DB3C29FC

#5Bruce Momjian
bruce@momjian.us
In reply to: Neil Conway (#4)
hackersgeneral
Re: getpid() function

Neil Conway wrote:

On Tue, Jul 30, 2002 at 09:48:42PM -0400, Bruce Momjian wrote:

OK, renamed to backend_pid() to match the libpq name.

Ok, thanks.

Where does the mention belong in the docs? I have it in the monitoring
section in the stats section right now.

I'd vote for User's Guide -> Functions & Operators -> Misc. Functions. I
don't think it belongs in the monitoring section, since it isn't part of
the stats collector and isn't really used for monitoring.

OK, docs moved to new section. I kept the function in pgstatfuncs.c.
Not sure where else to put it.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Neil Conway (#4)
hackersgeneral
Re: getpid() function

nconway@klamath.dyndns.org (Neil Conway) writes:

On Tue, Jul 30, 2002 at 09:48:42PM -0400, Bruce Momjian wrote:

Where does the mention belong in the docs? I have it in the monitoring
section in the stats section right now.

I'd vote for User's Guide -> Functions & Operators -> Misc. Functions.

There is a table in that section for "session information functions",
which seems the correct choice.

regards, tom lane

#7Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#6)
hackersgeneral
Re: getpid() function

Tom Lane wrote:

nconway@klamath.dyndns.org (Neil Conway) writes:

On Tue, Jul 30, 2002 at 09:48:42PM -0400, Bruce Momjian wrote:

Where does the mention belong in the docs? I have it in the monitoring
section in the stats section right now.

I'd vote for User's Guide -> Functions & Operators -> Misc. Functions.

There is a table in that section for "session information functions",
which seems the correct choice.

That's where I put it.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#8Karel Zak
zakkr@zf.jcu.cz
In reply to: Bruce Momjian (#3)
hackersgeneral
Re: getpid() function

On Tue, Jul 30, 2002 at 09:48:42PM -0400, Bruce Momjian wrote:

OK, renamed to backend_pid() to match the libpq name. I was unsure
about merging it into the stats stuff myself.

setest=> select backend_pid();
backend_pid
-------------
12996
(1 row)

Is there some common convention of names? Why not pg_backend_pid()?

Karel

--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/

C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz

#9Neil Conway
neilc@samurai.com
In reply to: Karel Zak (#8)
hackersgeneral
Re: getpid() function

On Thu, Aug 01, 2002 at 12:01:52PM +0200, Karel Zak wrote:

Is there some common convention of names?

No, there isn't (for example, pg_stat_backend_id() versus
current_schema() -- or pg_get_viewdef() versus obj_description() ).
Now that we have table functions, we might be using more built-in
functions to provide information to the user -- so there will be
an increasing need for some kind of naming convention for built-in
functions. However, establishing a naming convention without
breaking backwards compatibility might be tricky.

Cheers,

Neil

--
Neil Conway <neilconway@rogers.com>
PGP Key ID: DB3C29FC

#10Rod Taylor
rbt@rbt.ca
In reply to: Neil Conway (#9)
hackersgeneral
Re: getpid() function

On Thu, 2002-08-01 at 10:44, Neil Conway wrote:

On Thu, Aug 01, 2002 at 12:01:52PM +0200, Karel Zak wrote:

Is there some common convention of names?

functions. However, establishing a naming convention without
breaking backwards compatibility might be tricky.

Supporting both names for a release with comments in the release notes
stating the old names will disappear soon should be enough.

Most of the time it'll be a simple replacement command. Providing a
find -exec sed statement may help.

#11Karel Zak
zakkr@zf.jcu.cz
In reply to: Neil Conway (#9)
hackersgeneral
Re: getpid() function

On Thu, Aug 01, 2002 at 10:44:23AM -0400, Neil Conway wrote:

On Thu, Aug 01, 2002 at 12:01:52PM +0200, Karel Zak wrote:

Is there some common convention of names?

No, there isn't (for example, pg_stat_backend_id() versus

I know -- for this I asked. IMHO for large project like PostgreSQL
it's important. It's not good if there is possible speculate about
name of new function. It must be unmistakable -- for this is needful
make some convension. If somebody add new function and it's released,
it's in the PostgreSQL almost forever.

current_schema() -- or pg_get_viewdef() versus obj_description() ).
Now that we have table functions, we might be using more built-in
functions to provide information to the user -- so there will be
an increasing need for some kind of naming convention for built-in
functions. However, establishing a naming convention without
breaking backwards compatibility might be tricky.

Yes, but we can try be clean for new stuff.

Karel

--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/

C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz

#12Bruce Momjian
bruce@momjian.us
In reply to: Karel Zak (#11)
hackersgeneral
Re: getpid() function

Added to TODO:

* Consistently name server-side internal functions

---------------------------------------------------------------------------

Karel Zak wrote:

On Thu, Aug 01, 2002 at 10:44:23AM -0400, Neil Conway wrote:

On Thu, Aug 01, 2002 at 12:01:52PM +0200, Karel Zak wrote:

Is there some common convention of names?

No, there isn't (for example, pg_stat_backend_id() versus

I know -- for this I asked. IMHO for large project like PostgreSQL
it's important. It's not good if there is possible speculate about
name of new function. It must be unmistakable -- for this is needful
make some convension. If somebody add new function and it's released,
it's in the PostgreSQL almost forever.

current_schema() -- or pg_get_viewdef() versus obj_description() ).
Now that we have table functions, we might be using more built-in
functions to provide information to the user -- so there will be
an increasing need for some kind of naming convention for built-in
functions. However, establishing a naming convention without
breaking backwards compatibility might be tricky.

Yes, but we can try be clean for new stuff.

Karel

--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/

C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#13Bruce Momjian
bruce@momjian.us
In reply to: Karel Zak (#11)
hackersgeneral
Re: getpid() function

I can rename backend_pid if people want. I just made it consistent
with the other functions in that docs area. Comments?

---------------------------------------------------------------------------

Karel Zak wrote:

On Thu, Aug 01, 2002 at 10:44:23AM -0400, Neil Conway wrote:

On Thu, Aug 01, 2002 at 12:01:52PM +0200, Karel Zak wrote:

Is there some common convention of names?

No, there isn't (for example, pg_stat_backend_id() versus

I know -- for this I asked. IMHO for large project like PostgreSQL
it's important. It's not good if there is possible speculate about
name of new function. It must be unmistakable -- for this is needful
make some convension. If somebody add new function and it's released,
it's in the PostgreSQL almost forever.

current_schema() -- or pg_get_viewdef() versus obj_description() ).
Now that we have table functions, we might be using more built-in
functions to provide information to the user -- so there will be
an increasing need for some kind of naming convention for built-in
functions. However, establishing a naming convention without
breaking backwards compatibility might be tricky.

Yes, but we can try be clean for new stuff.

Karel

--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/

C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#14Hannu Krosing
hannu@tm.ee
In reply to: Bruce Momjian (#12)
hackersgeneral
Re: getpid() function

On Thu, 2002-08-01 at 19:41, Bruce Momjian wrote:

Added to TODO:

* Consistently name server-side internal functions

I'd suggest:

* Make up rules for consistently naming server-side internal functions

* Consistently name _new_ server-side internal functions

* make a plan for moving existing server-side internal functions
to consistent naming

---------------
Hannu

#15Neil Conway
neilc@samurai.com
In reply to: Karel Zak (#11)
hackersgeneral
Re: getpid() function

On Thu, Aug 01, 2002 at 05:09:52PM +0200, Karel Zak wrote:

I know -- for this I asked. IMHO for large project like PostgreSQL
it's important. It's not good if there is possible speculate about
name of new function. It must be unmistakable -- for this is needful
make some convension. If somebody add new function and it's released,
it's in the PostgreSQL almost forever.

I agree that a naming convention would be useful in some circumstances,
but for commonly-used functions, I think it would do more harm than
good. 'pg_nextval()' is awfully ugly, for example.

And if we're going to have a naming convention for builtin functions,
what about builtin types? 'pg_int4', anyone? :-)

Cheers,

Neil

--
Neil Conway <neilconway@rogers.com>
PGP Key ID: DB3C29FC

#16Peter Eisentraut
peter_e@gmx.net
In reply to: Neil Conway (#9)
hackersgeneral
Re: getpid() function

Neil Conway writes:

On Thu, Aug 01, 2002 at 12:01:52PM +0200, Karel Zak wrote:

Is there some common convention of names?

No, there isn't (for example, pg_stat_backend_id() versus
current_schema() -- or pg_get_viewdef() versus obj_description() ).

The "pg_" naming scheme is obsolete because system and user namespaces are
now isolated. Anything involving "get" is also redundant, IMHO, because
we aren't dealing with object-oriented things. Besides that, the
convention in SQL seems to be to use full noun phrases with words
separated by underscores.

So if "pg_get_viewdef" where reinvented today, by me, it would be called
"view_definition".

A whole 'nother issue is to use the right terms for the right things. For
example, the term "backend" is rather ambiguous and PostgreSQL uses it
differently from everyone else. Instead I would use "server process" when
referring to the PID.

--
Peter Eisentraut peter_e@gmx.net

#17Bruce Momjian
bruce@momjian.us
In reply to: Peter Eisentraut (#16)
hackersgeneral
Re: getpid() function

Peter Eisentraut wrote:

Neil Conway writes:

On Thu, Aug 01, 2002 at 12:01:52PM +0200, Karel Zak wrote:

Is there some common convention of names?

No, there isn't (for example, pg_stat_backend_id() versus
current_schema() -- or pg_get_viewdef() versus obj_description() ).

The "pg_" naming scheme is obsolete because system and user namespaces are
now isolated. Anything involving "get" is also redundant, IMHO, because
we aren't dealing with object-oriented things. Besides that, the
convention in SQL seems to be to use full noun phrases with words
separated by underscores.

So if "pg_get_viewdef" where reinvented today, by me, it would be called
"view_definition".

A whole 'nother issue is to use the right terms for the right things. For
example, the term "backend" is rather ambiguous and PostgreSQL uses it
differently from everyone else. Instead I would use "server process" when
referring to the PID.

Yes, I wanted to match libpq's function, which is the way people used to
get the pid.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#18Christopher Kings-Lynne
chriskl@familyhealth.com.au
In reply to: Neil Conway (#9)
hackersgeneral
Re: getpid() function

No, there isn't (for example, pg_stat_backend_id() versus
current_schema() -- or pg_get_viewdef() versus obj_description() ).
Now that we have table functions, we might be using more built-in
functions to provide information to the user -- so there will be
an increasing need for some kind of naming convention for built-in
functions. However, establishing a naming convention without
breaking backwards compatibility might be tricky.

I personally think that as many functions as possible should be prefixed
pg_*... People are still used to avoiding pg_ as a prefix.

Chris

#19Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#13)
hackersgeneral
Re: getpid() function

Bruce Momjian <pgman@candle.pha.pa.us> writes:

I can rename backend_pid if people want. I just made it consistent
with the other functions in that docs area. Comments?

I'd go for pg_backend_pid, I think. It's not an SQL standard function
and certainly never will be, so some sort of prefix seems appropriate.

Perhaps a more relevant question is why are we cluttering the namespace
with any such function at all? What's the use case for it? We've
gotten along fine without one so far, and I don't really think that we
*ought* to be exposing random bits of internal implementation details
at the SQL level.

regards, tom lane

#20Thomas Lockhart
lockhart@fourpalms.org
In reply to: Bruce Momjian (#13)
hackersgeneral
Re: getpid() function

...

Perhaps a more relevant question is why are we cluttering the namespace
with any such function at all? What's the use case for it? We've
gotten along fine without one so far, and I don't really think that we
*ought* to be exposing random bits of internal implementation details
at the SQL level.

Actually, I was wondering the same thing, maybe for a different reason.
Exposing the backend internals could have security implications (though
don't make me concoct a scenario to prove it ;)

Although it might have some usefulness for debugging, I think it should
not be an "installed by default" feature, so istm would be a great
candidate for a contrib/ function or library. If someone needs it, it is
almost immediately available.

- Thomas

#21Karel Zak
zakkr@zf.jcu.cz
In reply to: Bruce Momjian (#12)
hackersgeneral
#22Tatsuo Ishii
t-ishii@sra.co.jp
In reply to: Karel Zak (#21)
hackersgeneral
#23Christopher Kings-Lynne
chriskl@familyhealth.com.au
In reply to: Tatsuo Ishii (#22)
hackersgeneral
#24Yaroslav Dmitriev
yar@warlock.ru
In reply to: Karel Zak (#11)
hackersgeneral
#25Christopher Kings-Lynne
chriskl@familyhealth.com.au
In reply to: Yaroslav Dmitriev (#24)
hackersgeneral
#26Karel Zak
zakkr@zf.jcu.cz
In reply to: Tatsuo Ishii (#22)
hackersgeneral
#27Yaroslav Dmitriev
yar@warlock.ru
In reply to: Christopher Kings-Lynne (#25)
hackersgeneral
#28Sergio A. Kessler
sak@ksb.com.ar
In reply to: Yaroslav Dmitriev (#24)
hackersgeneral
#29Andrew Sullivan
andrew@libertyrms.info
In reply to: Yaroslav Dmitriev (#27)
hackersgeneral
#30David Blood
david@matraex.com
In reply to: Andrew Sullivan (#29)
hackersgeneral
#31Rod Taylor
rbt@rbt.ca
In reply to: Andrew Sullivan (#29)
hackersgeneral
#32Andrew Sullivan
andrew@libertyrms.info
In reply to: David Blood (#30)
hackersgeneral
#33Noname
ngpg@grymmjack.com
In reply to: Yaroslav Dmitriev (#24)
hackersgeneral
#34Bruce Momjian
bruce@momjian.us
In reply to: Thomas Lockhart (#20)
hackersgeneral
#35Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#34)
hackersgeneral
#36Christopher Kings-Lynne
chriskl@familyhealth.com.au
In reply to: Christopher Kings-Lynne (#25)
hackersgeneral
#37Hannu Krosing
hannu@tm.ee
In reply to: Tom Lane (#35)
hackersgeneral
#38Tom Lane
tgl@sss.pgh.pa.us
In reply to: Hannu Krosing (#37)
hackersgeneral
#39Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#35)
hackersgeneral
#40Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#39)
hackersgeneral
#41Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#40)
hackersgeneral
#42Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#41)
hackersgeneral
#43Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#42)
hackersgeneral
#44Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#43)
hackersgeneral
#45Peter A. Daly
petedaly@ix.netcom.com
In reply to: Christopher Kings-Lynne (#25)
hackersgeneral
#46Andrew Sullivan
andrew@libertyrms.info
In reply to: Rod Taylor (#31)
hackersgeneral