Assistance Needed: Error during PostgreSQL Configuration

2023-12-11 Thread Ayush Vatsa
Hello, PostgreSQL community,
I'm reaching out to you about an issue I've had while trying to configure
PostgreSQL by cloning its files from the GitHub repository.
During the configuration process, I encountered an error message that
appeared to be related to a syntax issue within the 'config.status' file.
Specifically, the error message reads as follows:
./config.status: line 486: syntax error near unexpected token `)'
./config.status: line 486: ` *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed
"s/'/'''/g"` ;;'
I have tried to resolve this on my own, but unfortunately, I haven't been
successful in finding a solution.
Could you please provide guidance or assistance in resolving this issue? I
would appreciate any insights or suggestions you have to help me move past
this obstacle.
Looking forward to your response.

Thanks
Ayush Vatsa
SDE Amazon


Re: Assistance Needed: Error during PostgreSQL Configuration

2023-12-12 Thread Ayush Vatsa
Hi,
Sorry, I should have included the required information initially itself. I
am new to the database field so please pardon my mistakes :)
What I have done till now is clone the source code files from Gihub in my
Mac laptop and then try to follow this documentation
<https://www.postgresql.org/docs/current/install-make.html>, then I got an
error posted in the mail in the very first step itself i.e. ./configure
command.

The PostgreSQL version is the latest (i.e. 16) as I have cloned the source
code from GitHub.
I have tried using both shells including zsh and bash here but same response
For sed, I am using GNU sed and also included this GNU sed in the PATH
variable

ayuvatsa@bcd0745f2da7 ~ % sed --version

sed (GNU sed) 4.9


The configure script runs fine till the step given below:

configure: using CPPFLAGS=-isysroot $(PG_SYSROOT)

configure: using LDFLAGS=-isysroot $(PG_SYSROOT)   -Wl,-dead_strip_dylibs

configure: creating ./config.status

Thanks
Ayush Vatsa

On Mon, 11 Dec 2023 at 20:20, Tom Lane  wrote:

> Ian Lawrence Barwick  writes:
> > 2023年12月11日(月) 18:09 Ayush Vatsa :
> >> ./config.status: line 486: syntax error near unexpected token `)'
> >> ./config.status: line 486: ` *\'*) ac_optarg=`$as_echo "$ac_optarg" |
> sed "s/'/'''/g"` ;;'
>
> > You should provide, at the very least, the following information:
> > - the PostgreSQL version you are trying to build
> > - the environment you are trying to build it in
>
> +1
>
> > A very hand-wavy guess, but possibly your local "sed" installation is
> > not GNU sed?
>
> I'm also wondering if the shell in use is nonstandard.  The configure
> script would likely already have failed if you tried to run it with,
> say, csh; but maybe more-subtly-incompatible shells could give rise
> to this symptom.
>
> regards, tom lane
>


Re: Assistance Needed: Error during PostgreSQL Configuration

2023-12-12 Thread Ayush Vatsa
Hi all,
@Ron Johnson, I am building from the source because I wanted to contribute
to the open-source community, and for that, I want the source files. I had
a few things in mind currently for the same :).
@Tom Lane , Thanks I am using a directory path with
spaces in it, and removing them solved my issue. Next time I will use '_'
in paths to be on the safer side.

Thanks and regards
Ayush Vatsa
SDE Amazon

On Tue, 12 Dec 2023 at 22:10, Tom Lane  wrote:

> Ayush Vatsa  writes:
> > Sorry, I should have included the required information initially itself.
> I
> > am new to the database field so please pardon my mistakes :)
>
> You still didn't mention the platform/environment, but I guess from
> the reference to -isysroot that it must be macOS (Darwin).  I further
> guess that you're using Homebrew or MacPorts, because bare macOS
> doesn't supply GNU sed.  That doesn't get us much further though;
> plenty of Postgres developers use one or the other of those setups
> without difficulty.
>
> One idea that comes to mind is that you might be trying to build in
> a directory path that contains spaces or other odd characters.
> That's generally not well supported by Unix-based tooling.
> However, I'm not sure how that'd lead to this particular failure.
>
> The only other idea I have is that maybe you have some weird
> Homebrew or MacPorts package installed that changes the behavior
> of your shell.  I have no idea what that would be though.
>
> FWIW, on my own Mac laptop, line 486 in config.status in a
> current build looks like
>
> *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'''/g"` ;;
>
> which seems identical to what you reported.  So that takes some
> steam out of the idea that the file was generated incorrectly
> in your build, pointing more to the idea that your shell is not
> reading it as-expected.
>
> regards, tom lane
>


