Attention PL authors: want to be listed in template table?

Started by Tom Laneover 20 years ago58 messageshackers
Jump to latest
#1Tom Lane
tgl@sss.pgh.pa.us

I've committed changes to implement the cut-down form of this proposal:
http://archives.postgresql.org/pgsql-hackers/2005-08/msg01185.php
discussed here:
http://archives.postgresql.org/pgsql-hackers/2005-09/msg00138.php

Barring further changes, we'll have a hard-wired template list for 8.1
and a real system catalog in 8.2. So there's a choice now for PLs that
are not part of the core distribution: do you want to be listed in the
hard-wired template?

The advantages of being listed are:

1. Reloading old dumps that involve your language should be easier,
since problems like version-specific paths to shared libraries will
go away.

2. Your PL support functions will end up in pg_catalog instead of
the public schema, which will please people who'd like to remove public
from their installations.

The main disadvantage I can see is that you won't easily be able to
change your PL creation parameters (eg, add a validator function)
over the lifespan of the 8.1 release. So depending on your development
roadmap you might think this a bad tradeoff.

If you want to be listed, let me know. What I need to know to list you
is values for this table:

typedef struct
{
char *lanname; /* PL name */
bool lantrusted; /* trusted? */
char *lanhandler; /* name of handler function */
char *lanvalidator; /* name of validator function, or NULL */
char *lanlibrary; /* path of shared library */
} PLTemplate;

As examples, the entries for the core PLs are

{ "plpgsql", true, "plpgsql_call_handler", "plpgsql_validator",
"$libdir/plpgsql" },
{ "pltcl", true, "pltcl_call_handler", NULL,
"$libdir/pltcl" },
{ "pltclu", false, "pltclu_call_handler", NULL,
"$libdir/pltcl" },
{ "plperl", true, "plperl_call_handler", "plperl_validator",
"$libdir/plperl" },
{ "plperlu", false, "plperl_call_handler", "plperl_validator",
"$libdir/plperl" },
{ "plpythonu", false, "plpython_call_handler", NULL,
"$libdir/plpython" },

regards, tom lane

