Bash scripts for installing and configuring PostgreSQL on Arch Linux.
These scripts automate the full PostgreSQL setup process — from package installation to hardware-based performance tuning — so that a clean Arch Linux installation can have a properly configured PostgreSQL server in minutes.
The goal is to have a reproducible, well-documented setup that can be reused across machines while keeping every configuration decision visible and intentional.
Installs and configures the PostgreSQL server. Run once per machine.
What it does:
- Installs the
postgresqlpackage viapacman - Generates
pt_BR.UTF-8locale if missing - Initializes the database cluster (
initdb) - Secures
pg_hba.conf— removes defaulttrustauthentication, setspeerfor thepostgressuperuser - Detects hardware (RAM, disk type) and calculates performance parameters
- Displays proposed values and asks for confirmation before applying
- Enables and starts the PostgreSQL service
The script is idempotent: it detects completed steps and skips them.
sudo ./setup-server.sh| Parameter | Formula | Purpose |
|---|---|---|
shared_buffers |
RAM / 4 | Data page cache |
effective_cache_size |
RAM × 3/4 | Query planner hint (does not allocate memory) |
work_mem |
RAM / 512 | Per-operation memory for sorts and hashes |
maintenance_work_mem |
RAM / 64 | Memory for VACUUM, CREATE INDEX, ALTER TABLE |
random_page_cost |
SSD: 1.1 / HDD: 4.0 | I/O cost estimate for the query planner |
effective_io_concurrency |
SSD: 200 / HDD: 2 | Parallel I/O requests |
Creates a dedicated role and database for a specific project. Run once per project.
What it does:
- Creates a role named
<project_name>dbwithLOGIN,NOSUPERUSER,NOCREATEDB,NOCREATEROLE - Prompts for a password (with confirmation)
- Creates a database named
<project_name>owned by the new role - Adds
scram-sha-256authentication rules topg_hba.conf(IPv4 + IPv6) - Reloads PostgreSQL to apply the new rules
The script is idempotent: it detects existing roles, databases, and rules, and skips them.
sudo ./setup-project.sh alma
# → Creates role 'almadb', database 'alma', authentication rules- Arch Linux
- Root access (
sudo)
| User | Connection type | Method | Scope |
|---|---|---|---|
postgres (superuser) |
Unix socket (local) |
peer |
All databases |
| Project roles | TCP (host, 127.0.0.1) |
scram-sha-256 |
Own database only |
MIT