pg-commands
pg-commands copied to clipboard
panic: command not found: pg_dump
Hi, I have a problem. Console error this like following panic: command not found: pg_dump
What is problem?
go version go1.19.5 windows/amd64
CODE
package main
import ( "fmt" pg "github.com/habx/pg-commands" "os" )
func main() {
fmt.Println("backupp")
dump, err := pg.NewDump(&pg.Postgres{
Host: "localhost",
Port: 5432,
DB: "dev_example",
Username: "example",
Password: "example",
})
if err != nil {
panic(err)
}
dump.EnableVerbose()
dumpExec := dump.Exec(pg.ExecOptions{StreamPrint: true, StreamDestination: os.Stdout})
if dumpExec.Error != nil {
fmt.Println(dumpExec.Error.Err)
fmt.Println(dumpExec.Output)
} else {
fmt.Println("Dump success")
fmt.Println(dumpExec.Output)
}
restore, err := pg.NewRestore(&pg.Postgres{
Host: "example",
Port: 5432,
DB: "dev_example_new",
Username: "example",
Password: "example",
})
if err != nil {
panic(err)
}
restoreExec := restore.Exec(dumpExec.File, pg.ExecOptions{StreamPrint: false})
if restoreExec.Error != nil {
fmt.Println(restoreExec.Error.Err)
fmt.Println(restoreExec.Output)
} else {
fmt.Println("Restore success")
fmt.Println(restoreExec.Output)
}
}
hi @mertcakmak2
You must have pg_dump
/ pg_restore
(binary: https://docs.postgresql.fr/15/app-pgdump.html) installed in your system
https://github.com/habx/pg-commands/blob/80902540e1f24a4d8d5a4651d57bec4922cac683/pg_dump.go#L12-L13
If its not work, I can modify my code for add new methods for setup execution path.
I'm also having this issue. Doesn't seem like there's a way of telling the lib where the executable is.
For reference I'm on Mac and have tried running this with the executable where it was installed by postgres as well as moving a copy to the project directory and nothing works.
It would be really helpful to be able to set the path as an argument to NewDump
Never mind, I see now that PGDumpCmd is a public variable and can be set from my project
yes ! you can update exec path