#2Joe Conway
mail@joeconway.com
In reply to: Tom Lane (#1)
Re: Attention PL authors: want to be listed in template

Tom Lane wrote:

If you want to be listed, let me know. What I need to know to list you
is values for this table:

typedef struct
{
char *lanname; /* PL name */
bool lantrusted; /* trusted? */
char *lanhandler; /* name of handler function */
char *lanvalidator; /* name of validator function, or NULL */
char *lanlibrary; /* path of shared library */
} PLTemplate;

Hi Tom,

Please include PL/R:

{ "plr", false, "plr_call_handler", NULL, "$libdir/plr" },

Thanks,

Joe

p.s. my (supposedly) static IP changed this summer -- I think my direct
mail might be getting blocked by your spam filters again.

#3Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#1)
Re: Attention PL authors: want to be listed in template table?

Tom Lane wrote:

Barring further changes, we'll have a hard-wired template list for
8.1 and a real system catalog in 8.2. So there's a choice now for
PLs that are not part of the core distribution: do you want to be
listed in the hard-wired template?

Is there any way to create the language and not use the template (an
override option of some kind)?

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#3)
Re: Attention PL authors: want to be listed in template table?

Peter Eisentraut <peter_e@gmx.net> writes:

Is there any way to create the language and not use the template (an
override option of some kind)?

There is deliberately not a way to override (other than using a
different name for the PL). One of the points of this facility is to
fix up broken PL definitions being imported from old dump files, so
believing what the CREATE LANGUAGE command says is exactly what we
don't want.

This will definitely be more palatable with a system catalog that you
could alter, of course. Still, I don't see that there's any big
problem. For instance, if you think you might want a validator later,
you can set up a no-op validator procedure today, and then the template
doesn't need to change when you make the validator do something.
Similarly, you could future-proof yourself against adding a trusted (or
untrusted) variant by putting in some stubs now.

regards, tom lane

#5Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#4)
Re: Attention PL authors: want to be listed in template

Tom Lane wrote:

For instance, if you think you might want a validator later,
you can set up a no-op validator procedure today, and then the template
doesn't need to change when you make the validator do something.
Similarly, you could future-proof yourself against adding a trusted (or
untrusted) variant by putting in some stubs now.

Only necessary for one release, right?

Anyway, clearly there are cases where a validator make no sense or very
little sense (pl/sh and pl/{j,java} spring to mind).

cheers

andrew

#6Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#4)
Re: Attention PL authors: want to be listed in template table?

Tom Lane wrote:

There is deliberately not a way to override (other than using a
different name for the PL). One of the points of this facility is to
fix up broken PL definitions being imported from old dump files, so
believing what the CREATE LANGUAGE command says is exactly what we
don't want.

I don't doubt that, but I just have a stomach ache with this entire
notion of having a hard-coded exception list of the sort "if the user
requires this, do this instead". Why don't we just put all PLs that we
know of into pg_language to begin with, revoke the permissions, and
just let CREATE LANGUAGE fail when the dump is restored? (The dump
should restore the permissions, shouldn't it?) At least that would let
you alter the "template" using existing means.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#7Peter Eisentraut
peter_e@gmx.net
In reply to: Andrew Dunstan (#5)
Re: Attention PL authors: want to be listed in template table?

Andrew Dunstan wrote:

Anyway, clearly there are cases where a validator make no sense or
very little sense (pl/sh and pl/{j,java} spring to mind).

PL/sh has a validator. :-)

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#8Andrew Dunstan
andrew@dunslane.net
In reply to: Peter Eisentraut (#7)
Re: Attention PL authors: want to be listed in template

Peter Eisentraut wrote:

Andrew Dunstan wrote:

Anyway, clearly there are cases where a validator make no sense or
very little sense (pl/sh and pl/{j,java} spring to mind).

PL/sh has a validator. :-)

Really? Curious. I must look more closely.

cheers

andrew

#9Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#6)
Re: Attention PL authors: want to be listed in template table?

Peter Eisentraut <peter_e@gmx.net> writes:

I don't doubt that, but I just have a stomach ache with this entire
notion of having a hard-coded exception list of the sort "if the user
requires this, do this instead".

I don't see it as an exception list. The direction I see for this is
that the parameters to CREATE LANGUAGE are obsolete and will eventually
be removed altogether, with "CREATE LANGUAGE foo" using an existing
template as the only recommended way to do it.

Why don't we just put all PLs that we
know of into pg_language to begin with, revoke the permissions, and
just let CREATE LANGUAGE fail when the dump is restored?

To do that we'd have to force an initdb, in which case we might as well
add the proposed pltemplate catalog and have done with it.

I'm entirely willing to add the catalog if people are willing to accept
an initdb now. As I said earlier, I don't want to mess with adding a
usage privilege just yet, but we could add the catalog with a
nonfunctional ACL column and write that code later.

regards, tom lane

#10Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#9)
Re: Attention PL authors: want to be listed in template table?

Tom Lane wrote:

I don't see it as an exception list. The direction I see for this is
that the parameters to CREATE LANGUAGE are obsolete and will
eventually be removed altogether, with "CREATE LANGUAGE foo" using an
existing template as the only recommended way to do it.

So your proposal is to enable a new language by doing:

1. register a template
2. activate template using CREATE LANGUAGE (which would copy it to
pg_language)

How is this different from

1. register language in pg_language without privileges
2. activate language by granting privileges

This already works and uses only well-known concepts.

Why don't we just put all PLs that we
know of into pg_language to begin with, revoke the permissions, and
just let CREATE LANGUAGE fail when the dump is restored?

To do that we'd have to force an initdb, in which case we might as
well add the proposed pltemplate catalog and have done with it.

I don't have a strong opinion on initdb, but a difference would be that
this solution would not *require* an initdb but only offer the
improvement if initdb were done while continuing to work as before
without initdb.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#11Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#10)
Re: Attention PL authors: want to be listed in template table?

Peter Eisentraut <peter_e@gmx.net> writes:

So your proposal is to enable a new language by doing:

1. register a template
2. activate template using CREATE LANGUAGE (which would copy it to
pg_language)

That's the long-term idea, yes.

How is this different from

1. register language in pg_language without privileges
2. activate language by granting privileges

Because you can't create a language without first creating the support
procedures, which ordinarily requires having the shared library present.
(This is why I proposed text names for the support procedures in
pltemplate, rather than OID references.) This is perhaps not an issue
for entries wired in by initdb, but it's definitely an issue for manual
addition of template entries.

Also, ISTM your proposal is to cause "CREATE LANGUAGE foo" on an
already-existing language to execute "GRANT USAGE ON LANGUAGE foo TO PUBLIC"
instead, rather than erroring out. That doesn't seem to pass the
least-surprise test at all.

regards, tom lane

#12uwcssa
uwcssa@gmail.com
In reply to: Tom Lane (#1)
purge hash table, how to?

i am using postgresql 8.0.3 as a single user by running "postgres"

I want to purge all contents in the bufferpool, and I did this by
calling "InitBufTable(256)" (buf_table.c) after each query. However,
this seems not working for each followup query I still get less disk read
(tracked by "smgrread()" in smgr.c) and increased bufferhitcount.

Could anyone tell me which module shall i modify instead?

#13Tom Lane
tgl@sss.pgh.pa.us
In reply to: uwcssa (#12)
Re: purge hash table, how to?

huaxin zhang <uwcssa@gmail.com> writes:

I want to purge all contents in the bufferpool,

Why do you think that's a good idea? It certainly won't purge the
kernel's disk caches, so if you're hoping to restore the system to
ground zero this won't do it.

and I did this by
calling "InitBufTable(256)" (buf_table.c) after each query.

Let's see ... I'd expect that to run out of shared memory pretty soon,
but not till after it's thoroughly corrupted your database ;-)

There is no API exported by bufmgr.c that does what you want. Something
like a combination of FlushRelationBuffers and DropRelFileNodeBuffers,
but processing a whole database (see also DropBuffers) or the whole buffer
cache, might work. You can't drop a buffer that some other process has
pinned, however.

regards, tom lane

#14Thomas Hallgren
thhal@mailblocks.com
In reply to: Tom Lane (#1)
Re: Attention PL authors: want to be listed in template table?

Tom,
I assume that the path of the shared library will be somehow relative to
the GUC dynamic_library_path? If not, the lanlibrary should be changed
to "$libdir/libpljava". That requires that PL/Java is installed within
the PostgreSQL distribution.

I also assume that the handler name can be prefixed with a schema name?
All PL/Java support functions reside in the sqlj schema.

If my assumptions are correct, then please add:

{ "java", true, "sqlj.java_call_handler", NULL,
"libpljava" },
{ "javaU", false, "sqlj.javau_call_handler", NULL,
"libpljava" },

The validator for PL/Java will have to wait until 8.2.

Regards,
Thomas Hallgren

Tom Lane wrote:

Show quoted text

I've committed changes to implement the cut-down form of this proposal:
http://archives.postgresql.org/pgsql-hackers/2005-08/msg01185.php
discussed here:
http://archives.postgresql.org/pgsql-hackers/2005-09/msg00138.php

Barring further changes, we'll have a hard-wired template list for 8.1
and a real system catalog in 8.2. So there's a choice now for PLs that
are not part of the core distribution: do you want to be listed in the
hard-wired template?

The advantages of being listed are:

1. Reloading old dumps that involve your language should be easier,
since problems like version-specific paths to shared libraries will
go away.

2. Your PL support functions will end up in pg_catalog instead of
the public schema, which will please people who'd like to remove public
from their installations.

The main disadvantage I can see is that you won't easily be able to
change your PL creation parameters (eg, add a validator function)
over the lifespan of the 8.1 release. So depending on your development
roadmap you might think this a bad tradeoff.

If you want to be listed, let me know. What I need to know to list you
is values for this table:

typedef struct
{
char *lanname; /* PL name */
bool lantrusted; /* trusted? */
char *lanhandler; /* name of handler function */
char *lanvalidator; /* name of validator function, or NULL */
char *lanlibrary; /* path of shared library */
} PLTemplate;

As examples, the entries for the core PLs are

{ "plpgsql", true, "plpgsql_call_handler", "plpgsql_validator",
"$libdir/plpgsql" },
{ "pltcl", true, "pltcl_call_handler", NULL,
"$libdir/pltcl" },
{ "pltclu", false, "pltclu_call_handler", NULL,
"$libdir/pltcl" },
{ "plperl", true, "plperl_call_handler", "plperl_validator",
"$libdir/plperl" },
{ "plperlu", false, "plperl_call_handler", "plperl_validator",
"$libdir/plperl" },
{ "plpythonu", false, "plpython_call_handler", NULL,
"$libdir/plpython" },

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

#15Tom Lane
tgl@sss.pgh.pa.us
In reply to: Thomas Hallgren (#14)
Re: Attention PL authors: want to be listed in template table?

Thomas Hallgren <thhal@mailblocks.com> writes:

I assume that the path of the shared library will be somehow relative to
the GUC dynamic_library_path?

Well, whatever you put in the template is what will be in the probin
field of the support functions. I suppose it does not *have* to use
$libdir, but I would definitely recommend using $libdir rather than
depending on dynamic_library_path.

I also assume that the handler name can be prefixed with a schema name?
All PL/Java support functions reside in the sqlj schema.

Not if you use the template facility, they won't. The handler and
validator are hard-wired to live in pg_catalog under this scheme.

The validator for PL/Java will have to wait until 8.2.

Do you want to drop in a stub? It's only a one-line function.

regards, tom lane

#16Thomas Hallgren
thhal@mailblocks.com
In reply to: Tom Lane (#15)
Re: Attention PL authors: want to be listed in template table?

Tom Lane wrote:

Thomas Hallgren <thhal@mailblocks.com> writes:

I assume that the path of the shared library will be somehow relative to
the GUC dynamic_library_path?

Well, whatever you put in the template is what will be in the probin
field of the support functions. I suppose it does not *have* to use
$libdir, but I would definitely recommend using $libdir rather than
depending on dynamic_library_path.

I'm not I understand this. The default setting for the
dynamic_library_path is $libdir, isn't it? So why have another hardwired
setting here? Wouldn't it be better if all PL's used the
dynamic_library_path setting at all times?

I also assume that the handler name can be prefixed with a schema name?
All PL/Java support functions reside in the sqlj schema.

Not if you use the template facility, they won't. The handler and
validator are hard-wired to live in pg_catalog under this scheme.

Ok. That's fine. They're not covered by the SQL standard anyway. I have
a lot of other "support functions" for managing jar files, classpath,
etc. in the database. They all live in the sqlj schema but they will not
be affected by this.

The validator for PL/Java will have to wait until 8.2.

Do you want to drop in a stub? It's only a one-line function.

Yes, that's a good idea. I'll call them "java_validator" and
"javau_validator" respectively.

Regards,
Thomas Hallgren

#17Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#1)
Re: Attention PL authors: want to be listed in template table?

Thomas Hallgren <thhal@mailblocks.com> writes:

Wouldn't it be better if all PL's used the
dynamic_library_path setting at all times?

I wouldn't think so at all. That's just another way to shoot yourself
in the foot; $libdir is the correct place by definition, and any other
directory is not the correct place, by definition. This is certainly
true for the PLs that are part of the distribution, but I don't see that
it would be any less true for add-on PLs.

As an example of how to shoot yourself in the foot, consider someone
setting dynamic_library_path to point to a version-specific directory:
/home/postgres/version74/lib
and then updating to a newer release without changing that.

If there were some upside to letting people load alternate versions of
PLs by changing dynamic_library_path then you might have a point ...
but I really don't see any value there, just risk of breakage.

Do you want to drop in a stub? It's only a one-line function.

Yes, that's a good idea. I'll call them "java_validator" and
"javau_validator" respectively.

OK, I'll add that to the template info.

regards, tom lane

#18Peter Eisentraut
peter_e@gmx.net
In reply to: Thomas Hallgren (#14)
Re: Attention PL authors: want to be listed in template table?

Thomas Hallgren wrote:

If my assumptions are correct, then please add:

{ "java", true, "sqlj.java_call_handler", NULL,
"libpljava" },
{ "javaU", false, "sqlj.javau_call_handler", NULL,
"libpljava" },

In the interest of uniformity, please rename your libraries to omit the
"lib" prefix.

The other problem I see emerging here is that in certain environments,
the "java" language may not be trusted, such as when it is compiled
with GCJ. Then, this built-in template will override the CREATE
LANGUAGE specification and introduce a security hole.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#19Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#11)
Re: Attention PL authors: want to be listed in template table?

Tom Lane wrote:

How is this different from

1. register language in pg_language without privileges
2. activate language by granting privileges

Because you can't create a language without first creating the support
procedures, which ordinarily requires having the shared library
present.

We are only talking about well-known procedural languages. The issue of
completely new languages added by the user is addressed by neither
proposal.

Also, ISTM your proposal is to cause "CREATE LANGUAGE foo" on an
already-existing language to execute "GRANT USAGE ON LANGUAGE foo TO
PUBLIC" instead, rather than erroring out. That doesn't seem to pass
the least-surprise test at all.

Clearly, there's going to be some surprise element. The surprise
element proposed by you is that the command does something completely
different than specified (which possibly introduces security holes, see
other mail). My proposal is that the command does only a subset of
what it would normally do, which amounts to some sort of implicit "OR
REPLACE", which people are familiar with.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#20Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#1)
Re: Attention PL authors: want to be listed in template table?

Tom Lane wrote:

Barring further changes, we'll have a hard-wired template list for
8.1 and a real system catalog in 8.2. So there's a choice now for
PLs that are not part of the core distribution: do you want to be
listed in the hard-wired template?

Another note: PLs that are not in the core distribution are not created
with createlang in the first place, so the issues that led up to this
proposal don't apply AFAICT, that is:

- "pg_dump dumps them at a pretty low semantic level" --> pg_dump dumps
them at exactly the level they were created at.

- "problem with adding a validator" --> An update of PostgreSQL does not
change the properties of external modules

- "issues with hardwired paths to the shared libraries" --> This is an
issue with all loadable modules and needs a more general solution.
Basically, on a major version upgrade, we need to make the user
recompile all shared libraries.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#21Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#19)
#22Peter Eisentraut
peter_e@gmx.net
In reply to: Peter Eisentraut (#20)
#23Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#22)
#24Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#18)
#25Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#23)
#26Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#24)
#27Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#25)
#28Thomas Hallgren
thhal@mailblocks.com
In reply to: Tom Lane (#24)
#29Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#26)
#30Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#1)
#31Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#27)
#32Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#31)
#33Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#1)
#34Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#29)
#35Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#30)
#36Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#34)
#37Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#35)
#38Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#27)
#39Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#38)
#40Thomas Hallgren
thhal@mailblocks.com
In reply to: Peter Eisentraut (#33)
#41Dave Cramer
pg@fastcrypt.com
In reply to: Thomas Hallgren (#40)
#42Thomas Hallgren
thhal@mailblocks.com
In reply to: Dave Cramer (#41)
#43Dave Cramer
pg@fastcrypt.com
In reply to: Thomas Hallgren (#40)
#44Dave Cramer
pg@fastcrypt.com
In reply to: Thomas Hallgren (#42)
#45Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#1)
#46Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#45)
#47Thomas Hallgren
thhal@mailblocks.com
In reply to: Peter Eisentraut (#45)
#48Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#1)
#49Thomas Hallgren
thhal@mailblocks.com
In reply to: Tom Lane (#46)
#50Thomas Hallgren
thhal@mailblocks.com
In reply to: Peter Eisentraut (#48)
#51Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#39)
#52Dave Cramer
pg@fastcrypt.com
In reply to: Thomas Hallgren (#49)
#53Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#1)
#54Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#1)
#55Dennis Bjorklund
db@zigo.dhs.org
In reply to: Tom Lane (#51)
#56Rupa Schomaker (lists)
pgsql-hackers@lists.rupa.com
In reply to: Tom Lane (#54)
#57Tom Lane
tgl@sss.pgh.pa.us
In reply to: Rupa Schomaker (lists) (#56)
#58Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dennis Bjorklund (#55)