Query regarding function cleanup in extension upgrade path

2024-02-14 Thread Ayush Vatsa
Hi PostgreSQL Community,
I have been working on a few extensions but got confused in the upgrade
scenario.
To ask the question let me give a hypothetical example:-
Suppose we have an extension named xyz with version 1.0. It has
xyz--1.0.sql and xyz.c file. I have declared a function named fun() in the
xyz--1.0.sql file and its definition in the xyz.c file.
Now I want to drop this function in the next upgrade i.e. xyz--1.0--1.1 so
I will use DROP FUNCTION fun(); in it and remove the definition from the
xyz.c file.
Here my doubt is wouldn't xyz--1.0 complain about the missing definition of
fun() and if yes how can I clean up my function definition in the xyz.c
file?
I had earlier asked the same question in DBS StackExchange
<https://dba.stackexchange.com/questions/335645/how-to-drop-a-function-in-postgres-extension-upgrade-script-with-required-cleanu?noredirect=1#comment653807_335645>
but didn't get any reply hence trying my luck here.

Regards
Ayush Vatsa
Amazon Web Services (AWS)


Re: Query regarding function cleanup in extension upgrade path

2024-02-14 Thread Ayush Vatsa
Hi Tom thanks for the answer,
Just two follow up queries regarding this -
1. Suppose I created a new version 1.1 in which I reduce the C function to
throw an error then ship it, will users get the .c latest file immediately
and their old function will throw error but they have to use ALTER
EXTENSION xyz UPGRADE TO 1.1 to use the latest objects defined in 1.1.sql.
Is this the correct understanding?
2. While going through the contrib folder I find that in the regress test
there are two .out files with respect to a single .sql file, example
citext.out and citext_1.out wrt citext.sql. Why is it so? Even in git blame
, I couldn't find much!

Regards
Ayush Vatsa
Amazon Web Services (AWS)

On Wed, 14 Feb 2024 at 22:07, Tom Lane  wrote:

> Ayush Vatsa  writes:
> > To ask the question let me give a hypothetical example:-
> > Suppose we have an extension named xyz with version 1.0. It has
> > xyz--1.0.sql and xyz.c file. I have declared a function named fun() in
> the
> > xyz--1.0.sql file and its definition in the xyz.c file.
> > Now I want to drop this function in the next upgrade i.e. xyz--1.0--1.1
> so
> > I will use DROP FUNCTION fun(); in it and remove the definition from the
> > xyz.c file.
> > Here my doubt is wouldn't xyz--1.0 complain about the missing definition
> of
> > fun() and if yes how can I clean up my function definition in the xyz.c
> > file?
>
> Yeah, you can't really remove the C extern symbol ever.  You can
> reduce the C function to a stub that just throws a not-supported
> error, perhaps, but your users won't necessarily appreciate that.
> It's usually better to make the shlib capable of supporting both
> the 1.0 and 1.1 APIs, so that users aren't forced into updating
> the extension's SQL declarations immediately.
>
> If you look at the standard contrib modules, you'll find a number
> of cases where there are backwards-compatibility functions that
> just exist to support people who're still using an older version
> of the extension's SQL declarations.  Those are likely to remain
> there indefinitely.
>
> regards, tom lane
>


Query regarding functions of postgres

2024-04-07 Thread Ayush Vatsa
Hi PostgreSQL Community,
Recently I was reading about functions Immutability and security definer
but got confused
Whether the below two functions can be marked immutable or not
1. If a function has constant Raise notice inside it. Eg.

CREATE OR REPLACE FUNCTION text_equals(text, text) RETURNS boolean AS $$BEGIN
RAISE NOTICE 'Comparing two texts';
RETURN $1 = $2;END;
$$ LANGUAGE plpgsql;

2. If a function has Raise notice but extracting current user inside
notice, although its output purely depends on its input arguments eg.

CREATE OR REPLACE FUNCTION text_equals(text, text) RETURNS boolean AS $$BEGIN
RAISE NOTICE 'Current user: %', current_user;
RETURN $1 = $2;END;
$$ LANGUAGE plpgsql;

On security definer part I am confused with the below example

set role postgres;

CREATE OR REPLACE FUNCTION outer_function()
RETURNS TEXT AS $$
DECLARE
user_text TEXT;
BEGIN
SELECT 'OuterFunction() -> Current user is ' || current_user INTO user_text;

user_text := user_text || ' | ' || inner_function();

RETURN user_text;
END;
$$ LANGUAGE plpgsql VOLATILE SECURITY DEFINER;

create role test;

create role alex;

grant create on schema public to test;

set role test;

CREATE OR REPLACE FUNCTION inner_function()
RETURNS TEXT AS $$
DECLARE
current_user_text TEXT;
BEGIN
current_user_text := 'InnerFunction() -> Current user is ' || current_user;
RETURN current_user_text;
END;
$$ LANGUAGE plpgsql VOLATILE SECURITY INVOKER;

set role alex;

select outer_function();

  outer_function
---
 OuterFunction() -> Current user is postgres | InnerFunction() ->
Current user is postgres

Shouldn't it be "InnerFunction() -> Current user is alex" instead of
postgres as alex called the security invoker function


I tried reading docs but couldn't get any satisfactory answers, it
will be helpful if someone helped me out here


Thanks,

Ayush Vatsa

SDE AWS


Clarification on View Privileges and Operator Execution in PostgreSQL

2024-04-07 Thread Ayush Vatsa
Hi PostgreSQL community,
I am recently studying about operators and views and I had doubts in two
small things
1. I know if a view (security definer) is accessing a table then it is
getting accessed by view owners privileges
but what about the view which contains inbuilt operators or inbuilt
functions with whose privileges those will be executed. Eg.
SET ROLE postgres;
CREATE TABLE x(id INT);
CREATE VIEW v AS SELECT * FROM x WHERE id > 100;
CREATE ROLE alex;
GRANT SELECT ON v TO alex;
SET ROLE alex;
SELECT * FROM v;

Now table x will be accessed (SELECT * FROM x) with "postgres" privileges
but who will execute the
underlying function inside the ( > ) operator ? Is it postgres or alex?

2. What if I used a user defined operator in the above example, then with
whose privileges that operator will be executed?

Thanks
Ayush Vatsa
SDE AWS


Re: Clarification on View Privileges and Operator Execution in PostgreSQL

2024-04-07 Thread Ayush Vatsa
> Functions in the view are executed with the privileges of the user
executing the query or the function owner
So does that imply to the function associated with the operators (both
builtin and user defined) too.
Basically wanted to know about this -
> Now table x will be accessed (SELECT * FROM x) with "postgres" privileges
but who will execute the
> underlying function inside the ( > ) operator ? Is it postgres or alex?

On Sun, 7 Apr 2024 at 21:56, David G. Johnston 
wrote:

> On Sun, Apr 7, 2024 at 9:10 AM Ayush Vatsa 
> wrote:
>
>>
>> but what about the view which contains inbuilt operators or inbuilt
>> functions with whose privileges those will be executed. Eg.
>>
>
> From the create view documentation:
> Functions called in the view are treated the same as if they had been
> called directly from the query using the view. Therefore, the user of a
> view must have permissions to call all functions used by the view.
> Functions in the view are executed with the privileges of the user
> executing the query or the function owner, depending on whether the
> functions are defined as SECURITY INVOKER or SECURITY DEFINER.
>


Re: Clarification on View Privileges and Operator Execution in PostgreSQL

2024-04-07 Thread Ayush Vatsa
> If you want to confirm what the documentation says create a custom
operator/function that alex is not permitted to execute and have them query
a view defined by postgres that uses that function.
Thanks for the suggestion, it helped and I found out alex could not execute
the view as it didn't have privileges for the function associated with
operator

But a small doubt arises here I have to revoke the execution of the
function using the command
REVOKE ALL ON ALL FUNCTIONS IN SCHEMA public from public;
but when I tried
REVOKE EXECUTE ON FUNCTION text_equals(text,text) FROM alex;
or
REVOKE ALL ON FUNCTION text_equals(text,text) FROM alex;
It didn't work i.e alex can still execute text_equals function. Why is it
so?

Thanks
Ayush Vatsa
SDE AWS


On Sun, 7 Apr 2024 at 22:31, David G. Johnston 
wrote:

> On Sun, Apr 7, 2024 at 9:32 AM Ayush Vatsa 
> wrote:
>
>>  but who will execute the
>> > underlying function inside the ( > ) operator ? Is it postgres or alex?
>>
>>>
> I'm reasonably confident that all the built-in functions are security
> invoker.  Not that a pure function like greater-than really cares.
>
> David J.
>
>


Re: Clarification on View Privileges and Operator Execution in PostgreSQL

2024-04-07 Thread Ayush Vatsa
Understood.
Thanks David it was a nice conversation and clarification from you

Regards
Ayush Vatsa

On Sun, 7 Apr 2024 at 23:45, David G. Johnston 
wrote:

> On Sun, Apr 7, 2024 at 11:02 AM Ayush Vatsa 
> wrote:
>
>> > If you want to confirm what the documentation says create a custom
>> operator/function that alex is not permitted to execute and have them query
>> a view defined by postgres that uses that function.
>> Thanks for the suggestion, it helped and I found out alex could not
>> execute the view as it didn't have privileges for the function associated
>> with operator
>>
>> But a small doubt arises here I have to revoke the execution of the
>> function using the command
>> REVOKE ALL ON ALL FUNCTIONS IN SCHEMA public from public;
>> but when I tried
>> REVOKE EXECUTE ON FUNCTION text_equals(text,text) FROM alex;
>> or
>> REVOKE ALL ON FUNCTION text_equals(text,text) FROM alex;
>> It didn't work i.e alex can still execute text_equals function. Why is it
>> so?
>>
>>>
>>>
> See https://www.postgresql.org/docs/current/ddl-priv.html
> Especially the part regarding default privileges.  The PUBLIC pseudo-role
> is granted execute on functions by default.  You are probably trying to
> revoke a privilege from alex that was never granted to alex directly.
>
> David J.
>
>


Query Discrepancy in Postgres HLL Test

2024-04-28 Thread Ayush Vatsa
Hi PostgreSQL Community,
I'm currently delving into Postgres HLL (HyperLogLog) functionality and
have encountered an unexpected behavior while executing queries from the "
cumulative_add_sparse_edge.sql
<https://github.com/citusdata/postgresql-hll/blob/master/sql/cumulative_add_sparse_edge.sql#L28-L36>"
regress test. This particular test data file
<https://github.com/citusdata/postgresql-hll/blob/master/sql/data/cumulative_add_sparse_edge.csv#L515-L516>
involves three columns, with the last column representing an HLL
(HyperLogLog) value derived from the previous HLL value and the current raw
value.

Upon manual inspection of the query responsible for deriving the last row's
HLL value, I noticed a discrepancy. When executing the query:
"""
-- '\x148B481002' is second last rows hll value
SELECT hll_add('\x148B481002.', hll_hashval(2561));
"""
instead of obtaining the expected value (''\x148B481002''), I received
a different output which is ('\x138b48000200410061008100a1 ').

My initial assumption is that this could potentially be attributed to a
precision error. However, I'm reaching out to seek clarity on why this
disparity is occurring and to explore potential strategies for mitigating
it (as I want the behaviour to be consistent to regress test file).

