Skip to content

Learning PostgreSQL connection pooling while implementing. Just the core functionality implementation.

Notifications You must be signed in to change notification settings

srcecde/postgresql-connection-pooling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PostgreSQL Connection Pooling

Naive implementation of the connection pooling for learning purpose.

Usage


from pgpool import ConnectionPool
con_obj = ConnectionPool(
        min_pool_size=5,
        max_pool_size=10,
        user="admin",
        password="admin",
        host="localhost",
        port="5432",
        dbname="postgres",
    )

print(f"Available connections: {con_obj.available_connections}")
print(f"Total connections: {con_obj.total_connection_pool}")

# get connection from pool
conn1 = con_obj.get_connection()

print(f"Available connections: {con_obj.available_connections}")
print(f"Total connections: {con_obj.total_connection_pool}")

# query execution
with conn1.cursor() as cur:
    cur.execute("SELECT 1")
    print(cur.fetchall())

# closing connection
con_obj.close(conn1)

print(f"Available connections: {con_obj.available_connections}")
print(f"Total connections: {con_obj.total_connection_pool}")

WIP

About

Learning PostgreSQL connection pooling while implementing. Just the core functionality implementation.

Topics

Resources

Stars

Watchers

Forks