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 |
GEOIDS_DB_USER | Database user | Current system user |
GEOIDS_DB_PASSWORD | Database password | Empty string |
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"
ENV["GEOIDS_DB_USER"] = "census_user"
ENV["GEOIDS_DB_PASSWORD"] = "secure_password"
# Load package
using GeoIDsCommand 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.jlConfiguration 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
export GEOIDS_DB_USER=census_userDatabase 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 exist - Enables the PostGIS extension if needed
- Downloads and extracts the U.S. Census TIGER/Line county shapefile
- Creates the
census.countiestable with proper schema - Loads 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().