MCPcopy Index your code
hub / github.com/coder/coder / PGDump

Function PGDump

coderd/database/dbtestutil/db.go:210–242  ·  view source on GitHub ↗

PGDump runs pg_dump against dbURL and returns the output. It is used by DumpOnFailure().

(dbURL string)

Source from the content-addressed store, hash-verified

208// PGDump runs pg_dump against dbURL and returns the output.
209// It is used by DumpOnFailure().
210func PGDump(dbURL string) ([]byte, error) {
211 if _, err := exec.LookPath("pg_dump"); err != nil {
212 return nil, xerrors.Errorf("could not find pg_dump in path: %w", err)
213 }
214 cmdArgs := []string{
215 "pg_dump",
216 dbURL,
217 "--data-only",
218 "--column-inserts",
219 "--no-comments",
220 "--no-privileges",
221 "--no-publication",
222 "--no-security-labels",
223 "--no-subscriptions",
224 "--no-tablespaces",
225 // "--no-unlogged-table-data", // some tables are unlogged and may contain data of interest
226 "--no-owner",
227 "--exclude-table=schema_migrations",
228 }
229 cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...) // nolint:gosec
230 cmd.Env = []string{
231 // "PGTZ=UTC", // This is probably not going to be useful if tz has been changed.
232 "PGCLIENTENCODING=UTF8",
233 "PGDATABASE=", // we should always specify the database name in the connection string
234 }
235 var stdout, stderr bytes.Buffer
236 cmd.Stdout = &stdout
237 cmd.Stderr = &stderr
238 if err := cmd.Run(); err != nil {
239 return nil, xerrors.Errorf("exec pg_dump: %w\n%s", err, stderr.String())
240 }
241 return stdout.Bytes(), nil
242}
243
244const minimumPostgreSQLVersion = 13
245

Callers 1

DumpOnFailureFunction · 0.85

Calls 5

CommandMethod · 0.80
RunMethod · 0.65
ErrorfMethod · 0.45
StringMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected