Skip to content

Commit 3d77281

Browse files
authored
Merge pull request #37 from clauspruefer/v1.0.1rc
V1.0.1
2 parents 34204bd + 0ca4eef commit 3d77281

6 files changed

Lines changed: 97 additions & 44 deletions

File tree

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Run tests
2+
3+
on:
4+
[push, pull_request]
5+
6+
jobs:
7+
test:
8+
name: Run tests and collect coverage
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 2
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
19+
- name: Install dependencies
20+
run: pip install pytest pytest-cov pytest-pep8
21+
22+
- name: Build Python module
23+
run: python3 setup.py sdist
24+
25+
- name: Install Python module
26+
run: pip3 install ./dist/pgdbpool-1.0.1.tar.gz
27+
28+
- name: Run tests
29+
run: pytest --cov --cov-branch --cov-report=xml

CHANGELOG.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
# Changelog
22

3+
## Version 1.0.1
4+
5+
### Bug Fixes
6+
7+
- **Default Configuration Values**: Added default values for optional database configuration parameters
8+
- `query_timeout`: Default 5000 milliseconds (5 seconds)
9+
- `session_tmp_buffer`: Default 128 MB
10+
- `ssl`: Default 'disable'
11+
- `connect_timeout`: Default 10 seconds
12+
- Fixes issue where example `01-logical-replication` would not work without explicit configuration
13+
14+
### Changes
15+
16+
- **Connection Retry**: Removed configurable connect retry sleep time
17+
- Connection retry sleep time is now statically set to 1 second
18+
- Simplifies configuration by removing `connection_retry_sleep` parameter
19+
20+
### Documentation
21+
22+
- **Configuration Documentation**: Updated configuration documentation to reflect correct units and types
23+
- Corrected `query_timeout` unit from Seconds to Milliseconds
24+
- Corrected `ssl` type from boolean to enum (disable|allow|prefer|require)
25+
- Updated default values to match implementation
26+
- Simplified multi-database configuration examples to show only required parameters
27+
28+
### CI/CD
29+
30+
- **GitHub Actions**: Added GitHub Actions CI workflow
31+
- Runs tests on push and pull request events
32+
- Includes pytest with coverage reporting
33+
- Validates module build and installation
34+
335
## Version 1.0 (Stable)
436

537
- Stable release tested and verified

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
## 1. Primary Scope
77

8-
The **pgdbpool** Python module is a tiny **PostgreSQL Database Connection De-Multiplexer**, primarily designed for *Web- / Application Servers*.
8+
The **pgdbpool** Python module is a tiny **PostgreSQL Database Connection De-Multiplexer**.
99

1010
**Key Features:**
1111
- **Multi-endpoint support**: Load balance across multiple PostgreSQL servers
@@ -17,12 +17,12 @@ The **pgdbpool** Python module is a tiny **PostgreSQL Database Connection De-Mul
1717

1818
```text
1919
+----------------------+ +---------------------
20-
| WebServer Service.py | -- Handler Con #1 ----> | PostgreSQL
20+
| Server Service.py | -- Handler Con #1 ----> | PostgreSQL
2121
| Request / Thread #1 | | Backend #1
2222
+----------------------+ |
2323
|
2424
+----------------------+ |
25-
| WebServer Service.py | -- Handler Con #2 ----> | PostgreSQL
25+
| Server Service.py | -- Handler Con #2 ----> | PostgreSQL
2626
| Request / Thread #2 | | Backend #2
2727
+----------------------+ +---------------------
2828
```

doc/conf.py/source/config.rst

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ The database connection configuration supports both single and multiple database
4848
'user': 'username',
4949
'pass': 'userpass',
5050
'ssl': False,
51-
'connect_timeout': 30,
51+
'connect_timeout': 10,
5252
'connection_retry_sleep': 1,
53-
'query_timeout': 120,
53+
'query_timeout': 5000,
5454
'session_tmp_buffer': 128
5555
}
5656
}
@@ -65,23 +65,13 @@ The database connection configuration supports both single and multiple database
6565
'host': 'db1.example.com',
6666
'name': 'dbname',
6767
'user': 'username',
68-
'pass': 'userpass',
69-
'ssl': False,
70-
'connect_timeout': 30,
71-
'connection_retry_sleep': 1,
72-
'query_timeout': 120,
73-
'session_tmp_buffer': 128
68+
'pass': 'userpass'
7469
},
7570
{
7671
'host': 'db2.example.com',
7772
'name': 'dbname',
7873
'user': 'username',
79-
'pass': 'userpass',
80-
'ssl': False,
81-
'connect_timeout': 30,
82-
'connection_retry_sleep': 1,
83-
'query_timeout': 120,
84-
'session_tmp_buffer': 128
74+
'pass': 'userpass'
8575
}
8676
]
8777
}
@@ -143,33 +133,27 @@ The threading model can be configured to optimize for different deployment scena
143133
-
144134
- Database Auth Password
145135
* - ssl
146-
- bool
136+
- enum (disable|allow|prefer|require)
147137
-
148-
- x
149-
- False
150-
- Use SSL / TLS
138+
-
139+
- disable
140+
- SSL / TLS properties
151141
* - connect_timeout
152142
- int
153143
- Seconds
154-
- x
155-
- 30
144+
-
145+
- 10
156146
- Connect Timeout
157-
* - connection_retry_sleep
158-
- int
159-
- Seconds
160-
- x
161-
- 1
162-
- Sleep Between Connect Retry
163147
* - query_timeout
164148
- int
165-
- Seconds
166-
- x
167-
- 120
149+
- Milliseconds
150+
-
151+
- 5000
168152
- Query Timeout
169153
* - session_tmp_buffer
170154
- int
171-
- Kilobytes
172-
- x
155+
- Megabytes
156+
-
173157
- 128
174158
- Session Buffer Memory
175159

