Installing PostgreSQL on Windows
suggest changeWhile it’s good practice to use a Unix based operating system (ex. Linux or BSD) as a production server you can easily install PostgreSQL on Windows (hopefully only as a development server).
Download the Windows installation binaries from EnterpriseDB: http://www.enterprisedb.com/products-services-training/pgdownload This is a third-party company started by core contributors to the PostgreSQL project who have optimized the binaries for Windows.
Select the latest stable (non-Beta) version (9.5.3 at the time of writing). You will most likely want the Win x86-64 package, but if you are running a 32 bit version of Windows, which is common on older computers, select Win x86-32 instead.
Note: A minor-version upgrade usually replaces the binaries and restarts the service. A major-version change, or a move between a beta and a later release with a different catalog version, needs pg_upgrade or a dump and restore.
You can check if your version of Windows is 32 or 64 bit by going to Control Panel -> System and Security -> System -> System type, which will say “##-bit Operating System”. This is the path for Windows 7, it may be slightly different on other versions of Windows.
In the installer select the packages you would like to use. For example:
- pgAdmin ( https://www.pgadmin.org ) is a free GUI for managing your database and I highly recommend it. In 9.6 this will be installed by default.
- PostGIS ( http://postgis.net ) provides geospatial analysis features on GPS coordinates, distances etc. very popular among GIS developers.
- The Language Package provides required libraries for officially supported procedural language PL/Python, PL/Perl and PL/Tcl.
- Other packages like pgAgent, pgBouncer and Slony are useful for larger production servers, only checked as needed.
All those optional packages can be later installed through “Application Stack Builder”.
Note: There are also other languages that are not officially supported, such as PL/V8, PL/Lua, and PL/Java.
Open pgAdmin and connect to your server by double clicking on its name, for example “PostgreSQL 9.5 (localhost:5432)”.
From this point you can follow guides such as the excellent book PostgreSQL: Up and Running, 2nd Edition ( http://shop.oreilly.com/product/0636920032144.do ).
Optional: Manual Service Startup Type
PostgreSQL runs as a service in the background which is slightly different than most programs. This is common for databases and web servers. Its default Startup Type is Automatic which means it will always run without any input from you.
Why would you want to manually control the PostgreSQL service? If you’re using your PC as a development server some of the time and also use it to play video games, for example, PostgreSQL could slow down your system a bit while it’s running.
Why wouldn’t you want manual control? Starting and stopping the service can be a hassle if you do it often.
If you don’t notice any difference in speed and prefer avoiding the hassle then leave its Startup Type as Automatic and ignore the rest of this guide. Otherwise…
Go to Control Panel -> System and Security -> Administrative Tools.
Select “Services” from the list, right click on its icon, and select Send To -> Desktop to create a desktop icon for more convenient access.
Close the Administrative Tools window then launch Services from the desktop icon you just created.
Scroll down until you see a service with a name like postgresql-x##-9.# (ex. “postgresql-x64-9.5”).
Right click on the postgres service, select Properties -> Startup type -> Manual -> Apply -> OK. You can change it back to automatic just as easily.
If you see other PostgreSQL-related services in the list, such as “pgbouncer” or “PostgreSQL Scheduling Agent - pgAgent”, you can also change their Startup Type to Manual because they’re not much use if PostgreSQL isn’t running. Although this will mean more hassle each time you start and stop, so it’s up to you. They don’t use as many resources as PostgreSQL itself and may not have any noticeable impact on your system’s performance.
If the service is running its Status will say Started, otherwise it isn’t running.
To start it right click and select Start. A loading prompt will be displayed and should disappear on its own soon after. If it gives you an error try a second time. If that doesn’t work then there was some problem with the installation, possibly because you changed some setting in Windows most people don’t change, so finding the problem might require some sleuthing.
To stop postgres right click on the service and select Stop.
If you ever get an error while attempting to connect to your database, check Services to make sure it’s running.
For other very specific details about the EDB PostgreSQL installation, for example the Python runtime version in the official language pack of a specific PostgreSQL version, always refer to the official EDB installation guide. Change the version in the link to your installer’s major version. The version numbers in this page are from the 9.5/9.6 era.