views:

25

answers:

1

Hello.

I have a Web Application which is based on MapServer, which uses PostGIS as underlying database extension. Now I want to have a dedicated database role which is used for MapServer, cause I don't want to access the database via the postgres superuser. This role should only have SELECT permission on public tables (which is easy to achieve) and EXECUTE permissions on public PostGIS functions.

Several questions arise: Are ALL the PostGIS relevant functions stored in the public schema of a database or is there anything else to consider?

How can I extract all the functions information - i.e. function name, number and names of arguments - from the information_schema or the pg_catalog of the database?! I need this information for the GRANT EXECUTE on function(args) to MapServerUser statements!

Thank you in advance!!!

A: 

In PostgreSQL 8.4.x:

SELECT n.nspname as "Schema",
  p.proname as "Name",
  pg_catalog.pg_get_function_result(p.oid) as "Result data type",
  pg_catalog.pg_get_function_arguments(p.oid) as "Argument data types",
CASE
  WHEN p.proisagg THEN 'agg'
  WHEN p.proiswindow THEN 'window'
  WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN 'trigger'
  ELSE 'normal'
END as "Type"
FROM pg_catalog.pg_proc p
    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE pg_catalog.pg_function_is_visible(p.oid)
     AND n.nspname <> 'pg_catalog'
  AND n.nspname <> 'information_schema'
ORDER BY 1, 2, 4;

Found by running psql with the -E parameter (show hidden queries) and then running the \df command.

Also, the "public" schema in PostgreSQL is just named that way. It carries no special meaning. It's a bad name. What you DO need to look out for is the "PUBLIC" role (all caps). While tables are not automatically granted the PUBLIC role, my experience is that PUBLIC automatically gets execute permission on functions defined with SECURITY INVOKER.

Matthew Wood
I almost forgot: that query only shows the user-defined functions. If you need the internal functions, you'll need to remove the "AND n.nspname <> 'pg_catalog'" part of the WHERE clause.
Matthew Wood
Thank you, this seems close to what I want. As I'm using PostgreSQL 8.2.9, I don't have the functions pg_get_fuction_result(oid) and pg_get_function_arguments(oid), so maybe you know the equivalent 8.2. functions? I looked for them but couldn't find them. Also, the column proiswindow does not exist.
ilu-tg
Run this at the command line: "psql -E". Then issue the psql command "\df". It will print the query it uses to output the list of functions (with parameter and return types). That should work in all version of PostgreSQL.
Matthew Wood