|
| 1 | +--- |
| 2 | +title: User profiles |
| 3 | +description: Learn how to manage user profiles and set resource limits for users in Memgraph Enterprise. |
| 4 | +--- |
| 5 | + |
| 6 | +# User profiles |
| 7 | + |
| 8 | +User profiles allow you to set resource limits for users in Memgraph Enterprise. You can define limits on the number of sessions and memory usage to control resource consumption and prevent abuse. |
| 9 | + |
| 10 | +User profiles provide a way to: |
| 11 | +- Set resource limits for individual users |
| 12 | +- Control the number of concurrent sessions per user |
| 13 | +- Limit query memory usage over all active |
| 14 | +- Monitor resource consumption in real-time |
| 15 | +- Enforce resource quotas to prevent system abuse |
| 16 | + |
| 17 | +## Prerequisites |
| 18 | + |
| 19 | +To use user profiles, you need: |
| 20 | +- Memgraph Enterprise Edition |
| 21 | +- The `PROFILE_RESTRICTION` privilege to manage profiles |
| 22 | + |
| 23 | +## Creating profiles |
| 24 | + |
| 25 | +You can create a profile with default unlimited limits: |
| 26 | + |
| 27 | +```cypher |
| 28 | +CREATE PROFILE profile_name; |
| 29 | +``` |
| 30 | + |
| 31 | +Or create a profile with specific limits: |
| 32 | + |
| 33 | +```cypher |
| 34 | +CREATE PROFILE profile_name LIMIT sessions 10, transactions_memory 100MB; |
| 35 | +``` |
| 36 | + |
| 37 | +### Available limits |
| 38 | + |
| 39 | +- **sessions**: Maximum number of concurrent sessions (default: unlimited) |
| 40 | +- **transactions_memory**: Maximum query memory usage over all active transactions (default: unlimited) |
| 41 | + |
| 42 | +### Limit values |
| 43 | + |
| 44 | +You can specify limits in different formats: |
| 45 | + |
| 46 | +- **Unlimited**: `UNLIMITED` (default) |
| 47 | +- **Quantity**: A positive number (e.g., `10`) |
| 48 | +- **Memory**: A number with unit MB/KB (e.g., `100MB`, `512KB`) |
| 49 | + |
| 50 | +### Examples |
| 51 | + |
| 52 | +```cypher |
| 53 | +-- Create a profile with session limit only |
| 54 | +CREATE PROFILE session_limited LIMIT sessions 5; |
| 55 | +
|
| 56 | +-- Create a profile with memory limit only |
| 57 | +CREATE PROFILE memory_limited LIMIT transactions_memory 50MB; |
| 58 | +
|
| 59 | +-- Create a profile with both limits |
| 60 | +CREATE PROFILE strict_profile LIMIT sessions 3, transactions_memory 25MB; |
| 61 | +
|
| 62 | +-- Create a profile with different memory units |
| 63 | +CREATE PROFILE small_profile LIMIT transactions_memory 1KB; |
| 64 | +``` |
| 65 | + |
| 66 | +## Managing profiles |
| 67 | + |
| 68 | +### Update a profile |
| 69 | + |
| 70 | +```cypher |
| 71 | +UPDATE PROFILE profile_name LIMIT sessions 5, transactions_memory 50MB; |
| 72 | +``` |
| 73 | + |
| 74 | +### Drop a profile |
| 75 | + |
| 76 | +```cypher |
| 77 | +DROP PROFILE profile_name; |
| 78 | +``` |
| 79 | + |
| 80 | +**Note**: When you drop a profile, all users assigned to that profile will have their limits reset and profile assignment cleared. |
| 81 | + |
| 82 | + |
| 83 | +### Clear a profile assignment |
| 84 | + |
| 85 | +```cypher |
| 86 | +CLEAR PROFILE FOR username; |
| 87 | +``` |
| 88 | + |
| 89 | +This removes the profile assignment, returning the user to unlimited resources. |
| 90 | + |
| 91 | +## Viewing profile assignments |
| 92 | + |
| 93 | +### Show profile for a user |
| 94 | + |
| 95 | +```cypher |
| 96 | +SHOW PROFILE FOR username; |
| 97 | +``` |
| 98 | + |
| 99 | +### Show users assigned to a profile |
| 100 | + |
| 101 | +```cypher |
| 102 | +SHOW USERS FOR PROFILE profile_name; |
| 103 | +``` |
| 104 | + |
| 105 | +## Monitoring resource usage |
| 106 | + |
| 107 | +### Show resource usage for a user |
| 108 | + |
| 109 | +```cypher |
| 110 | +SHOW RESOURCE USAGE FOR username; |
| 111 | +``` |
| 112 | + |
| 113 | +This command shows the current resource consumption and imposed limits for the specified user, including: |
| 114 | +- Number of active sessions |
| 115 | +- Current transaction memory usage |
| 116 | + |
| 117 | +## Profile management |
| 118 | + |
| 119 | +User profiles are assigned directly to users and provide resource limits for those specific users. Each user can have one profile assigned at a time. |
| 120 | + |
| 121 | +### Profile assignment behavior |
| 122 | + |
| 123 | +**Important**: Profile assignment is a simple mapping between profile names and usernames. This means: |
| 124 | + |
| 125 | +- **Users don't need to exist** when you assign a profile to them |
| 126 | +- You can assign a profile to a username that hasn't been created yet |
| 127 | +- You can assign a profile to a SSO user that will never exist in Memgraph |
| 128 | +- The profile will be automatically applied when that user connects to the database |
| 129 | +- Dropping a profile **does remove the mapping** |
| 130 | + |
| 131 | +## Error handling |
| 132 | + |
| 133 | +The system provides clear error messages for invalid operations: |
| 134 | + |
| 135 | +- **Duplicate profile creation**: Error when trying to create a profile with an existing name |
| 136 | +- **Non-existent profile operations**: Error when trying to show, update, or drop non-existent profiles |
| 137 | +- **Invalid limit values**: Error for negative numbers or invalid memory units |
| 138 | +- **Invalid limit names**: Error for unsupported limit types |
| 139 | + |
| 140 | +**Note**: Assigning a profile to a non-existent user will **not** cause an error. The assignment will be stored and applied when the user connects to the database. |
| 141 | + |
| 142 | +## Best practices |
| 143 | + |
| 144 | +1. **Start with unlimited profiles**: Create profiles without limits first, then gradually add restrictions |
| 145 | +2. **Monitor usage**: Regularly check resource usage to understand actual consumption patterns |
| 146 | + |
| 147 | +## Examples |
| 148 | + |
| 149 | +### Complete workflow example |
| 150 | + |
| 151 | +```cypher |
| 152 | +-- 1. Create users |
| 153 | +CREATE USER developer1; |
| 154 | +CREATE USER developer2; |
| 155 | +
|
| 156 | +-- 2. Create profiles with different restrictions |
| 157 | +CREATE PROFILE basic_profile LIMIT sessions 10; |
| 158 | +CREATE PROFILE strict_profile LIMIT sessions 3, transactions_memory 50MB; |
| 159 | +
|
| 160 | +-- 3. Assign profiles |
| 161 | +SET PROFILE FOR developer1 TO basic_profile; |
| 162 | +SET PROFILE FOR developer2 TO strict_profile; |
| 163 | +
|
| 164 | +-- 4. Verify assignments |
| 165 | +SHOW PROFILE FOR developer1; |
| 166 | +SHOW USERS FOR PROFILE basic_profile; |
| 167 | +
|
| 168 | +-- 5. Monitor usage |
| 169 | +SHOW RESOURCE USAGE FOR developer1; |
| 170 | +
|
| 171 | +-- 6. Update limits based on usage patterns |
| 172 | +UPDATE PROFILE strict_profile LIMIT sessions 5, transactions_memory 25MB; |
| 173 | +
|
| 174 | +-- 7. Verify limits |
| 175 | +SHOW RESOURCE USAGE FOR developer2; |
| 176 | +``` |
| 177 | + |
| 178 | +## Syntax reference |
| 179 | + |
| 180 | +| Command | Description | |
| 181 | +|---------|-------------| |
| 182 | +| `CREATE PROFILE name [LIMIT limit_list]` | Create a new profile | |
| 183 | +| `UPDATE PROFILE name LIMIT limit_list` | Update existing profile limits | |
| 184 | +| `DROP PROFILE name` | Delete a profile | |
| 185 | +| `SHOW PROFILES` | List all profiles | |
| 186 | +| `SHOW PROFILE name` | Show specific profile details | |
| 187 | +| `SET PROFILE FOR user TO profile` | Assign profile to user | |
| 188 | +| `CLEAR PROFILE FOR user` | Remove profile assignment | |
| 189 | +| `SHOW PROFILE FOR user` | Show profile assigned to user | |
| 190 | +| `SHOW USERS FOR PROFILE name` | List users assigned to profile | |
| 191 | +| `SHOW RESOURCE USAGE FOR user` | Show current resource usage | |
| 192 | + |
| 193 | +### Limit syntax |
| 194 | + |
| 195 | +``` |
| 196 | +limit_list: limit_item [, limit_item]* |
| 197 | +limit_item: sessions number | transactions_memory memory_value |
| 198 | +memory_value: number (MB | KB) |
| 199 | +number: positive integer |
| 200 | +``` |
0 commit comments