Created
November 27, 2019 04:44
-
-
Save jwreagor/716800c936e73edf20b8fbab30986024 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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