A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3resource.com/PostgreSQL/snippets/postgresql-max-connections.php below:

Website Navigation


Understanding PostgreSQL Max Connections Configuration

Understanding PostgreSQL Max Connections ConfigurationLast update on December 31 2024 05:34:49 (UTC/GMT +8 hours)

PostgreSQL Max Connections: Managing Connection Limits

PostgreSQL allows administrators to control the maximum number of concurrent database connections using the max_connections parameter. This setting ensures that server resources are efficiently utilized without overwhelming the system. Adjusting this parameter requires changes to the PostgreSQL configuration file and a server restart. In this guide, we will explore how to configure and manage max_connections with examples.

Syntax:

Examples and Code:

1. Viewing Current Max Connections

Code:

-- Check the current maximum allowed connections
SHOW max_connections;

Output:

plaintext
Copy code
 max_connections
-----------------
 100
(1 row)

2. Modifying Max Connections in postgresql.conf

3. Setting Connections Dynamically Using SQL (Temporary)

Code:

-- Set max connections dynamically for the session
SET max_connections TO 150;

Note: This change only lasts for the current session and does not persist after a restart.

4. Monitoring Active Connections

To monitor the number of active and idle connections:

Code:

-- View active connections
SELECT 
    datname AS database_name, 
    usename AS user_name, 
    count(*) AS active_connections 
FROM pg_stat_activity 
GROUP BY datname, usename;

Output:

database_name	user_name	active_connections
postgres	admin	10
mydb	user1	5

Explanation

Use Cases:

All PostgreSQL Questions, Answers, and Code Snippets Collection.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4