We start PostgreSQL without installation

Original author: Leo Hsu and Regina Obe
  • Transfer
  • Tutorial
This question quite often arises in all kinds of forums. “Therefore, this recipe is worth sharing,” we thought. And this is how it usually happens with us.

Objective: start the PostgreSQL server on a desktop computer or server running Windows without installation, possibly from portable media.



There are situations when it is really necessary. For example, your program does not require installation, but uses a PostgreSQL server. Or you do not have rights to install (update) the server on this machine.

So what you need to do:

  1. First you need the binary server files for Windows. You can copy the PostgreSQL folder (minus the data folder ) from an existing server installation, or simply download files from the PostgreSQL Windows site section . Make sure the .zip archive is selected.
  2. Next, copy the batch file below to the root of the new PostgreSQL folder.
  3. At first use, uncomment the line in the initdb call .
  4. Run the batch file.


Below is the script that starts the PostgreSQL server and, upon pressing the enter key (Enter), stops the service. We use this script as part of a standalone development and testing kit running PostgreSQL 9.0-beta. We run the process on a non-standard port (5439 to know that this is exactly a 9.0 server). To initialize the database for the first time, you will need to run the initdb command . Initialize the database only once. Next, you can transfer the folder to the USB device if you want. The variable % CD% returns the path to the folder in which the batch file is located.

@ECHO ON
REM Устанавливаем переменные окружения для запуска PostgreSQL
@SET PATH="%CD%\bin";%PATH%
@SET PGDATA=%CD%\data
@SET PGDATABASE=postgres
@SET PGUSER=postgres
@SET PGPORT=5439
@SET PGLOCALEDIR=%CD%\share\locale
REM %CD%\bin\initdb -U postgres -A trust
%CD%\bin\pg_ctl -D %CD%/data -l logfile start
ECHO "Нажмите Enter чтобы остановить работу сервера"
pause
%CD%\bin\pg_ctl -D %CD%/data stop

Also popular now: