-
-
Notifications
You must be signed in to change notification settings - Fork 563
PostgreSQL: Constraints not showing when connected as a read-only user #1653
Copy link
Copy link
Closed
Labels
enhancementEnhances an existing featureEnhances an existing featurenettype-postgresqlPostgreSQL specific issuePostgreSQL specific issue
Milestone
Description
Preconditions
- HeidiSQL version: 12.1.0.6540
- Database type and version: postgresql 14.4.0
- OS: Windows
Describe the bug
HeidiSQL is looking for constraints (e.g. foreign key) by examining the information_schema.constraint_column_usage table. Unfortunately, columns will only be returned if the user is the owner of the table. See: https://www.postgresql.org/docs/current/infoschema-constraint-column-usage.html So if I connect to the database as any other user, e.g. a read-only user, then this information is not being shown.
As an alternative, foreign keys can be discovered with a slightly different query:
SELECT
conrelid::regclass AS table_from,
conname,
pg_get_constraintdef(c.oid) AS constraintdef
FROM pg_constraint c
JOIN pg_namespace n
ON n.oid = c.connamespace
WHERE contype IN ('f')
AND n.nspname = 'schema_name_here';
To Reproduce
- Create a database, schema, and a table with a foreign key to another table
- Create a user with read only privileges: grant usage on schema "your_schema_name" to "ro_user", grant select on all tables in schema "your_schema_name" to "ro_user";
- Connect to the database as "ro_user" and try to view foreign keys on your table, you will see 0.
- Connect to the database as a super user, you will see the foreign keys.
Screenshots or Crash reports
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementEnhances an existing featureEnhances an existing featurenettype-postgresqlPostgreSQL specific issuePostgreSQL specific issue