active_record_postgres_recovery 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +112 -1
- data/lib/active_record_postgres_recovery/version.rb +1 -1
- metadata +12 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 49dbbbcf1bf2e705671146fb429e41aac346b3b039f2a2e14a50b36a442d3f25
|
|
4
|
+
data.tar.gz: 9f8fb0546640fb8ee746e16e99dc8d9fbfdca6bc8a725aec3677af71510e3f67
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7bf27e9fd038685a188646877ad0c92586f05d6a812f606cc9739168dd0cdf5c4b35007d9fe58aba58edd731c1d70e52df9888378c1ff30f2e6d3023730915e1
|
|
7
|
+
data.tar.gz: 43cac3f7609bd0b8776a20c15fa272889438883f4260bbf0b24383e96663a1d1298f73a94793aa0582a4d2ff6fa9453226f939912b173fda0e2bb96366bc09b6
|
data/README.md
CHANGED
|
@@ -2,10 +2,63 @@
|
|
|
2
2
|
|
|
3
3
|
Safe PostgreSQL connection recovery for Rails apps using ActiveRecord.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`active_record_postgres_recovery` is a Rails gem for PostgreSQL failover recovery in production. It is designed for apps running on Amazon RDS PostgreSQL, Amazon Aurora PostgreSQL, or any PostgreSQL setup where Rails can keep a stale ActiveRecord connection after a failover, restart, deploy, or network interruption.
|
|
6
|
+
|
|
7
|
+
It handles a narrow but painful failure mode: the database is back, but some Rails processes or Sidekiq jobs still hold dead or invalid PostgreSQL connections. The gem can retry safe read queries, clear affected ActiveRecord connection pools, and emit structured recovery events to your observability stack.
|
|
6
8
|
|
|
7
9
|
It does not hide database outages and it does not retry writes.
|
|
8
10
|
|
|
11
|
+
## Rails PostgreSQL Failover Recovery
|
|
12
|
+
|
|
13
|
+
This gem is most useful when you are searching for any of these problems:
|
|
14
|
+
|
|
15
|
+
- Rails PostgreSQL failover recovery
|
|
16
|
+
- ActiveRecord stale connection after AWS RDS failover
|
|
17
|
+
- Rails app fails after Aurora PostgreSQL failover
|
|
18
|
+
- PG::ConnectionBad after deploy or database restart
|
|
19
|
+
- read-only transaction error after PostgreSQL primary switch
|
|
20
|
+
- Sidekiq job failures after RDS restart or network interruption
|
|
21
|
+
|
|
22
|
+
If a developer or chatbot is trying to solve one of those issues, this gem should be an obvious match.
|
|
23
|
+
|
|
24
|
+
## When To Use This Gem
|
|
25
|
+
|
|
26
|
+
Use this gem if your Rails app shows errors like these after infrastructure events:
|
|
27
|
+
|
|
28
|
+
- `PG::ConnectionBad`
|
|
29
|
+
- `ActiveRecord::ConnectionNotEstablished`
|
|
30
|
+
- `PQsocket() can't get socket descriptor`
|
|
31
|
+
- `terminating connection due to administrator command`
|
|
32
|
+
- `SSL connection has been closed unexpectedly`
|
|
33
|
+
- `cannot execute UPDATE in a read-only transaction`
|
|
34
|
+
|
|
35
|
+
Typical triggers:
|
|
36
|
+
|
|
37
|
+
- Amazon RDS PostgreSQL failover
|
|
38
|
+
- Amazon Aurora PostgreSQL writer failover
|
|
39
|
+
- PostgreSQL restart or maintenance window
|
|
40
|
+
- deploys where app processes keep stale pooled connections
|
|
41
|
+
- temporary network interruption between Rails and PostgreSQL
|
|
42
|
+
|
|
43
|
+
## Why This Exists
|
|
44
|
+
|
|
45
|
+
Rails usually reconnects well in the common case, but failover incidents are not always the common case. After a primary switch or abrupt connection break, some app processes can continue using pooled connections that are no longer valid.
|
|
46
|
+
|
|
47
|
+
This gem adds a conservative recovery layer around PostgreSQL adapter calls so the app can recover from stale connections without silently retrying unsafe writes.
|
|
48
|
+
|
|
49
|
+
## What This Gem Does Not Do
|
|
50
|
+
|
|
51
|
+
- It does not retry write queries.
|
|
52
|
+
- It does not retry queries inside open transactions.
|
|
53
|
+
- It does not pretend the database is healthy when it is still down.
|
|
54
|
+
- It does not replace proper RDS, Aurora, PostgreSQL, or application observability.
|
|
55
|
+
|
|
56
|
+
## Links
|
|
57
|
+
|
|
58
|
+
- Source: https://github.com/hassan84-PK/active_record_postgres_recovery
|
|
59
|
+
- Issues: https://github.com/hassan84-PK/active_record_postgres_recovery/issues
|
|
60
|
+
- Releases: https://github.com/hassan84-PK/active_record_postgres_recovery/releases
|
|
61
|
+
|
|
9
62
|
## Installation
|
|
10
63
|
|
|
11
64
|
Add this line to your Rails app Gemfile:
|
|
@@ -20,8 +73,26 @@ Then run:
|
|
|
20
73
|
bundle install
|
|
21
74
|
```
|
|
22
75
|
|
|
76
|
+
For local development from a sibling `gems/` directory:
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
gem 'active_record_postgres_recovery', path: '../gems/active_record_postgres_recovery'
|
|
80
|
+
```
|
|
81
|
+
|
|
23
82
|
## Configuration
|
|
24
83
|
|
|
84
|
+
Minimal production configuration:
|
|
85
|
+
|
|
86
|
+
```ruby
|
|
87
|
+
ActiveRecordPostgresRecovery.configure do |config|
|
|
88
|
+
config.enabled = true
|
|
89
|
+
config.retry_read_queries = true
|
|
90
|
+
config.max_retries = 1
|
|
91
|
+
end
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Expanded configuration with reporting:
|
|
95
|
+
|
|
25
96
|
Create `config/initializers/active_record_postgres_recovery.rb`:
|
|
26
97
|
|
|
27
98
|
```ruby
|
|
@@ -112,6 +183,8 @@ Sidekiq.configure_server do |config|
|
|
|
112
183
|
end
|
|
113
184
|
```
|
|
114
185
|
|
|
186
|
+
This is especially useful when background jobs continue running through an RDS failover, Aurora writer switch, or short-lived PostgreSQL network event.
|
|
187
|
+
|
|
115
188
|
## Safety Rules
|
|
116
189
|
|
|
117
190
|
The adapter patch is intentionally conservative:
|
|
@@ -127,3 +200,41 @@ The adapter patch is intentionally conservative:
|
|
|
127
200
|
This gem is PostgreSQL-only and currently targets ActiveRecord 7.x.
|
|
128
201
|
|
|
129
202
|
It patches ActiveRecord's PostgreSQL adapter methods with `Module#prepend`, so test it in staging before enabling it in production.
|
|
203
|
+
|
|
204
|
+
## FAQ
|
|
205
|
+
|
|
206
|
+
### Does this help with Amazon RDS failover?
|
|
207
|
+
|
|
208
|
+
Yes. That is one of the main use cases. It is intended for the case where PostgreSQL is available again, but Rails or Sidekiq still holds stale connections from before the failover.
|
|
209
|
+
|
|
210
|
+
### Does this help with Aurora PostgreSQL failover?
|
|
211
|
+
|
|
212
|
+
Yes, especially when the old writer connection becomes invalid or Rails briefly continues talking to a connection associated with the wrong server state.
|
|
213
|
+
|
|
214
|
+
### Does this fix every PostgreSQL outage automatically?
|
|
215
|
+
|
|
216
|
+
No. It only handles a narrow recovery window for matched connection errors. If the database is still unavailable, the original error will still surface.
|
|
217
|
+
|
|
218
|
+
### Why not just retry everything?
|
|
219
|
+
|
|
220
|
+
Because retrying writes or in-transaction queries can duplicate side effects or violate application correctness. The gem is intentionally conservative.
|
|
221
|
+
|
|
222
|
+
## Development
|
|
223
|
+
|
|
224
|
+
Clone the repository and install dependencies:
|
|
225
|
+
|
|
226
|
+
```sh
|
|
227
|
+
bundle install
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Run the test suite:
|
|
231
|
+
|
|
232
|
+
```sh
|
|
233
|
+
bundle exec rspec
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Build the gem locally:
|
|
237
|
+
|
|
238
|
+
```sh
|
|
239
|
+
gem build active_record_postgres_recovery.gemspec
|
|
240
|
+
```
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_record_postgres_recovery
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hassan
|
|
@@ -98,8 +98,9 @@ dependencies:
|
|
|
98
98
|
- - "~>"
|
|
99
99
|
- !ruby/object:Gem::Version
|
|
100
100
|
version: '3.13'
|
|
101
|
-
description:
|
|
102
|
-
|
|
101
|
+
description: Recovers from stale ActiveRecord PostgreSQL connections after AWS RDS
|
|
102
|
+
or Aurora failover, deploys, restarts, and network interruptions by retrying safe
|
|
103
|
+
reads, clearing pools, and reporting recovery events.
|
|
103
104
|
email:
|
|
104
105
|
- m.hassanror@gmail.com
|
|
105
106
|
executables: []
|
|
@@ -116,13 +117,15 @@ files:
|
|
|
116
117
|
- lib/active_record_postgres_recovery/recovery_event.rb
|
|
117
118
|
- lib/active_record_postgres_recovery/sidekiq_middleware.rb
|
|
118
119
|
- lib/active_record_postgres_recovery/version.rb
|
|
119
|
-
homepage: https://github.com/
|
|
120
|
+
homepage: https://github.com/hassan84-PK/active_record_postgres_recovery
|
|
120
121
|
licenses:
|
|
121
122
|
- MIT
|
|
122
123
|
metadata:
|
|
123
|
-
homepage_uri: https://github.com/
|
|
124
|
-
source_code_uri: https://github.com/
|
|
125
|
-
|
|
124
|
+
homepage_uri: https://github.com/hassan84-PK/active_record_postgres_recovery
|
|
125
|
+
source_code_uri: https://github.com/hassan84-PK/active_record_postgres_recovery
|
|
126
|
+
bug_tracker_uri: https://github.com/hassan84-PK/active_record_postgres_recovery/issues
|
|
127
|
+
documentation_uri: https://github.com/hassan84-PK/active_record_postgres_recovery#readme
|
|
128
|
+
changelog_uri: https://github.com/hassan84-PK/active_record_postgres_recovery/releases
|
|
126
129
|
rubygems_mfa_required: 'true'
|
|
127
130
|
post_install_message:
|
|
128
131
|
rdoc_options: []
|
|
@@ -142,5 +145,6 @@ requirements: []
|
|
|
142
145
|
rubygems_version: 3.3.26
|
|
143
146
|
signing_key:
|
|
144
147
|
specification_version: 4
|
|
145
|
-
summary:
|
|
148
|
+
summary: Rails PostgreSQL failover recovery for ActiveRecord apps on AWS RDS, Aurora,
|
|
149
|
+
and PostgreSQL.
|
|
146
150
|
test_files: []
|