pg_conn 0.26.1 → 0.26.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pg_conn/session_methods.rb +8 -6
- data/lib/pg_conn/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 419e3bd17f4343be6860d172864ad0eeaaed032ab72cc659a02afa14914cdf65
|
4
|
+
data.tar.gz: 00d673f75424491bd322cf1321cc8afbb67eba1d955a9545b4f7a0df334bc0b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e732a7523af59a16052603766aeea731d3d54a4f36fbd250f2dea33b85d1bc890af2fb7de4f8efb96d816eed2ecce390fb4510224715f78bd75a693c4243062
|
7
|
+
data.tar.gz: f1b0b073a7231a68a5e0e3b255523c50000db9d50e24596a7545d9228b84bc69056a70b4c8111f899ad6852990ac6b84dc646f2e369c7cb4fbe77f77615d65e7
|
@@ -16,14 +16,14 @@ module PgConn
|
|
16
16
|
else
|
17
17
|
conn.tuples %(
|
18
18
|
select datname, usename
|
19
|
-
from pg_stat_activity
|
19
|
+
from pg_stat_activity
|
20
20
|
where datname is not null and usename is not null
|
21
21
|
)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
# Return true if the given database accepts connections
|
26
|
-
def enabled?(database)
|
26
|
+
def enabled?(database)
|
27
27
|
!database.nil? or raise ArgumentError
|
28
28
|
conn.value "select datallowconn from pg_catalog.pg_database where datname = '#{database}'"
|
29
29
|
end
|
@@ -50,19 +50,21 @@ module PgConn
|
|
50
50
|
# multiple sessions (is this ever relevant?)
|
51
51
|
#
|
52
52
|
def terminate(database, *users)
|
53
|
+
users = Array(users).flatten
|
53
54
|
!database.nil? or raise ArgumentError
|
54
55
|
enabled = self.enabled?(database)
|
55
56
|
|
56
57
|
case users
|
57
|
-
when [];
|
58
|
+
when [];
|
58
59
|
return
|
59
60
|
when [nil]
|
60
61
|
self.disable(database) if enabled
|
61
62
|
users = self.list(database)
|
62
|
-
else
|
63
|
+
else
|
63
64
|
users = Array(users).flatten
|
64
65
|
end
|
65
66
|
pids = self.pids(database, users)
|
67
|
+
|
66
68
|
if !pids.empty?
|
67
69
|
pids_sql = pids.map { |pid| "(#{pid})" }.join(", ")
|
68
70
|
conn.execute "select pg_terminate_backend(pid) from ( values #{pids_sql} ) as x(pid)"
|
@@ -71,7 +73,7 @@ module PgConn
|
|
71
73
|
end
|
72
74
|
|
73
75
|
# Run block without any connected users. Existing sessions are terminated
|
74
|
-
def exclusive(database, &block)
|
76
|
+
def exclusive(database, &block)
|
75
77
|
!database.nil? or raise ArgumentError
|
76
78
|
begin
|
77
79
|
disable(database)
|
@@ -85,7 +87,7 @@ module PgConn
|
|
85
87
|
# Return true if session triggers are enabled. Triggers are enabled by
|
86
88
|
# default by Postgres
|
87
89
|
def triggers?() conn.value "select current_setting('session_replication_role') <> 'replica'" end
|
88
|
-
|
90
|
+
|
89
91
|
# Enable session triggers
|
90
92
|
def enable_triggers()
|
91
93
|
conn.execute "set session session_replication_role = DEFAULT"
|
data/lib/pg_conn/version.rb
CHANGED