Regards
Ayush Vatsa


Seeking Clarification on Function Definitions in PostgreSQL Extensions

2024-06-18 Thread Ayush Vatsa
Hi PostgreSQL community,
Recently I am exploring extensions in postgres and got a little confused
regarding the function definition present in SQL file. For example consider
below three functions:

CREATE FUNCTION fun1(integer)
RETURNS TABLE(
col1 integer,
col2 text
)
AS 'MODULE_PATHNAME', 'fun1'
LANGUAGE C;

CREATE FUNCTION fun2(
IN  input integer,
OUT col1 integer,
OUT col2 text
)
RETURNS SETOF record
AS 'MODULE_PATHNAME', 'fun2'
LANGUAGE C;

CREATE FUNCTION fun3(
IN  input integer,
OUT col1 integer,
OUT col2 text
)
AS 'MODULE_PATHNAME', 'fun3'
LANGUAGE C;

1/ I wanted to know what's the difference between the above three
definitions.
As per my understanding, "fun1" and "fun2" look the same, taking one
integer and returning two columns with multiple rows.
Whereas "fun3" is used when we are returning only one row, but my doubt for
"fun3" is that, Can the above definition (used for fun1 and fun2) cover
both single and multiple row scenarios.

2/ How does someone decide which type of definition is to be used?

Regards
Ayush Vatsa


Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions

2024-06-19 Thread Ayush Vatsa
Hi David,
Thanks for clarification
> I prefer TABLE.  Using setof is more useful when the returned type is
predefined
But in the table also isn't the returned type predefined? Example:
CREATE FUNCTION fun1(integer)
RETURNS TABLE(
col1 integer,
col2 text
)
AS 'MODULE_PATHNAME', 'fun1'
LANGUAGE C;
We know the returned type will have two columns with type -  integer and
text. Am I correct?

> Or a true record where the caller has to specify the shape.
Sorry but didn't get this shape part?

Thanks
Ayush Vatsa


Issue with pgstattuple on Sequences in PostgreSQL

2024-06-24 Thread Ayush Vatsa
Hi PostgreSQL Community,

I was recently exploring the pgstattuple code directory and found this
piece of code:
https://github.com/postgres/postgres/blob/master/contrib/pgstattuple/pgstattuple.c#L255-L259
.

It indicates that pgstattuple supports relations, toast tables,
materialized views, and sequences.
However, when I executed a query with a sequence, I encountered the
following error:

postgres=> CREATE SEQUENCE serial START 101;
CREATE SEQUENCE
postgres=> SELECT * FROM pgstattuple('serial');
ERROR:  only heap AM is supported
postgres=>

It got stuck in this if condition -
https://github.com/postgres/postgres/blob/master/contrib/pgstattuple/pgstattuple.c#L326-L329
How can one use pgstattuple on sequences?

Regards,
Ayush Vatsa


Re: Issue with pgstattuple on Sequences in PostgreSQL

2024-06-25 Thread Ayush Vatsa
>  I agree it’s a documentation bug
Thanks for confirmation, then maybe I can start a new thread in
pgsql-hackers about this bug and I can myself create a patch for the same.

> then the regression test should be fixed as well
I will add regress test for sequences as well.

We can remove *SEQUENCE* from
https://github.com/postgres/postgres/blob/master/contrib/pgstattuple/pgstattuple.c#L255-L259

as well so that users can encounter *ERRCODE_FEATURE_NOT_SUPPORTED*.

Thanks
Ayush Vatsa
SDE AWS


Issues with PostgreSQL Source Code Installation

2024-09-24 Thread Ayush Vatsa
Hi PostgreSQL Community,

I am encountering an issue while trying to install PostgreSQL from its
source code and would appreciate any guidance you can provide.
Here are the steps I've taken so far:
sudo yum install libicu-devel
git clone git://git.postgresql.org/git/postgresql.git
./configure --enable-tap-tests --prefix=`pwd`/build
make world-bin

However, during the make world-bin process, I am encountering the following
errors:

