MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / EnableInPostgreSQL

Function EnableInPostgreSQL

internal/pgaudit/postgres.go:33–51  ·  view source on GitHub ↗

When the pgAudit shared library is not loaded, the extension cannot be installed. The "CREATE EXTENSION" command fails with an error, "pgaudit must be loaded…". When the pgAudit shared library is loaded but the extension is not installed, AUDIT messages are logged according to the various levels an

(ctx context.Context, exec postgres.Executor)

Source from the content-addressed store, hash-verified

31
32// EnableInPostgreSQL installs pgAudit triggers into every database.
33func EnableInPostgreSQL(ctx context.Context, exec postgres.Executor) error {
34 log := logging.FromContext(ctx)
35
36 stdout, stderr, err := exec.ExecInAllDatabases(ctx,
37 // Quiet the NOTICE from IF EXISTS, and install the pgAudit event triggers.
38 // Use the default setting for "synchronous_commit".
39 // - https://www.postgresql.org/docs/current/runtime-config-client.html
40 // - https://www.postgresql.org/docs/current/runtime-config-wal.html
41 // - https://github.com/pgaudit/pgaudit#settings
42 `SET client_min_messages = WARNING; CREATE EXTENSION IF NOT EXISTS pgaudit;`,
43 map[string]string{
44 "ON_ERROR_STOP": "on", // Abort when any one command fails.
45 "QUIET": "on", // Do not print successful commands to stdout.
46 })
47
48 log.V(1).Info("enabled pgAudit", "stdout", stdout, "stderr", stderr)
49
50 return err
51}
52
53// PostgreSQLParameters sets the parameters required by pgAudit.
54func PostgreSQLParameters(outParameters *postgres.Parameters) {

Callers 2

TestEnableInPostgreSQLFunction · 0.70

Calls 3

FromContextFunction · 0.92
ExecInAllDatabasesMethod · 0.80
InfoMethod · 0.80

Tested by 1

TestEnableInPostgreSQLFunction · 0.56