📜 ⬆️ ⬇️

Run PostgreSQL without installation

This question often arises in all kinds of forums. “Therefore, this recipe is worth sharing,” we thought. And that's how it usually happens here.

Task: run 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 permission to install (update) the server on this machine.

So what you need to do:

  1. First you need the server binary files for Windows. You can copy the PostgreSQL folder (minus the data folder) from an existing server installation, or simply download files from the Windows PostgreSQL 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. When first used, uncomment the line in the initdb call.
  4. Run the batch file.

Below is the script that starts the PostgreSQL server and, when you press the enter key, will stop the service. We use this script as part of the stand-alone development and testing suite managed by PostgreSQL 9.0-beta. We run the process on a nonstandard port (5439, to know that this is exactly 9.0-server). To initialize the database for the first time, you will need to run the initdb command. You only need to initialize the database once. Then you can transfer the folder to a USB device if you want. The variable % CD% returns the path to the folder where the batch file is located.

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 "
%CD% \bin\pg_ctl -D %CD% /data stop

Source: https://habr.com/ru/post/101678/

All Articles