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)
| 31 | |
| 32 | // EnableInPostgreSQL installs pgAudit triggers into every database. |
| 33 | func 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. |
| 54 | func PostgreSQLParameters(outParameters *postgres.Parameters) { |