Run PostgreSQL without installing

This issue appears very often in all kinds of forums. "So, this recipe is worth sharing" – we thought. And that's usually how it happens

Objective: to run the PostgreSQL server on a desktop computer or a server running Windows without installing it, possibly with portable media.



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

So what you need to do:

    the
  1. To start the necessary binary files for Windows server. Can copy the PostgreSQL folder (minus the folder data) from an existing server installation, or just download the files from the website PostgreSQL Windows. Make sure that you have selected .zip archive.
  2. the
  3. Then copy the following batch file in the root of the new folder PostgreSQL.
  4. the
  5. Upon first use, uncomment the line in the call to initdb.
  6. the
  7. Run the batch file.


Below is the script that starts the PostgreSQL server and clicking the enter key (Enter), stop the service. The script we use in the Autonomous set of development and testing under PostgreSQL 9.0-beta. We are launching a process on a non-standard port (5439 so that you know that this is the 9.0 server). To initialize the database the first time, you will need to run the command initdb. You need to initialize the database only once. Then you can transfer the folder to a USB drive if you want. Variable %CD% returns the path to the folder where the batch file is located.

@ECHO ON
REM Set environment variables to run 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 "Press Enter to stop the server"
pause
%CD%\bin\pg_ctl -D %CD%/data stop
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Fresh hay from the cow, or 3000 icons submitted!

Knowledge base. Part 2. Freebase: make requests to the Google Knowledge Graph

Group edit the resources (documents) using MIGXDB