/usr/bin/ld: commands/collationcmds.o: in function
`pg_import_system_collations':
collationcmds.c:(.text+0xeed): undefined reference to
`uloc_countAvailable_73'
/usr/bin/ld: collationcmds.c:(.text+0xf0a): undefined reference to
`uloc_getAvailable_73'
/usr/bin/ld: collationcmds.c:(.text+0xfc6): undefined reference to
`uloc_getDisplayName_73'
/usr/bin/ld: regex/regcomp.o: in function `pg_wc_isalpha':
regcomp.c:(.text+0xe41): undefined reference to `u_isalpha_73'
/usr/bin/ld: regex/regcomp.o: in function `pg_wc_isspace':
regcomp.c:(.text+0xef1): undefined reference to `u_isspace_73'
/usr/bin/ld: regex/regcomp.o: in function `pg_wc_isdigit':
regcomp.c:(.text+0x1031): undefined reference to `u_isdigit_73'
/usr/bin/ld: regex/regcomp.o: in function `pg_wc_isalnum':
regcomp.c:(.text+0x10e1): undefined reference to `u_isalnum_73'
/usr/bin/ld: regex/regcomp.o: in function `pg_wc_isgraph':
regcomp.c:(.text+0x1c81): undefined reference to `u_isgraph_73'
/usr/bin/ld: regex/regcomp.o: in function `pg_wc_isupper':
regcomp.c:(.text+0x1d31): undefined reference to `u_isupper_73'
/usr/bin/ld: regex/regcomp.o: in function `pg_wc_islower':

I have ICU version 73.1 installed, which I confirmed with: icu-config
--version
My ~/.zshrc file looks like:

export LDFLAGS="-L/usr/lib64 -L/usr/local/lib"
export CPPFLAGS="-I/usr/include"
export PATH="/usr/lib64/icu:$PATH"
export PKG_CONFIG_PATH="/usr/lib64/pkgconfig/:/usr/local/lib/pkgconfig"
export LD_LIBRARY_PATH="/usr/lib64:/usr/local/lib:$LD_LIBRARY_PATH"

Output for: sudo find / -name libicui18n.so
/usr/lib64/libicui18n.so

I am using:
Linux kernel version: 6.1.106-116.188.amzn2023.x86_64
Architecture: x86_64

Regards
Ayush


Re: Issues with PostgreSQL Source Code Installation

2024-09-24 Thread Ayush Vatsa
> Why are you building against the repo instead  of a fixed version from
> here?:
So actually I wanted to modify and playaround with the code,
hence I am using the github repo and building postgres from it.

> Did you checkout a given tag?
I haven't checkout on any branch and currently
on branch master where I am trying to build postgres

Regards
Ayush


Re: Issues with PostgreSQL Source Code Installation

2024-09-24 Thread Ayush Vatsa
> I would go to the source link I posted download a specific version and
> verify it builds. Then you know whether your setup is correct. Then you
> could go back to exploring the Git code.
Thanks will check that out


Re: Issues with PostgreSQL Source Code Installation

2024-09-26 Thread Ayush Vatsa
> It looks to me like there is something
> wrong with your libicu installation --- perhaps headers out of sync
> with shared library?
Yes correct, fixing libicu installation resolved the issue.


Understanding ALTER DEFAULT PRIVILEGES Behavior in PostgreSQL

2025-02-04 Thread Ayush Vatsa
Hello PostgreSQL Community,

I was experimenting with default privileges in PostgreSQL and came across a
behavior I didn’t
fully understand. I would appreciate any insights on this.

I wanted to ensure that, by default, no roles had EXECUTE privileges on
functions created in my
schema. To achieve this, I ran the following:

postgres=# CREATE SCHEMA my_schema;
CREATE SCHEMA

postgres=# CREATE ROLE alex LOGIN;
CREATE ROLE

postgres=# ALTER DEFAULT PRIVILEGES IN SCHEMA my_schema REVOKE EXECUTE ON
FUNCTIONS FROM PUBLIC;
ALTER DEFAULT PRIVILEGES

postgres=# CREATE OR REPLACE FUNCTION my_schema.hello_world()
RETURNS TEXT AS $$
BEGIN
RETURN 'Hello, World!';
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION

postgres=# GRANT USAGE ON SCHEMA my_schema TO alex;
GRANT

postgres=# SET ROLE alex;
SET

postgres=> SELECT my_schema.hello_world();
  hello_world
---
 Hello, World!
(1 row)

To my surprise, alex was still able to execute the function hello_world,
even though I had
altered the default privileges before creating it. I was expecting the
function to be inaccessible
unless explicitly granted permissions.

Could someone help me understand why this happens? Also, what would be the
best way to
ensure that, by default, no roles (except the function owner) have any
privileges on new
functions created in my protected schema?
I know about REVOKE ALL ON ALL FUNCTIONS IN SCHEMA my_schema FROM public but
this won't work for the functions created after this revoke statement.

Thanks
Ayush Vatsa


Clarification on Role Access Rights to Table Indexes

2025-02-17 Thread Ayush Vatsa
Hi PostgreSQL Community,
I am currently exploring the behavior of pg_prewarm and encountered an
issue related to role
access rights that I was hoping you could help clarify.

Here is the scenario I observed:

postgres=# CREATE ROLE alpha;
CREATE ROLE
postgres=# GRANT SELECT ON pg_class TO alpha;
GRANT
postgres=# SET ROLE alpha;
SET
postgres=> SELECT pg_prewarm('pg_class');
 pg_prewarm

 14
(1 row)

postgres=> SELECT pg_prewarm('pg_class_oid_index');
ERROR:  permission denied for index pg_class_oid_index
postgres=> RESET ROLE;
RESET

postgres=# GRANT SELECT ON pg_class_oid_index TO alpha;
ERROR:  "pg_class_oid_index" is an index

Based on this, I have few questions:
1. Can a role have access rights to a table without having access to its
index?
2. If yes, how can we explicitly grant access to the index?
3. If no, and the role inherently gets access to the index when granted
access to the table, why
does the pg_prewarm call fail [1] in the above scenario?

[1]
https://github.com/postgres/postgres/blob/master/contrib/pg_prewarm/pg_prewarm.c#L108-L110


Regards,
Ayush Vatsa
SDE AWS


Re: Clarification on Role Access Rights to Table Indexes

2025-02-17 Thread Ayush Vatsa
> This is pointless, everyone (i.e. the PUBLIC pseudo-role) can already
read pg_class.
True, Just checked that.

> It fails because AFAICS there is no way for it to work on an index, only
tables.
pg_prewarm extension works on index if we have right (SELECT) privileges
postgres=# CREATE TABLE x(id INT);
CREATE TABLE
postgres=# CREATE INDEX idx ON x(id);
CREATE INDEX

postgres=# INSERT INTO x SELECT * FROM generate_series(1,1);
INSERT 0 1
postgres=# SELECT pg_prewarm('x');
 pg_prewarm

 45
(1 row)

postgres=# SELECT pg_prewarm('idx');
 pg_prewarm

 30
(1 row)

> It seems like ownership of the table would be more appropriate, or maybe
> access to one of the built-in roles like pg_maintain.
True, adding Robert Haas (author) to this thread for his opinion.

Regards,
Ayush Vatsa
SDE AWS


Clarification on REVOKE ALL ON FUNCTION – Are there any privileges apart from EXECUTE?

2025-05-18 Thread Ayush Vatsa
Hi Postgres Community,
I had a quick question regarding function-level privileges in PostgreSQL.
We know that REVOKE EXECUTE ON FUNCTION ... removes the ability to call the
function. But when we do:
REVOKE ALL ON FUNCTION my_func(args) FROM some_role;

does this revoke anything other than EXECUTE? Are there any other
privileges that apply to functions which get revoked via REVOKE ALL?

I looked through the documentation but couldn’t find a definitive answer on
whether ALL includes more than just EXECUTE in the context of functions.

Would appreciate any insights or pointers.

---
Regards,
Ayush