Last active
September 22, 2015 06:28
-
-
Save tobiasviehweger/cbfd9a1a55bff0862f9e to your computer and use it in GitHub Desktop.
Spin up local postgres
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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