How to Create a PostgreSQL Role with Limited Connections
Create a Role with Limited Connection Attempts
Write a PostgreSQL query to create a role limited_user with a maximum of 3 connections.
Solution:
-- Create a role with limited connections
CREATE ROLE limited_user WITH LOGIN CONNECTION LIMIT 3;
Explanation:
- Purpose of the Query:
- Restricts simultaneous database connections.
- Key Components:
- CONNECTION LIMIT 3: Limits connections to 3.
- Real-World Application:
- Prevents excessive resource usage.
For more Practice: Solve these Related Problems:
- Write a PostgreSQL query to create a role restricted_user with a maximum of 5 concurrent connections and set a login time window.
- Write a PostgreSQL query to create a role temp_access that limits connection attempts to 3 per hour.
- Write a PostgreSQL query to create a role secure_role that has a maximum connection limit and is only allowed to connect from specified IP addresses.
- Write a PostgreSQL query to create a role controlled_user with both a connection limit and a timeout period for idle sessions.
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous PostgreSQL Exercise: Lock a User Account.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.