🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Technology & Design › Data Management / Database Administration › PostgreSQL Administration › Lesson 2
TEC-DATA86-03 · Lesson 2 · 10 clock hours · theory

Core Configuration: postgresql.conf and pg_hba.conf

Objective. Students adjust key server parameters in postgresql.conf and write client authentication rules in pg_hba.conf, explaining the effect of each change.

⚠ Pending professional review

This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.

VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.

Core Configuration: postgresql.conf and pg_hba.conf

Why Configuration Files Matter

A freshly installed PostgreSQL server uses conservative default settings designed to run on modest hardware. In a production environment those defaults rarely match real workloads. Two files control the vast majority of server behavior: postgresql.conf sets performance, logging, and replication parameters; pg_hba.conf controls who may connect, from where, and how they must authenticate. Mastering both files is a foundational DBA skill tested by the EnterpriseDB PostgreSQL CE exam and expected by every employer who runs PostgreSQL.

Always keep a timestamped backup of both files before editing. A syntax error in either file can prevent the server from starting or accepting connections, which constitutes a production outage.

---

postgresql.conf — Server Configuration

postgresql.conf is a plain-text file located in the data directory (often `/etc/postgresql/<version>/main/` on Debian-based systems or `$PGDATA` on others). Parameters follow the format:

```

parameter_name = value # optional comment

```

Lines beginning with `#` are comments. The server reads this file at startup; many parameters can also be reloaded without a full restart using `pg_ctl reload` or the SQL command `SELECT pg_reload_conf();`. A smaller set of parameters (such as `max_connections`) require a full service restart because they affect shared-memory allocation.

Ten commonly tuned parameters:

| Parameter | What it controls | Reload or restart? |

|---|---|---|

| `shared_buffers` | Size of the shared memory buffer pool | Restart |

| `work_mem` | Memory per sort/hash operation per query node | Reload |

| `maintenance_work_mem` | Memory for VACUUM, CREATE INDEX, etc. | Reload |

| `max_connections` | Maximum simultaneous client connections | Restart |

| `effective_cache_size` | Planner estimate of OS cache available | Reload |

| `wal_level` | Amount of information written to WAL | Restart |

| `checkpoint_completion_target` | Fraction of checkpoint interval for writes | Reload |

| `logging_collector` | Enable file-based log capture | Restart |

| `log_min_duration_statement` | Log queries exceeding this duration (ms) | Reload |

| `max_wal_size` | Maximum WAL size before forced checkpoint | Reload |

shared_buffers is the single most impactful parameter. The PostgreSQL community recommends starting at roughly 25% of total RAM as a baseline, then tuning based on observed performance. On a server with 64 GB RAM that gives 16 GB. PostgreSQL also relies on the operating system's file-system cache, so allocating more than ~40% of RAM to shared_buffers is generally counterproductive.

work_mem is per sort or hash operation per query node, and a single complex query can allocate it multiple times. Set it conservatively: `Total RAM × a small fraction ÷ max_connections` is a useful starting heuristic. Too high a value with many concurrent users causes out-of-memory conditions.

After editing, confirm active values with `SHOW parameter_name;` or query `pg_settings`:

```sql

SELECT name, setting, unit FROM pg_settings

WHERE name IN ('shared_buffers','work_mem','max_connections');

```

---

pg_hba.conf — Client Authentication

pg_hba.conf (Host-Based Authentication) is read top-to-bottom; the first matching rule wins. Each rule is one line with five space-separated fields:

```

TYPE DATABASE USER ADDRESS METHOD [options]

```

TYPE values:

Common authentication methods:

| Method | Description |

|---|---|

| `trust` | No password; accept unconditionally. Use only on loopback for tightly controlled setups. |

| `reject` | Always deny. Useful as an explicit block rule. |

| `ident` | Map OS username to PostgreSQL username via the ident protocol (local/host). |

| `peer` | Check OS username of the connecting process (local connections only). |

| `md5` | MD5-hashed password challenge. Widely supported; weaker than scram. |

| `scram-sha-256` | SCRAM-SHA-256 challenge-response. Current recommended method for password authentication. |

| `ldap` | Delegate authentication to an LDAP server. |

| `cert` | Require a valid client SSL certificate. |

A safe rule ordering for a typical production server places `reject` rules for sensitive databases near the top, followed by specific user/CIDR rules, and ends with a narrow default.

Example rules:

```

local all postgres peer

host appdb appuser 192.168.10.0/24 scram-sha-256

host legacydb legacyuser 10.0.5.50/32 md5

```

After editing pg_hba.conf, reload (no restart needed): `SELECT pg_reload_conf();`

---

Safety and Best Practices

Key terms8

postgresql.confThe primary server configuration file for PostgreSQL, containing parameters that control memory, connections, WAL behavior, logging, and more.
pg_hba.confHost-Based Authentication configuration file; each line defines a rule specifying which users may connect to which databases from which hosts using which authentication method.
shared_buffersA postgresql.conf parameter that sets the amount of memory PostgreSQL allocates for its shared buffer pool; a common starting point is 25% of total system RAM.
work_memMemory allocated per sort or hash operation per query execution node; applies multiple times within a single complex query, so it must be sized carefully relative to max_connections.
scram-sha-256The current recommended pg_hba.conf password authentication method, using SCRAM-SHA-256 challenge-response to avoid sending passwords over the network.
wal_levelA postgresql.conf parameter controlling how much information is written to the Write-Ahead Log; options include minimal, replica, and logical, with higher levels enabling replication and logical decoding.
pg_reload_conf()A PostgreSQL SQL function that signals the server to re-read configuration files without a full restart; effective for parameters that support reload.
CIDR notationA compact way to specify an IP address range in pg_hba.conf (e.g., 192.168.1.0/24 covers all addresses from 192.168.1.0 to 192.168.1.255).

Worked examples4

1. A production server has 64 GB of RAM. Calculate the recommended starting value for shared_buffers using the 25% community guideline, and express it in megabytes.
  1. Convert total RAM to megabytes: 64 GB × 1024 MB/GB = 65,536 MB
  2. Apply the 25% guideline: 65,536 MB × 0.25 = 16,384 MB
  3. Express in PostgreSQL notation: shared_buffers = 16384MB (or equivalently 16GB)
Answer: shared_buffers = 16384MB (16 GB)
2. On the same 64 GB server with max_connections = 200, estimate a conservative work_mem value using the heuristic: allocate 5% of RAM to the total work_mem budget, then divide by max_connections. Express the result in MB.
  1. Calculate 5% of total RAM in MB: 65,536 MB × 0.05 = 3,276.8 MB
  2. Divide by max_connections: 3,276.8 MB ÷ 200 = 16.384 MB
  3. Round down to a clean value safe for production: work_mem = 16MB
Answer: work_mem = 16MB (a conservative starting point; tune upward only after monitoring actual query memory usage)
3. Write a pg_hba.conf rule that allows the user 'analyst' to connect to the database 'reports' from any host in the subnet 10.10.20.0/24 using scram-sha-256 authentication.
  1. Identify the TYPE: TCP/IP connection, so use 'host'
  2. Fill in DATABASE: reports
  3. Fill in USER: analyst
  4. Fill in ADDRESS: 10.10.20.0/24
  5. Fill in METHOD: scram-sha-256
  6. Assemble the line: host reports analyst 10.10.20.0/24 scram-sha-256
Answer: host reports analyst 10.10.20.0/24 scram-sha-256
4. After editing postgresql.conf to set work_mem = 32MB, a DBA runs a SHOW command and still sees 16MB. What is the most likely cause, and what is the correct action?
  1. Check whether work_mem requires a restart or only a reload — it requires only a reload
  2. Determine whether a reload was performed after saving the file
  3. If no reload was done, execute: SELECT pg_reload_conf(); or run pg_ctl reload from the OS
  4. Run SHOW work_mem; again to confirm the new value is active
Answer: The server was not reloaded after the file was saved. Running SELECT pg_reload_conf(); and then SHOW work_mem; should confirm the updated value of 32MB.

The math in this lesson1

Learners convert 64 GB to MB and apply a 25% guideline to set shared_buffers.
7.RP.3
Brush up in the math halls at newSchoolWorks.com:
In class: Read PostgreSQL Documentation Chapter 20 (Client Authentication) and Chapter 19 (Server Configuration); annotate a printed excerpt identifying the ten most commonly tuned parameters (shared_buffers, work_mem, max_connections, wal_level, etc.) and the authentication methods available in pg_hba.conf. · Using a provided scenario card (e.g., 'production server with 64 GB RAM, 200 concurrent users'), calculate recommended values for shared_buffers (roughly 25% of RAM as a starting point per community guidance) and work_mem, enter them in postgresql.conf, reload the server, and confirm changes with SHOW statements. · Write three pg_hba.conf rules covering local ident, md5, and scram-sha-256 authentication for different client CIDRs; attempt connections as test users to verify each rule fires correctly, logging results in a configuration journal.
Materials: PostgreSQL 16 Documentation Chapters 19–20, pgtune.leopard.in.ua reference (for instructor demonstration only), psql client, configuration journal template
Check: Instructor reviews configuration journal for correct parameter syntax, valid pg_hba.conf rules, and SHOW output screenshots; pass = all three authentication scenarios work as intended AND journal entries explain reasoning.

Practice check8

Answer each question, then check it. Nothing is recorded; this is your own practice.

PostgreSQL Server Configuration
1. Which postgresql.conf parameter controls the size of the shared memory buffer pool and typically requires a server restart to take effect?
PostgreSQL Client Authentication
2. A pg_hba.conf file contains these two consecutive lines: host all all 0.0.0.0/0 reject host appdb appuser 10.0.1.0/24 scram-sha-256 User 'appuser' tries to connect to 'appdb' from 10.0.1.15. What happens?
PostgreSQL Security and Authentication
3. Which pg_hba.conf authentication method is currently recommended by the PostgreSQL community for password-based remote connections?
PostgreSQL Server Configuration
4. After changing max_connections in postgresql.conf from 100 to 300, the DBA runs SELECT pg_reload_conf(); but the SHOW max_connections; output still shows 100. What is the correct next step?
PostgreSQL Performance Tuning
5. A server has 32 GB of RAM. Using the 25% community starting guideline, what is the correct beginning value for shared_buffers?
PostgreSQL Security and Authentication
6. Which pg_hba.conf connection TYPE requires that the client establish a connection encrypted with SSL?
PostgreSQL Server Configuration
7. Which SQL statement can a DBA use to confirm that a postgresql.conf change to work_mem has taken effect without restarting the server?
PostgreSQL Client Authentication
8. A DBA needs to allow the local OS user 'pgadmin' to connect to all databases as the PostgreSQL user 'pgadmin' via a Unix-domain socket without a password, relying on operating-system username verification. Which pg_hba.conf rule is correct?
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.