Skip to content

Commit 38a4dde

Browse files
authored
Merge pull request #280355 from shriram-muthukrishnan/userrolesmod
Converting the workaround to query based approach
2 parents a378cd7 + a9facfa commit 38a4dde

File tree

1 file changed

+58
-19
lines changed

1 file changed

+58
-19
lines changed

articles/postgresql/migrate/migration-service/concepts-user-roles-migration-service.md

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,67 @@ We removed all privileges for non-superusers on the following pg_catalog views.
5454

5555
Allowing unrestricted access to these system tables and views could lead to unauthorized modifications, accidental deletions, or even security breaches. By restricting access, we're reducing the risk of unintended changes or data exposure.
5656

57+
### pg_pltemplate deprecation
58+
59+
Another important consideration is the deprecation of the **pg_pltemplate** system table within the pg_catalog schema by the PostgreSQL community **starting from version 13.** Therefore, if you're migrating to Flexible Server versions 13 and above, and if you have granted permissions to users on the pg_pltemplate table, it is necessary to undo these permissions before initiating the migration process.
60+
5761
#### What is the impact?
5862
- If your application is designed to directly query the affected tables and views, it will encounter issues upon migrating to the flexible server. We strongly advise you to refactor your application to avoid direct queries to these system tables.
5963

60-
- If you have granted privileges to any users or roles for the affected pg_catalog tables and views, you encounter an error during the migration process. This error will be identified by the following pattern: **"pg_restore error: could not execute query GRANT/REVOKE PRIVILEGES on TABLENAME to username."**
61-
To resolve this error, it's necessary to revoke the select privileges granted to various users and roles on the pg_catalog tables and views. You can accomplish this by taking the following steps.
62-
1. Take a pg_dump of the database containing only the schema by executing the following command from a machine with access to your single server.
63-
```sql
64-
pg_dump -h <singleserverhostname> -U <username@singleserverhostname> -d <databasename> -s > dump_output.sql
65-
```
66-
2. Search for **GRANT** statements associated with the impacted tables and views in the dump file. These GRANT statements follow this format.
67-
```sql
68-
GRANT <privileges> to pg_catalog.<impacted tablename/viewname> to <username>;
69-
```
70-
3. If any such statements exist, ensure to execute the following command on your single server for each GRANT statement.
71-
```sql
72-
REVOKE <privileges> ON pg_catalog.<impacted tablename/viewname> from <username>;
73-
```
74-
75-
##### Understanding pg_pltemplate deprecation
76-
Another important consideration is the deprecation of the **pg_pltemplate** system table within the pg_catalog schema by the PostgreSQL community **starting from version 13.** Therefore, if you're migrating to Flexible Server versions 13 and above, and if you have granted permissions to users on the pg_pltemplate table, it is necessary to revoke these permissions before initiating the migration process. You can follow the same steps outlined above and conduct a search for **pg_pltemplate** in Step 2. Failure to do so leads to a failed migration.
77-
78-
After completing these steps, you can proceed to initiate a new migration from the single server to the flexible server using the migration tool. You're expected not to encounter permission-related issues during this process.
64+
- If you have specifically granted or revoked privileges to any users or roles for the affected pg_catalog tables and views, you will encounter an error during the migration process. This error will be identified by the following pattern:
65+
66+
```sql
67+
pg_restore error: could not execute query <GRANT/REVOKE> <PRIVILEGES> on <affected TABLE/VIEWS> to <user>.
68+
```
69+
70+
To resolve this error, it's necessary to undo the privileges granted to users and roles on the affected pg_catalog tables and views. You can accomplish this by taking the following steps.
71+
72+
**Step 1: Identify Privileges**
73+
74+
Execute the following query on your single server by logging in as the admin user:
75+
76+
```sql
77+
SELECT
78+
array_to_string(array_agg(acl.privilege_type), ', ') AS privileges,
79+
t.relname AS relation_name,
80+
r.rolname AS grantee
81+
FROM
82+
pg_catalog.pg_class AS t
83+
CROSS JOIN LATERAL aclexplode(t.relacl) AS acl
84+
JOIN pg_roles r ON r.oid = acl.grantee
85+
WHERE
86+
acl.grantee <> 'azure_superuser'::regrole
87+
AND t.relname IN (
88+
'pg_authid', 'pg_largeobject', 'pg_subscription', 'pg_user_mapping', 'pg_statistic',
89+
'pg_config', 'pg_file_settings', 'pg_hba_file_rules', 'pg_replication_origin_status', 'pg_shadow', 'pg_pltemplate'
90+
)
91+
GROUP BY
92+
r.rolname, t.relname;
93+
94+
```
95+
96+
**Step 2: Review the Output**
97+
98+
The output of the above query will show the list of privileges granted to roles on the impacted tables and views.
99+
100+
For example:
101+
102+
| Privileges | Relation name | Grantee |
103+
| :--- | :--- | :--- |
104+
| SELECT | pg_authid | adminuser1
105+
| SELECT, UPDATE | pg_shadow | adminuser2
106+
107+
**Step 3: Undo the privileges**
108+
109+
To undo the privileges, run REVOKE statements for each privilege on the relation from the grantee. In the above example, you would run:
110+
111+
```sql
112+
REVOKE SELECT ON pg_authid FROM adminuser1;
113+
REVOKE SELECT ON pg_shadow FROM adminuser2;
114+
REVOKE UPDATE ON pg_shadow FROM adminuser2;
115+
```
116+
117+
After completing these steps, you can proceed to initiate a new migration from the single server to the flexible server using the migration service. You should not encounter permission-related issues during this process.
79118

80119
## Related content
81120
- [Migration service](concepts-migration-service-postgresql.md)

0 commit comments

Comments
 (0)