Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
lesovsky committed May 10, 2020
2 parents 8904129 + 12127bc commit 7ee17a8
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 52 deletions.
18 changes: 5 additions & 13 deletions Makefile
@@ -1,20 +1,13 @@
PROGRAM_NAME = pgcenter
PREFIX ?= /usr
INCLUDEDIR =
LIBDIR =
SHAREDIR = ${PREFIX}/share
MANDIR = ${SHAREDIR}/man/man1

SOURCE = ${PROGRAM_NAME}.go
COMMIT=$(shell git rev-parse --short HEAD)
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
TAG=$(shell git describe --tags |cut -d- -f1)

LDFLAGS = -ldflags "-X github.com/lesovsky/pgcenter/cmd.GitTag=${TAG} \
-X github.com/lesovsky/pgcenter/cmd.GitCommit=${COMMIT} \
-X github.com/lesovsky/pgcenter/cmd.GitBranch=${BRANCH}"

DESTDIR ?=
LDFLAGS = -ldflags "-X github.com/lesovsky/pgcenter/cmd.gitTag=${TAG} \
-X github.com/lesovsky/pgcenter/cmd.gitCommit=${COMMIT} \
-X github.com/lesovsky/pgcenter/cmd.gitBranch=${BRANCH}"

.PHONY: all clean install uninstall

Expand All @@ -25,11 +18,10 @@ pgcenter:
CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} go build ${LDFLAGS} -o ${PROGRAM_NAME} ${SOURCE}

install:
mkdir -p ${DESTDIR}${PREFIX}/bin/
install -pm 755 ${PROGRAM_NAME} ${DESTDIR}${PREFIX}/bin/${PROGRAM_NAME}
install -pm 755 ${PROGRAM_NAME} /usr/bin/${PROGRAM_NAME}

clean:
rm -f ${PROGRAM_NAME}

uninstall:
rm -f ${DESTDIR}${PREFIX}/bin/${PROGRAM_NAME}
rm -f /usr/bin/${PROGRAM_NAME}
14 changes: 2 additions & 12 deletions cmd/cmd.go
Expand Up @@ -3,7 +3,6 @@
package cmd

import (
"fmt"
"github.com/lesovsky/pgcenter/cmd/config"
"github.com/lesovsky/pgcenter/cmd/profile"
"github.com/lesovsky/pgcenter/cmd/record"
Expand All @@ -12,18 +11,15 @@ import (
"github.com/spf13/cobra"
)

// Root describes the CLI command of main profram
// Root describes the CLI command of main program
var Root = &cobra.Command{
Use: ProgramName,
Use: programName,
Short: "Admin tool for PostgreSQL",
Long: "pgCenter is a command line admin tool for PostgreSQL.",
Version: "dummy", // use constants from version.go
}

func init() {
// Use this in case when you want to make something in root 'pgcenter' command
//Root.Run = runRoot

Root.PersistentFlags().BoolP("help", "?", false, "show this help and exit")

// Setup help and versions templates for main program
Expand Down Expand Up @@ -60,9 +56,3 @@ func init() {
top.CommandDefinition.SetHelpTemplate(printTopHelp())
top.CommandDefinition.SetUsageTemplate(printTopHelp())
}

// Things executed in root 'pgcenter' command.
func runRoot(cmd *cobra.Command, args []string) {
// debug purpose
fmt.Printf("%#v\n", args)
}
18 changes: 9 additions & 9 deletions cmd/help.go
Expand Up @@ -65,7 +65,7 @@ Options:
-P, --pid PID backend PID to profile to
-F, --freq FREQ profile at this frequency (min 1, max 1000)
-s, --strsize SIZE limit length of print query strings to STRSIZE chars (default 128)
-s, --strsize SIZE limit length of print query strings to STRSIZE chars (default 128)
General options:
-?, --help show this help and exit
Expand Down Expand Up @@ -138,9 +138,9 @@ Report options:
-T, --tables show pg_stat_user_tables statistics
-I, --indexes show pg_stat_user_indexes and pg_statio_user_indexes statistics
-P, --progress [X] show pg_stat_progress_* statistics, use additional selector to choose stats.
'v' - vacuum; 'c' - cluster; 'i' - create index.
'v' - vacuum; 'c' - cluster; 'i' - create index.
-X, --statements [X] show pg_stat_statements statistics, use additional selector to choose stats.
'm' - timings; 'g' - general; 'i' - io; 't' - temp files io; 'l' - local files io.
'm' - timings; 'g' - general; 'i' - io; 't' - temp files io; 'l' - local files io.
-d, --describe show statistics description, combined with one of the report options
Expand All @@ -160,35 +160,35 @@ func printMainHelp() string {
record.CommandDefinition.Short,
report.CommandDefinition.Short,
top.CommandDefinition.Short,
ProgramIssuesUrl)
programIssuesUrl)
}

func printConfigHelp() string {
return fmt.Sprintf(configHelpTemplate,
config.CommandDefinition.Long,
ProgramIssuesUrl)
programIssuesUrl)
}

func printProfileHelp() string {
return fmt.Sprintf(profileHelpTemplate,
profile.CommandDefinition.Long,
ProgramIssuesUrl)
programIssuesUrl)
}

func printTopHelp() string {
return fmt.Sprintf(topHelpTemplate,
top.CommandDefinition.Long,
ProgramIssuesUrl)
programIssuesUrl)
}

func printRecordHelp() string {
return fmt.Sprintf(recordHelpTemplate,
record.CommandDefinition.Long,
ProgramIssuesUrl)
programIssuesUrl)
}

func printReportHelp() string {
return fmt.Sprintf(reportHelpTemplate,
report.CommandDefinition.Long,
ProgramIssuesUrl)
programIssuesUrl)
}
14 changes: 8 additions & 6 deletions cmd/version.go
Expand Up @@ -7,17 +7,19 @@ import (
)

const (
// ProgramName is the name of this program
ProgramName = "pgcenter"
// ProgramIssuesUrl is the public URL for posting issues, bug reports and asking questions
ProgramIssuesUrl = "https://github.com/lesovsky/pgcenter/issues"
// programName is the name of this program
programName = "pgcenter"

// programIssuesUrl is the public URL for posting issues, bug reports and asking questions
programIssuesUrl = "https://github.com/lesovsky/pgcenter/issues"
)

var (
GitTag, GitCommit, GitBranch string
// Git variables imported at build stage
gitTag, gitCommit, gitBranch string
)

// PrintVersion prints the name and version of this program
func PrintVersion() string {
return fmt.Sprintf("%s %s %s-%s\n", ProgramName, GitTag, GitCommit, GitBranch)
return fmt.Sprintf("%s %s %s-%s\n", programName, gitTag, gitCommit, gitBranch)
}
14 changes: 11 additions & 3 deletions doc/Changelog
@@ -1,3 +1,11 @@
pgcenter (0.6.5) unstable; urgency=low
* nothing important, removed old code, small refactoring and bugfixes
* top: fix 'G' hotkey when building query report

pgcenter (0.6.4) unstable; urgency=low
pgcenter (0.6.3) unstable; urgency=low
* nothing important, just attempts to fix CI errors

pgcenter (0.6.2) unstable; urgency=low
* report: print header at the beginning of the output
* top/report: refactoring aligning
Expand All @@ -13,7 +21,7 @@ pgcenter (0.6.1) unstable; urgency=low
- record: records complete length of pg_stat_statements.query (be careful, it might produce high-volume stats file)
- record: add startup parameter for configuring truncation
- report: can use '--truncate 0', for disabling truncation only for pg_stat_statements.query (might produce an "eyes-bleeding" output)
* reworked pg_stat_statements queries:
* reworked pg_stat_statements queries:
- remove unnecessary GROUP BY, ORDER BY and aggregations
- simplify usage of regexp_replace()
- use pg_get_userbyid() instead of joining pg_roles view
Expand Down Expand Up @@ -206,7 +214,7 @@ pgcenter (0.1.3) unstable; urgency=low
* fix broken multiple connections when log_min_duration_statement issued.
* remove DEFAULT_HOST, DEFAULT_PORT; use libpq default behaviour.
* improve add_connection(): reset counters, remove unnecessary vars.

-- Alexey Lesovsky <lesovsky@gmail.com> Sun, 28 Aug 2015 14:27:07 +0500

pgcenter (0.1.2) unstable; urgency=low
Expand Down Expand Up @@ -269,5 +277,5 @@ pgcenter (0.1.2) unstable; urgency=low
* Add console switching ability.
* Add title (progname, current time), cpu usage, load average output.
* Add ncurses, libpq.

-- Alexey Lesovsky <lesovsky@gmail.com> Sun, 24 May 2015 22:37:07 +0500
1 change: 0 additions & 1 deletion go.mod
Expand Up @@ -3,7 +3,6 @@ module github.com/lesovsky/pgcenter
require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869
github.com/jmoiron/sqlx v1.2.0
github.com/jroimartin/gocui v0.4.0
github.com/lib/pq v1.0.0
github.com/mattn/go-runewidth v0.0.3 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
@@ -1,17 +1,13 @@
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4=
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag=
github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA=
github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
github.com/jroimartin/gocui v0.4.0 h1:52jnalstgmc25FmtGcWqa0tcbMEWS6RpFLsOIO+I+E8=
github.com/jroimartin/gocui v0.4.0/go.mod h1:7i7bbj99OgFHzo7kB2zPb8pXLqMBSQegY7azfqXMkyY=
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4=
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/nsf/termbox-go v0.0.0-20180819125858-b66b20ab708e h1:fvw0uluMptljaRKSU8459cJ4bmi3qUYyMs5kzpic2fY=
github.com/nsf/termbox-go v0.0.0-20180819125858-b66b20ab708e/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
Expand Down
6 changes: 3 additions & 3 deletions lib/stat/pgstat.go
Expand Up @@ -434,13 +434,13 @@ func (r *PGresult) Sort(key int, desc bool) {
// SetAlign method aligns length of values depending of the columns width
func (r *PGresult) SetAlign(widthes map[int]int, truncLimit int, dynamic bool) (err error) {
var lastColTruncLimit, lastColMaxWidth int
lastColTruncLimit = truncLimit
lastColTruncLimit = utils.Max(truncLimit, colsTruncMinLimit)
truncLimit = utils.Max(truncLimit, colsTruncMinLimit)

// no rows in result, set width using length of a column name and return with error (because not aligned using result's values)
if len(r.Result) == 0 {
for colidx, colname := range r.Cols { // walk per-column
widthes[colidx] = len(colname)
widthes[colidx] = utils.Max(len(colname), colsTruncMinLimit)
}
return fmt.Errorf("RESULT_NO_ROWS")
}
Expand All @@ -449,7 +449,7 @@ func (r *PGresult) SetAlign(widthes map[int]int, truncLimit int, dynamic bool) (
var valuelen, colnamelen int
for colidx, colname := range r.Cols { // walk per-column
for rownum := 0; rownum < len(r.Result); rownum++ { // walk through rows
valuelen = len(r.Result[rownum][colidx].String)
valuelen = utils.Max(len(r.Result[rownum][colidx].String), colsTruncMinLimit)
colnamelen = utils.Max(len(colname), colsWidthMin)

switch {
Expand Down
2 changes: 1 addition & 1 deletion top/report.go
Expand Up @@ -79,7 +79,7 @@ const (
FROM pg_stat_statements_normalized p
JOIN pg_roles a ON a.oid=p.userid
JOIN pg_database d ON d.oid=p.dbid
WHERE TRUE AND left(md5(d.datname || a.rolname || left(p.query, 128)), 10) = $1
WHERE TRUE AND left(md5(p.dbid::text || p.userid || p.queryid), 10) = $1
GROUP BY d.datname, a.rolname, query_normalized
),
totals_readable AS (
Expand Down

0 comments on commit 7ee17a8

Please sign in to comment.