PostgreSQL/PostGIS without instllation

Using EnterpriseDB installer to install PostgreSQL and using Stackbuilder to install PostGIS is very easy. However, running PostgreSQL/PostGIS as a service, which is the default result of such installations, has some overhead because it is running in the background no matter it is actually used or not. Note that PostgreSQL has a small footprint when in “idle”. Nevertheless, it could be useful to run PostgreSQL/PostGIS as needed using binaries.

Download PostgreSQL and PostGIS Binaries

PostgreSQL and PostGIS binaries are executable files and can run without installation. Here are a few good sources for information.

Stack Overflow

Enterprise DB Binaries for PostgreSQL

PostGIS Zip Files

Command to start/stop PostgreSQL

The basic process is to unzip the PostgreSQL to a folder. Then unzip the PostGIS binary and overwrite those in PostgreSQL.

Commands to manage PostgreSQL/PostGIS


@ECHO Change to the bin folder of the downloaded/unzipped PostgreSQL Binaries
@ECHO Intialize a database cluster (data folder/directory) using initdb with -D

initdb -D c:\Users\Arthur\pgdata -U postgres -W -E UTF8 -A scram-sha-256

Then, create a batch file to start, stop PostgreSQL


@ECHO OFF

REM Initialize the database cluster using a data folder
REM C:\PortableSoftware\pgsql\bin\initdb -D C:\PortableSoftware\pgsql\data

REM Start the service with a log file
C:\PortableSoftware\pgsql\bin\pg_ctl.exe -D C:\PortableSoftware\pgsql\data -l C:\PortableSoftware\pgsql\bin\pg.log start 

@ECHO Press any key three times to stop the service ... 
PAUSE
PAUSE
PAUSE

REM STOP the service
C:\PortableSoftware\pgsql\bin\pg_ctl.exe -D C:\PortableSoftware\pgsql\data stop

The above is to start PostgreSQL and below is to stop it.


@ECHO OFF

REM Initialize the database using a data folder
REM C:\PortableSoftware\pgsql\bin\initdb -D C:\PortableSoftware\pgsql\data

REM Start the service with a log file
REM C:\PortableSoftware\pgsql\bin\pg_ctl.exe -D C:\PortableSoftware\pgsql\data -l pg.log start

REM STOP the service
C:\PortableSoftware\pgsql\bin\pg_ctl.exe -D C:\PortableSoftware\pgsql\data stop