Skip to content

Instantly share code, notes, and snippets.

@percursoaleatorio
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save percursoaleatorio/c68f9dc7e45eb9b82a95 to your computer and use it in GitHub Desktop.
Save percursoaleatorio/c68f9dc7e45eb9b82a95 to your computer and use it in GitHub Desktop.

PGAdmin

You might try installing from the command line with a command like this:

*msiexec* /i pgadmin3.msi *ALLUSERS*=""

That should run the installer but for it into per-user mode.

From: http://www.postgresql.org/message-id/BANLkTimHUFk9CZQKigHcvFd1Om39nfnKnA@mail.gmail.com

PostgreSQL

Can you run a PostgreSQL server on your windows desktop/server box without having to install anything? The answer is yes and quite easily.

Get binaries for Windows. You can either copy the postgresql folder (minus the data folder) from an existing PostgreSQL install, or just download the PostgreSQL binaries from PostgreSQL Windows. Make sure to choose the zip archive.

Next copy the below batch file into the root of the postgresql folder.

For first time use, unremark out the (initdb step)

Run the batch file

Below is the script that will start a PostgreSQL server and clicking the enter key will shut the service down. This is one we were using as part of a self-contained development kit running PostgreSQL 9.0 beta. We chose to run on a non-standard port (5439 so we know it's the 9.0 server). To initialize the database for the first time, you will want to run the remarked out initdb line. You only need to run once. From then on you can carry the server on USB device if you want and launch as you wish. Clicking enter in the window will shut it down. The assumpution of the script is that its in the root of your unzipped PostgreSQL folder. The %CD% returns the folder path of current directory and %~dp0 returns folder path of script:

@ECHO ON
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=5439
@SET PGLOCALEDIR=%~dp0\share\locale
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

From: http://www.postgresonline.com/journal/archives/172-Starting-PostgreSQL-in-windows-without-install.html

Extract files from an MSI file

To extract files from a .msi file at the command line, type:

msiexec /a PathToMSIFile /qb TARGETDIR=DirectoryToExtractTo

For example, to extract files from f:downloadxpto.msi into c:xpto you would type:

msiexec /a f:\download\xpto.msi /qb TARGETDIR=c:\xpto

The destination directory does not need to exist prior to running this command.

Another step by step

Preparing the PostgreSQL 9.1 Installation

This process has two steps:

The first step is to download and install the Microsoft Visual C++ 2008 redistributable package.

The second step is downloading and unpacking the PostgreSQL binary distribution.

After you have downloaded the binary zip distribution, you can unzip the binary distribution to the preferred directory.

When this is done, the target directory should contain a directory called ‘pgsql’. This directory contains the binaries of PostgreSQL 9.1. I will refer this directory simply as POSTGRESQL_ROOT (Remember to replace the string POSTGRESQL_ROOT with the actual directory path of your installation when following these instructions).

The next step is to create the data and log directories for your PostgreSQL installation. This is done by creating the following directories to the POSTGRESQL_ROOT directory:

The ‘data’ directory contains the data files of your PostgreSQL installation. The ‘log’ directory contains the logs of your PostgreSQL installation.

You have now finished the needed preparations and can move on to the next phase of the installation process.

Configuring the PostgreSQL 9.1 Installation

The next step is to create a new PostgreSQL database cluster. You can do this by using the initdb command which is found from the POSTGRESQL_ROOTbin directory.

You can create the database cluster by running the following command from the bin directory of your PostgreSQL installation:

initdb -U postgres -A password -E utf8 -W -D POSTGRESQL_ROOT\data

The command line parameters of the initdb command are described in following:

-U postgres means that the superuser account of your database is called ‘postgres’.
-A password means that password authentication is used.
-E utf8 means that the default encoding will be UTF-8.
-W means that you will enter the superuser password manually.
-D POSTGRESQL_ROOT\data specifies the data directory of your PostgreSQL installation.

After you have successfully created the database cluster, your PostgreSQL installation is ready to be used. You can start and stop your database instance by using the following commands:

The database can be started by running the following command:

"POSTGRESQL_ROOT/bin/pg_ctl" -D "POSTGRESQL_ROOT/data" -l "POSTGRESQL_ROOT/log/pgsql.log" start

The database can be stopped by running the following command:

"POSTGRESQL_ROOT/bin/pg_ctl" -D "POSTGRESQL_ROOT/data" -l "POSTGRESQL_ROOT/log/pgsql.log" stop

To make things as easy as possible, you should create new shortcuts to your desktop and use them for starting and stopping the database server.

Note: If you want to run PostgreSQL as a service, you should run the following command:

POSTGRESQL_ROOT/bin/pg_ctl.exe register -N "postgresql" -U "NT AUTHORITY\NetworkService" -D "POSTGRESQL_ROOT/data" -w

After you have done this, you can start the service by using the Services panel.

Congratulations

Your PostgreSQL 9.1 installation should now be functional. The next step is to start the database server by using the created shortcut and verify that you can connect to your database instance.

You can use the PgAdmin database management tool for this task and congratulate yourself for a job well done.

From: http://www.petrikainulainen.net/programming/tips-and-tricks/installing-postgresql-9-1-to-windows-7-from-the-binary-zip-distribution/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment