pgready

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

pgready

GitHub tag (latest SemVer) Go Reference License

A simple command-line utility to check if a PostgreSQL database is ready to accept connections. This tool is particularly useful in containerized environments and deployment scripts where you need to ensure the database is available before starting your application.

Features

  • Configurable connection retry attempts
  • Adjustable retry interval
  • Supports connection string via command line flag or environment variable
  • Returns appropriate exit codes (0 for success, 1 for failure)

Installation

go install github.com/dmitrymomot/pgready@latest

Usage

Basic Usage
# Using command line flags
pgready --db-url "postgres://user:password@localhost:5432/dbname"

# Using environment variable
export DATABASE_URL="postgres://user:password@localhost:5432/dbname"
pgready
Command Line Options
  • --db-url: PostgreSQL connection string (can also be set via DATABASE_URL environment variable)
  • --retry-attempts: Number of connection retry attempts (default: 20)
  • --retry-interval: Interval between retry attempts (default: 1s)
Examples
# Custom retry attempts and interval
pgready --db-url "postgres://user:password@localhost:5432/dbname" --retry-attempts 30 --retry-interval 2s

# Wait for PostgreSQL in a Docker Compose setup
pgready --db-url "postgres://postgres:postgres@db:5432/myapp?sslmode=disable" --retry-interval 5s

# Use in a shell script
if pgready --db-url "postgres://localhost/app"; then
    echo "Database is ready"
    ./start-application
else
    echo "Database failed to become ready"
    exit 1
fi

Exit Codes

  • 0: PostgreSQL is ready for connections
  • 1: Failed to connect to PostgreSQL within the given retry attempts or invalid configuration

License

This project is licensed under the Apache 2.0 - see the LICENSE file for details.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL