Issue while trying to connect AWS RDS service for postgres database using backend golang

161 views Asked by At

I tried to connect to the postgres database in AWS RDS service and it's returning error while pinging. I checked pinging the database via cli and it's responding good but it throws error while it's through the program.

I'm using the package "github.com/go-pg/pg/v10". I check pinging the database through cli from the web server and it's responding but when i tried through program and it's returning error

ERROR" FATAL #28000 no pg_hba.conf entry for host "103.4..", user "postgres", database "postgres", no encryption goroutine 1"

CONNECTION SNIPPET


func (dbw *Wrapper) Connect(user string, password string, addr string, databaseName string) error {
    opts, err := generateOptions(user, password, addr, databaseName)
    if err != nil {
        return err
    }

    dbw.db = pg.Connect(opts)
    if dbw.db == nil {
        return errors.New("failed to connect to the database")
    }

    err = dbw.PingDataBase()
    if err != nil {
        return err
    }
    return nil
}


func (dbw *Wrapper) PingDataBase() error {
    return dbw.db.Ping(context.Background())
}


func generateOptions(user string, password string, addr string, databaseName string) (*pg.Options, error) {
    if user != "" && password != "" && addr != "" && databaseName != "" {
        return &pg.Options{
            User:       user,
            Password:   password,
            Addr:       addr,
            Database:   databaseName,
            MaxRetries: 3,
            PoolSize:   40,
        }, nil
    }
    return nil, errors.New("options for database connection failed")
}
0

There are 0 answers