https://github.com/tkuchiki/go-pg-slowlog
A Go library for parsing and collecting the slowlog of PostgreSQL.
https://github.com/tkuchiki/go-pg-slowlog
Last synced: 2 months ago
JSON representation
A Go library for parsing and collecting the slowlog of PostgreSQL.
- Host: GitHub
- URL: https://github.com/tkuchiki/go-pg-slowlog
- Owner: tkuchiki
- License: apache-2.0
- Created: 2023-10-09T05:27:50.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-24T15:49:02.000Z (over 1 year ago)
- Last Synced: 2025-01-25T09:11:08.119Z (4 months ago)
- Language: Go
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-pg-slowlog
A Go library for parsing and collecting the slowlog of PostgreSQL.
## Usage
```go
package mainimport (
"fmt"
"log"
"os""github.com/tkuchiki/go-pg-slowlog/parser"
)func main() {
f, err := os.Open("/path/to/postgresql-xxx.log")
if err != nil {
log.Fatal(err)
}
defer f.Close()logLinePrefix := "%m [%p]"
slowLogParser, err := parser.NewPGSlowLogParser(f, logLinePrefix)
if err != nil {
log.Fatal(err)
}defer slowLogParser.Stop()
go slowLogParser.Start()for logEntry := range slowLogParser.LogEntryChan() {
fmt.Println(logEntry.Duration, logEntry.Statement)
}
// example output
// 1.009444s SELECT * FROM singers
// 1.002257s SELECT * FROM albums
}
```