Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save GunGunGun/d852433170db444796eaa1481291fa92 to your computer and use it in GitHub Desktop.
Save GunGunGun/d852433170db444796eaa1481291fa92 to your computer and use it in GitHub Desktop.
Portable Postgres / PostGIS Install for Windows
@ECHO OFF
REM The script sets environment variables helpful for PostgreSQL
@SET PATH="%~dp0\bin";%PATH%
@SET PGDATA=%~dp0\data
@SET PGDATABASE=postgres
@SET PGUSER=postgres
@SET PGPORT=5432
@SET PGLOCALEDIR=%~dp0\share\locale
cmd
set PGPORT=5432
set PGHOST=localhost
set PGUSER=postgres
set PGPASSWORD=
set THEDB=test_postgis
set PGINSTALL=%~dp0
set PGBIN=%PGINSTALL%\bin\
set PGLIB=%PGINSTALL%\lib\
set POSTGISVER=2.1
"%PGBIN%\psql" -c "CREATE DATABASE %THEDB%"
"%PGBIN%\psql" -d "%THEDB%" -c "CREATE LANGUAGE plpgsql"
"%PGBIN%\psql" -d "%THEDB%" -f "share\contrib\postgis-%POSTGISVER%\postgis.sql"
"%PGBIN%\psql" -d "%THEDB%" -f "share\contrib\postgis-%POSTGISVER%\spatial_ref_sys.sql"
"%PGBIN%\psql" -d "%THEDB%" -f "share\contrib\postgis-%POSTGISVER%\postgis_comments.sql"
REM Add topolgy- and raster-SQLs here, if needed.
REM Uncomment the below line if this is a template database
REM "%PGBIN%\psql" -d "%THEDB%" -c "UPDATE pg_database SET datistemplate = true WHERE datname = '%THEDB%';GRANT ALL ON geometry_columns TO PUBLIC; GRANT ALL ON spatial_ref_sys TO PUBLIC"
pause
Eine kurze Dokumentation, wie man Postgres/Postgis unter Windows ohne Installation betreibt:
- PG-Binaries (ZIP) herunterladen und entpacken
http://www.enterprisedb.com/products-services-training/pgbindownload
- Batch-Datei lt. Anhang bzw. lt.
http://www.postgresonline.com/journal/archives/172-Starting-PostgreSQL-in-windows-without-install.html
im Haupt-Verzeichnis speichern (das Verzeichnis, in dem /bin zu finden ist).
- Beim ERSTEN Start der run.bat muss die gekennzeichnete Zeile ausgeführt, danach aber wieder auskommentiert werden.
- Fortan startet
run.bat den Server (ein Tastendruck in der Konsole beendet den Server wieder),
env.bat startet eine Kommandozeile mit Umgebungsvariablen (evtl editieren),
im Verzeichnis /bin befindet sich zudem pgadmin3.exe.
- Nun kann Postgis nach Anleitung installiert werden
http://postgis.net/docs/postgis_installation.html
http://postgis.net/windows_downloads
Dafür zuerst die zu Postgres passende ZIP laden, entpacken und in das Postgres-Verzeichnis integrieren
http://download.osgeo.org/postgis/windows/
Die unten stehende makepostgisdb.BAT-Datei kann als Hilfestellung genutzt werden.
@REM source: http://www.postgresonline.com/journal/archives/172-Starting-PostgreSQL-in-windows-without-install.html
@ECHO OFF
REM The script starts a PostgreSQL server
@SET PATH="%~dp0\bin";%PATH%
@SET PGDATA=%~dp0\data
@SET PGDATABASE=postgres
@SET PGUSER=postgres
@SET PGPORT=5432
@SET PGLOCALEDIR=%~dp0\share\locale
@REM uncomment the line below on FIRST RUN
@REM "%~dp0\bin\initdb" -U postgres -A trust
"%~dp0\bin\pg_ctl" -D "%~dp0/data" -l logfile start
ECHO "Click enter to stop"
pause
"%~dp0\bin\pg_ctl" -D "%~dp0/data" stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment