ruby-pg-extras 4.9.0 → 4.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28817e57f333673450b7717d6477212f620e7b9ff2d47e64602a575913b00e57
4
- data.tar.gz: 564ff926e6ef12499ca3f4e9572f59ebe364129ff354079f32d2c88269c83c44
3
+ metadata.gz: 6fa76a798c41ebe051c5df9fcabc34e271b9d045c42220fae3968f5de88328e8
4
+ data.tar.gz: b3aa49df175c069ad6ec077db5315806e71b2bce9a1690cf9b4062fae37169b3
5
5
  SHA512:
6
- metadata.gz: a604904f5d6382ccf5b6c94afcdb3f25b55f214981921d0044ca72a89bde0f12b7089ae7d3dccd1b616a25e1c20e0178eed4fd4db8c1cd6359bd2a0bef6d57db
7
- data.tar.gz: 06cabd33eaa90d5d0db7ad5fc5153433c50207d97e26800b1290bf81e704ac2ff9fe1325843200fb3ddd13b8b3383d2259c38dcb1630d274294ae93bd294db4b
6
+ metadata.gz: 5b5518dc8bb7739708768ab0ebb19ed885c30aa1a61083228bf2bfa2e8668d1e29b61e0ed09618980dfacef8daf8d8514ff9862ed9c0f3babac0aa67a1a5ff19
7
+ data.tar.gz: cf4a2bce35f343245b0a594f480249597bfe69b82e421923d73619cdfac5dad5199770e7038a1e5561701cfc2a644bb931b7ecf0a6b3215c509665e4ea7e6d30
data/README.md CHANGED
@@ -591,6 +591,16 @@ RubyPgExtras.kill_all
591
591
 
592
592
  This commands kills all the currently active connections to the database. It can be useful as a last resort when your database is stuck in a deadlock.
593
593
 
594
+ ### `kill_by_pid`
595
+
596
+ ```ruby
597
+
598
+ RubyPgExtras.kill_by_pid(args: { pid: 4657 })
599
+
600
+ ```
601
+
602
+ This commands kills currently active database connection by its `pid` number. You can use `connections` method to find the correct `pid` values.
603
+
594
604
  ### `pg_stat_statements_reset`
595
605
 
596
606
  ```ruby
@@ -625,6 +635,24 @@ RubyPgExtras.extensions
625
635
 
626
636
  This command lists all the currently installed and available PostgreSQL extensions.
627
637
 
638
+ ### `connections`
639
+
640
+ ```ruby
641
+
642
+ RubyPgExtras.connections
643
+
644
+ +-----------------------------------------------------+
645
+ | Returns the list of all active database connections |
646
+ +-----------------+----------------+------------------+
647
+ | username | client_address | application_name |
648
+ +-----------------+----------------+------------------+
649
+ | postgres | 172.19.0.1/32 | psql |
650
+ | postgres | 172.19.0.1/32 | irb |
651
+ +-----------------+----------------+------------------+
652
+ ```
653
+
654
+ This command returns the list of all active database connections.
655
+
628
656
  ### `mandelbrot`
629
657
 
630
658
  ```ruby
@@ -22,9 +22,9 @@ module RubyPgExtras
22
22
  long_running_queries mandelbrot outliers
23
23
  records_rank seq_scans table_index_scans table_indexes_size
24
24
  table_size total_index_size total_table_size
25
- unused_indexes duplicate_indexes vacuum_stats kill_all
25
+ unused_indexes duplicate_indexes vacuum_stats kill_all kill_by_pid
26
26
  pg_stat_statements_reset buffercache_stats
27
- buffercache_usage ssl_used
27
+ buffercache_usage ssl_used connections
28
28
  )
29
29
 
30
30
  DEFAULT_ARGS = Hash.new({}).merge({
@@ -45,7 +45,8 @@ module RubyPgExtras
45
45
  seq_scans: { schema: "public" },
46
46
  table_index_scans: { schema: "public" },
47
47
  records_rank: { schema: "public" },
48
- tables: { schema: "public" }
48
+ tables: { schema: "public" },
49
+ kill_by_pid: { pid: 0 }
49
50
  })
50
51
 
51
52
  QUERIES.each do |query_name|
@@ -0,0 +1,3 @@
1
+ /* Returns the list of all active database connections */
2
+
3
+ SELECT usename as username, pid, client_addr::text as client_address, application_name FROM pg_stat_activity WHERE datname = current_database();
@@ -0,0 +1,6 @@
1
+ /* Kill database connection by its pid */
2
+
3
+ SELECT pg_terminate_backend(pid) FROM pg_stat_activity
4
+ WHERE pid = %{pid}
5
+ AND query <> '<insufficient privilege>'
6
+ AND datname = current_database();
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyPgExtras
4
- VERSION = "4.9.0"
4
+ VERSION = "4.11.0"
5
5
  end
data/spec/smoke_spec.rb CHANGED
@@ -13,7 +13,7 @@ describe RubyPgExtras do
13
13
  end
14
14
  end
15
15
 
16
- RubyPgExtras::QUERIES.each do |query_name|
16
+ RubyPgExtras::QUERIES.reject { |q| q == :kill_all }.each do |query_name|
17
17
  it "#{query_name} query can be executed" do
18
18
  expect do
19
19
  RubyPgExtras.run_query(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-pg-extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.9.0
4
+ version: 4.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-18 00:00:00.000000000 Z
11
+ date: 2022-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -96,6 +96,7 @@ files:
96
96
  - lib/ruby_pg_extras/queries/cache_hit.sql
97
97
  - lib/ruby_pg_extras/queries/calls.sql
98
98
  - lib/ruby_pg_extras/queries/calls_legacy.sql
99
+ - lib/ruby_pg_extras/queries/connections.sql
99
100
  - lib/ruby_pg_extras/queries/db_settings.sql
100
101
  - lib/ruby_pg_extras/queries/duplicate_indexes.sql
101
102
  - lib/ruby_pg_extras/queries/extensions.sql
@@ -105,6 +106,7 @@ files:
105
106
  - lib/ruby_pg_extras/queries/index_usage.sql
106
107
  - lib/ruby_pg_extras/queries/indexes.sql
107
108
  - lib/ruby_pg_extras/queries/kill_all.sql
109
+ - lib/ruby_pg_extras/queries/kill_by_pid.sql
108
110
  - lib/ruby_pg_extras/queries/locks.sql
109
111
  - lib/ruby_pg_extras/queries/long_running_queries.sql
110
112
  - lib/ruby_pg_extras/queries/mandelbrot.sql