pgdexter 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +2 -2
- data/lib/dexter/client.rb +5 -4
- data/lib/dexter/csv_log_parser.rb +1 -1
- data/lib/dexter/indexer.rb +12 -6
- data/lib/dexter/logging.rb +18 -3
- data/lib/dexter/processor.rb +2 -2
- data/lib/dexter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3940bf892014f2337cc5cd95c85b66f245b3725ad7ce84397c4eb4f9e3751c3c
|
4
|
+
data.tar.gz: b8fc834cda0161c8ef0b44853c14f5f608c00f373e6a95481321e45611d2d5b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 463430e69b2a1f08ca411db0a4938c7243839e78f81db72455d508ff1e9de1a752889bff8a3e42486cf4859042065b0847f0b6c0216c80c9b9a36a10cf360753
|
7
|
+
data.tar.gz: d31949fc719e863aa56672fd807141dfbeb521d2ce2525ca551109e09840115c3091e7130cc47617a6b836ff31853dbf12a1bb9fb4dea492b17cbf7c9bfd5c8e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -146,10 +146,10 @@ dexter --interval 60 # seconds
|
|
146
146
|
|
147
147
|
## Examples
|
148
148
|
|
149
|
-
Ubuntu with PostgreSQL
|
149
|
+
Ubuntu with PostgreSQL 12
|
150
150
|
|
151
151
|
```sh
|
152
|
-
tail -F -n +1 /var/log/postgresql/postgresql-
|
152
|
+
tail -F -n +1 /var/log/postgresql/postgresql-12-main.log | sudo -u postgres dexter dbname
|
153
153
|
```
|
154
154
|
|
155
155
|
Homebrew on Mac
|
data/lib/dexter/client.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
module Dexter
|
2
2
|
class Client
|
3
|
+
extend Logging
|
3
4
|
include Logging
|
4
5
|
|
5
6
|
attr_reader :arguments, :options
|
6
7
|
|
7
8
|
def self.start
|
8
9
|
Dexter::Client.new(ARGV).perform
|
9
|
-
rescue Dexter::Abort => e
|
10
|
-
abort e.message
|
10
|
+
rescue Dexter::Abort, PG::UndefinedFile => e
|
11
|
+
abort colorize(e.message.strip, :red)
|
11
12
|
end
|
12
13
|
|
13
14
|
def initialize(args)
|
@@ -78,11 +79,11 @@ module Dexter
|
|
78
79
|
|
79
80
|
# TODO don't use global var
|
80
81
|
$log_level = options[:log_level].to_s.downcase
|
81
|
-
|
82
|
+
raise Dexter::Abort, "Unknown log level" unless ["error", "info", "debug", "debug2", "debug3"].include?($log_level)
|
82
83
|
|
83
84
|
[arguments, options]
|
84
85
|
rescue Slop::Error => e
|
85
|
-
|
86
|
+
raise Dexter::Abort, e.message
|
86
87
|
end
|
87
88
|
end
|
88
89
|
end
|
data/lib/dexter/indexer.rb
CHANGED
@@ -123,9 +123,9 @@ module Dexter
|
|
123
123
|
begin
|
124
124
|
execute("CREATE EXTENSION IF NOT EXISTS hypopg")
|
125
125
|
rescue PG::UndefinedFile
|
126
|
-
|
126
|
+
raise Dexter::Abort, "Install HypoPG first: https://github.com/ankane/dexter#installation"
|
127
127
|
rescue PG::InsufficientPrivilege
|
128
|
-
|
128
|
+
raise Dexter::Abort, "Use a superuser to run: CREATE EXTENSION hypopg"
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
@@ -421,7 +421,7 @@ module Dexter
|
|
421
421
|
# print summary
|
422
422
|
if new_indexes.any?
|
423
423
|
new_indexes.each do |index|
|
424
|
-
log "Index found: #{index[:table]} (#{index[:columns].join(", ")})"
|
424
|
+
log colorize("Index found: #{index[:table]} (#{index[:columns].join(", ")})", :green)
|
425
425
|
end
|
426
426
|
else
|
427
427
|
log "No new indexes found"
|
@@ -515,7 +515,7 @@ module Dexter
|
|
515
515
|
PG::Connection.new(config)
|
516
516
|
end
|
517
517
|
rescue PG::ConnectionBad => e
|
518
|
-
|
518
|
+
raise Dexter::Abort, e.message
|
519
519
|
end
|
520
520
|
|
521
521
|
def execute(query, pretty: true)
|
@@ -527,7 +527,7 @@ module Dexter
|
|
527
527
|
# as an extra defense against SQL-injection attacks.
|
528
528
|
# https://www.postgresql.org/docs/current/static/libpq-exec.html
|
529
529
|
query = squish(query) if pretty
|
530
|
-
log "
|
530
|
+
log colorize("[sql] #{query}", :cyan) if @log_sql
|
531
531
|
|
532
532
|
@mutex.synchronize do
|
533
533
|
conn.exec_params(query, []).to_a
|
@@ -596,7 +596,13 @@ module Dexter
|
|
596
596
|
|
597
597
|
view_tables = {}
|
598
598
|
result.each do |row|
|
599
|
-
|
599
|
+
begin
|
600
|
+
view_tables[row["table_name"]] = PgQuery.parse(row["definition"]).tables
|
601
|
+
rescue PgQuery::ParseError
|
602
|
+
if @log_level.start_with?("debug")
|
603
|
+
log colorize("ERROR: Cannot parse view definition: #{row["table_name"]}", :red)
|
604
|
+
end
|
605
|
+
end
|
600
606
|
end
|
601
607
|
|
602
608
|
view_tables
|
data/lib/dexter/logging.rb
CHANGED
@@ -1,11 +1,26 @@
|
|
1
1
|
module Dexter
|
2
2
|
module Logging
|
3
|
+
COLOR_CODES = {
|
4
|
+
red: 31,
|
5
|
+
green: 32,
|
6
|
+
yellow: 33,
|
7
|
+
cyan: 36
|
8
|
+
}
|
9
|
+
|
10
|
+
def output
|
11
|
+
$stdout
|
12
|
+
end
|
13
|
+
|
3
14
|
def log(message = "")
|
4
|
-
puts
|
15
|
+
output.puts(message) unless $log_level == "error"
|
5
16
|
end
|
6
17
|
|
7
|
-
def
|
8
|
-
|
18
|
+
def colorize(message, color)
|
19
|
+
if output.tty?
|
20
|
+
"\e[#{COLOR_CODES[color]}m#{message}\e[0m"
|
21
|
+
else
|
22
|
+
message
|
23
|
+
end
|
9
24
|
end
|
10
25
|
end
|
11
26
|
end
|
data/lib/dexter/processor.rb
CHANGED
@@ -37,7 +37,7 @@ module Dexter
|
|
37
37
|
begin
|
38
38
|
process_queries
|
39
39
|
rescue PG::ServerError => e
|
40
|
-
log "ERROR: #{e.class.name}: #{e.message}"
|
40
|
+
log colorize("ERROR: #{e.class.name}: #{e.message}", :red)
|
41
41
|
end
|
42
42
|
sleep(@interval)
|
43
43
|
end
|
@@ -47,7 +47,7 @@ module Dexter
|
|
47
47
|
begin
|
48
48
|
@log_parser.perform
|
49
49
|
rescue Errno::ENOENT => e
|
50
|
-
|
50
|
+
raise Dexter::Abort, "ERROR: #{e.message}"
|
51
51
|
end
|
52
52
|
|
53
53
|
process_queries
|
data/lib/dexter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pgdexter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slop
|