Database Configuration#
GeoIDs.jl uses PostgreSQL with the PostGIS extension to store and manage GEOID sets. The package provides flexible configuration options through environment variables.
Note: If you need to install and set up PostgreSQL first, see our PostgreSQL Setup Guide.
Environment Variables#
You can customize the database connection using these environment variables:
| Environment Variable | Description | Default Value |
|---|---|---|
GEOIDS_DB_NAME |
Database name | tiger |
GEOIDS_DB_HOST |
Database host | localhost |
GEOIDS_DB_PORT |
Database port | 5432 |
Note: The package now uses PostgreSQL's default socket authentication which generally doesn't require username and password on local development setups. This is especially convenient on macOS with Homebrew installations.
Setting Environment Variables#
Within Julia#
You can set environment variables before loading the package:
# Set database configuration
ENV["GEOIDS_DB_NAME"] = "my_census_db"
ENV["GEOIDS_DB_HOST"] = "db.example.com"
ENV["GEOIDS_DB_PORT"] = "5433"
# Load package
using GeoIDs
Command Line#
You can set environment variables when running your script:
GEOIDS_DB_NAME=my_census_db GEOIDS_DB_HOST=db.example.com julia my_script.jl
Configuration File#
For a more permanent solution, you can add configuration to your .bashrc, .zshrc, or equivalent:
# Add to your .bashrc or .zshrc
export GEOIDS_DB_NAME=my_census_db
export GEOIDS_DB_HOST=db.example.com
Connection String Format#
The connection string is formatted as:
postgresql://host:port/dbname
For example:
postgresql://localhost:5432/tiger
This format uses PostgreSQL's default authentication mechanism, which is socket authentication on most development setups.
Database Setup#
GeoIDs.jl requires these database tables:
census.counties- Table containing county information with GEOID and geometrycensus.geoid_sets- Table for GEOID set metadata (created automatically)census.geoid_set_members- Table for GEOID set members (created automatically)census.geoid_set_changes- Table for tracking changes (created automatically)
All required tables are created automatically when you run the initialize_database() function. This function:
Creates the
censusschema if it doesn't existEnables the PostGIS extension if needed
Uses the local U.S. Census TIGER/Line county shapefile from the GeoIDs.jl/data directory
Creates the
census.countiestable with proper schemaLoads county data with GEOIDs and geometries
Sets up the GEOID set management tables
Required Schema#
The census.counties table must have the following schema:
CREATE TABLE census.counties (
geoid VARCHAR(5) PRIMARY KEY,
name VARCHAR(100),
stusps VARCHAR(2), -- State postal code
geom GEOMETRY(MultiPolygon, 4269) -- County geometry
-- Other fields can vary
);
This table is automatically created and populated when you run initialize_database().