This Flox environment gives you a local PostgreSQL setup that runs in a controlled environment, preventing dependency conflicts without using containers or VMs. Flox doesn't sandbox processes or limit the local user's access.
- Local PostgreSQL instance—no containers—that doesn't mess with your system
- PostGIS extension for spatial data preinstalled
- Declarative version selection—easily define which version of PostgreSQL you need.
- Port isolation to avoid conflicts with existing PostgreSQL instances
- Setup that takes <30 seconds, not >30 minutes
postgresql_16- Latest stable PostgreSQL release; can customize this topostgresql_15,postgresql_14, etc.postgis- Spatial extension for geo workgum- Powers the clean, elegant, stylish setup UIbat- Powers thereadmefunction
- Flox installed
- That's it. No, really.
- Clone or create a directory
git clone https://github.com/youruser/postgres-env && cd postgres-env- Activate and go
flox activateWant PostgreSQL to start immediately? Just add the -s flag:
flox activate -sOn first activation, you'll get a simple UI that:
- Lets you set a custom host, port, username, password, and database
- Uses sane defaults if you just want to get moving
- Creates an isolated data directory that won't conflict with anything
After setup, these commands are all you need:
# Start PostgreSQL
pgstart
# Stop PostgreSQL
pgstop
# Restart PostgreSQL (if you change configs)
pgrestart
# Reconfigure from scratch
pgconfigure
# Connect directly to your database
psqlThis environment:
- Creates an isolated data directory in
$FLOX_ENV_CACHE/postgres - Initializes PostgreSQL with UTF-8 encoding and proper permissions
- Spins up a terminal wizard you can use to configure custom port, username, password, database, and path
- Uses Unix sockets for better performance
- Provides service management through Flox
By default, your database exists at $FLOX_ENV_CACHE/postgres/data and persists between environment activations. The terminal bootstrapping wizard gives you a way to change this path.
- Main config:
$FLOX_ENV_CACHE/postgres.config - PostgreSQL config:
$PGDATA/postgresql.conf
Having issues? Try these fixes:
-
Service won't start:
- Check if another PostgreSQL instance is using your configured port
- Run
pgstopfollowed bypgstartto reset the service - Check log output with
tail -f $PGHOST/LOG
-
Connection issues:
- Verify your host and port with
echo $PGHOSTADDR:$PGPORT - Try connecting with explicit parameters:
psql -h $PGHOSTADDR -p $PGPORT -U $PGUSER $PGDATABASE - Make sure the service is running with
flox services status
- Verify your host and port with
-
Total reset:
- Run
pgconfigureto wipe and rebuild your configuration - If all else fails, delete
$FLOX_ENV_CACHE/postgresand reactivate
- Run
Runs on:
- macOS (ARM/Intel)
- Linux (ARM/x86)
- Run
flox editto switch PostgreSQL versions, add PostgreSQL extensions, etc. - To access your local PostgreSQL instance from the network, set the host to
0.0.0.0during configuration - PostGIS is ready to use - just run
CREATE EXTENSION postgis;in your database. The Flox Catalog has all popular PostgreSQL extensions. You can useflox search <keyword>to discover them.
Flox combines package and environment management, building on Nix. It gives you Nix with a git-like syntax and an intuitive UX:
- Declarative environments. Software packages, variables, services, etc. are defined in simple, human-readable TOML format;
- Content-addressed storage. Multiple versions of packages with conflicting dependencies can coexist in the same environment;
- Reproducibility. The same environment can be reused across development, CI, and production;
- Deterministic builds. The same inputs always produce identical outputs for a given architecture, regardless of when or where builds occur;
- World's largest collection of packages. Access to over 150,000 packages—and millions of package-version combinations—from Nixpkgs.