The manage_user_permissions PostgreSQL extension simplifies the process of creating users, databases, and managing permissions dynamically. This extension provides functions to handle common tasks such as creating databases, granting or revoking permissions, and helping with usage details.
-
Create Databases and Users Dynamically
- Automatically creates a database and its owner with a secure, randomly generated password.
-
Grant or Revoke Permissions
- Assign or revoke fine-grained permissions such as data reading, writing, updating, monitoring, schema connection, and more.
-
Help Functionality
- Provides detailed usage instructions for all supported operations.
SELECT manage_user_permissions('help');Provides usage details, including supported operations, parameters, and examples.
SELECT manage_user_permissions('user_name', 'database_name');- Automatically creates a user with a secure random password.
- Creates the specified database with the user as the owner.
- Returns the generated password for the created user.
SELECT manage_user_permissions(
'user_name',
'database_name',
'permissions',
'action',
'schema_name'
);- Permissions:
data_loader,data_read,data_write,data_update_only,data_monitor,user_login,connect_schema,all. - Actions:
grantorrevoke. - Schema Name: Defaults to
publicif not specified.
-
Download the latest version of the RPM from your repository or local source it also support PostgreSQL 13 or later:
manage_user_permissions-1.4-1.pg13.el9.x86_64.rpm manage_user_permissions-1.4-1.pg14.el9.x86_64.rpm manage_user_permissions-1.4-1.pg15.el9.x86_64.rpm manage_user_permissions-1.4-1.pg16.el9.x86_64.rpm -
Install the RPM package:
sudo rpm -ivh manage_user_permissions-1.4-1.pg13.el9.x86_64.rpm sudo rpm -ivh manage_user_permissions-1.4-1.pg14.el9.x86_64.rpm sudo rpm -ivh manage_user_permissions-1.4-1.pg15.el9.x86_64.rpm sudo rpm -ivh manage_user_permissions-1.4-1.pg16.el9.x86_64.rpm
-
Verify installation:
rpm -q manage_user_permissions
-
Connect to your PostgreSQL instance:
psql -U postgres
-
Enable the extension in your database:
CREATE EXTENSION manage_user_permissions;
-
Verify the extension is enabled:
\dx
-
Get Help:
SELECT manage_user_permissions('help');
-
Create a User and Database:
SELECT manage_user_permissions('test_user', 'test_db');
-
Grant Data Read Permission:
SELECT manage_user_permissions( 'test_user', 'test_db', 'data_read', 'grant', 'public' );
-
Revoke User Login:
SELECT manage_user_permissions( 'test_user', 'test_db', 'user_login', 'revoke', 'public' );
-
Ensure the
dblinkextension is installed and enabled on your PostgreSQL instance:CREATE EXTENSION dblink;
-
Replace
yourpasswordwith a secure password for thepostgresuser in the scripts. -
Manage access to the generated user passwords securely.
If you encounter issues or have feature requests, feel free to open an issue or contribute to the GitHub repository.