@@ -230,9 +214,9 @@ The following schema represents the internal Python structures. Some values (e.g
230214
'user': 'dbuser',
231215
'pass': 'dbpass',
232216
'ssl': False,
233-
'connect_timeout': 30,
217+
'connect_timeout': 10,
234218
'connection_retry_sleep': 1,
235-
'query_timeout': 120,
219+
'query_timeout': 5000,
236220
'session_tmp_buffer': 128
237221
},
238222
'groups': {
@@ -288,18 +272,12 @@ Configure multiple database endpoints for automatic load balancing and failover:
288272
'name': 'myapp',
289273
'user': 'appuser',
290274
'pass': 'securepassword',
291-
'ssl': 'require',
292-
'connect_timeout': 30,
293-
'query_timeout': 120
294275
},
295276
{
296277
'host': 'secondary-db.example.com',
297278
'name': 'myapp',
298279
'user': 'appuser',
299280
'pass': 'securepassword',
300-
'ssl': 'require',
301-
'connect_timeout': 30,
302-
'query_timeout': 120
303281
}
304282
],
305283
'groups': {

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "pgdbpool"
7-
version = "1.0"
7+
version = "1.0.1"
88
authors = [
99
{ name="Claus Prüfer", email="pruefer@webcodex.de" },
1010
]

src/pool.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ def _init_class(cls):
103103
cls._dbiter_ref = cls._dbiter()
104104

105105
db_config = cls._config['db'][0]
106+
107+
if 'query_timeout' not in db_config:
108+
db_config['query_timeout'] = 5000
109+
if 'session_tmp_buffer' not in db_config:
110+
db_config['session_tmp_buffer'] = 128
111+
106112
statement_timeout = 'statement_timeout={}'.format(db_config['query_timeout'])
107113
temp_buffers = 'temp_buffers={}MB'.format(db_config['session_tmp_buffer'])
108114

@@ -216,10 +222,12 @@ def get_connection_count(cls, connection):
216222
(group, group_id) = connection
217223
cls.logger.debug('connection get_connection_count() group_id:{}'.format(group_id))
218224
connections = cls._config['groups'][group]['connections']
225+
219226
for (conn_ref, status) in connections:
220227
cls.logger.debug('connection get_connection_count() conn_ref:{} status:{}'.format(conn_ref, status))
221228
if status == 'occupied':
222229
connection_count += 1
230+
223231
return connection_count
224232

225233
@classmethod
@@ -236,6 +244,7 @@ def set_connection_status(cls, connection, status):
236244
connection_by_id = connections[group_id]
237245
new_connection = (connection_by_id[0], status)
238246
connections[group_id] = new_connection
247+
239248
cls.logger.debug('connection set_connection_status() group_id:{} status:{} con_ref:{}'.format(
240249
group_id,
241250
status,
@@ -271,6 +280,11 @@ def connect(cls, connection):
271280

272281
cls.logger.debug('connection connect() db_config:{}'.format(db_container))
273282

283+
if 'ssl' not in db_container:
284+
db_container['ssl'] = 'disable'
285+
if 'connect_timeout' not in db_container:
286+
db_container['connect_timeout'] = 10
287+
274288
group_container['connections'][conn_id] = (
275289
psycopg2.connect(
276290
dbname = db_container['name'],
@@ -316,7 +330,7 @@ def reconnect(cls, connection):
316330
return
317331
except DBConnectionError as e:
318332
cls.logger.debug('connection reconnect() exception:{}'.format(repr(e)))
319-
time.sleep(cls._config['db']['connection_retry_sleep'])
333+
time.sleep(1)
320334

321335

322336
class Query(object):

0 commit comments

Comments
 (0)