Skip to content

Instantly share code, notes, and snippets.

@jwreagor
Created November 27, 2019 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwreagor/716800c936e73edf20b8fbab30986024 to your computer and use it in GitHub Desktop.
Save jwreagor/716800c936e73edf20b8fbab30986024 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"os"
"github.com/jackc/pgtype"
"github.com/jackc/pgx"
)
func main() {
conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to connection to database: %v\n", err)
os.Exit(1)
}
defer conn.Close(context.Background())
pctx := context.Background()
var n pgtype.Interval
err = conn.QueryRow(pctx, "SELECT now() - pg_last_xact_replay_timestamp() AS time_lag").Scan(&n)
if err != nil {
fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err)
os.Exit(1)
}
nn, err := n.Value()
if err != nil {
fmt.Fprintf(os.Stderr, "Value failed: %v\n", err)
os.Exit(2)
}
fmt.Printf("output: %v\n", nn)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment