Skip to content

Instantly share code, notes, and snippets.

@tobiasviehweger
Last active September 22, 2015 06:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobiasviehweger/cbfd9a1a55bff0862f9e to your computer and use it in GitHub Desktop.
Save tobiasviehweger/cbfd9a1a55bff0862f9e to your computer and use it in GitHub Desktop.
Spin up local postgres
# Assumes postgres binaries in .postgres subfolder
# http://get.enterprisedb.com/postgresql/postgresql-9.4.1-3-windows-x64-binaries.zip
$targetPath = $PSScriptRoot + "\.postgres\"
$env:Path = $targetPath + "pgsql\bin;" + $env:Path
$env:PGDATA = $targetPath + "data"
$env:PGDATABASE = "postgres"
$env:PGUSER = "postgres"
$env:PGPORT = "1338"
$env:PGLOCALEDIR = $targetPath + "pgsql\share\locale"
New-Item -Path $targetPath -Name "data" -ItemType "directory"
#Init postgres & new database
.\.postgres\pgsql\bin\initdb -U postgres -A trust
Start-Process .\.postgres\pgsql\bin\pg_ctl -ArgumentList "-D",($targetPath + "data"),"-w","-l",".postgres\logfile","start" -PassThru -NoNewWindow
Write-Host "Waiting for PostgreSQL..."
sleep -Seconds 5
# Make sure db_create.sql contains all necessary statements (CREATE DATABASE etc)
.\.postgres\pgsql\bin\psql.exe -f "db_create.sql"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment