0

I am encountering an issue in PostgreSQL where a specific user cannot see all the tables in information_schema.tables, even though all tables belong to the same database and schema.

Context:

  • PostgreSQL version: 14.5
  • All tables are in a single database (not the postgres database).
  • The user has been granted access to the schema and tables using:
GRANT USAGE ON SCHEMA public TO my_user;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO my_user;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO my_user;
  • The user can see some tables in information_schema.tables, but others are missing.

What I’ve checked:

  • Verified privileges on the missing tables using information_schema.role_table_grants:
SELECT table_schema, table_name, grantee, privilege_typeFROM information_schema.role_table_grants
WHERE table_name = 'missing_table';
  • Ensured the user has USAGE privileges on the public schema:
SELECT schema_name, grantee, privilege_type
FROM information_schema.role_usage_grants
WHERE schema_name = 'public';
  • Verified that the missing tables are owned by the same user as the visible ones:
SELECT table_schema, table_name, table_owner
FROM information_schema.tables
WHERE table_name IN ('visible_table', 'missing_table');
  • Checked the user’s roles and privileges using:
SELECT * FROM information_schema.role_table_grants WHERE grantee = 'my_user';

Observations:

  • The user can query the visible tables without issues.
  • The user can also query the missing tables directly, e.g.:
SELECT * FROM public.missing_table;

This works without any errors, suggesting that the user does have sufficient privileges on the table itself. However, the tables do not appear in information_schema.tables.

Question:

  • What could cause certain tables to be invisible in information_schema.tables for a user, even though they belong to the same schema and the same GRANT commands were applied?
  • How can I troubleshoot this further to identify the root cause?

Additional Information:

  • All tables are part of the public schema.
  • I have administrative access to the database and can execute any necessary queries or provide more details.

Any help or guidance on resolving this would be greatly appreciated!

9
  • 1
    The only thing I can think of at the moment is index issue on system tables. As admin/superuser try reindex schema pg_catalog; and the query information_schema.tables. Commented Dec 27, 2024 at 19:04
  • Thank you for the answer. I tried to reindex, but unfortunately the issue persists. Commented Dec 27, 2024 at 19:30
  • 1
    1) In psql do \dn+ and add the result as text to the question text. 2) Again in psql do \dp missing_table and add result to question text. Commented Dec 27, 2024 at 22:54
  • It would be useful to have a script that makes the problem reproducible. For example, you could pg_dump -s a problem table from the database. Commented Dec 28, 2024 at 5:26
  • @AdrianKlaver, thank you. In order to generate psql outputs for those commands as the user that then selects tables from information_schema, I needed to change pg_hba.conf file. After the postgres service restart - the original script that was not able to fetch those tables is working flawlessy! Any chance that GRANT commands needed that postgresql restart in order to take effect? Is there something like "FLUSH PRIVILEGES" command in mysql for postgres also? Another question: as the original question now is out of context, what should I do? Commented Dec 28, 2024 at 15:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.