# PostgreSQL Installation from Source Code

This document describes the installation of PostgreSQL using this source code distribution.

If you are building PostgreSQL for Microsoft Windows, read this document if you intend to build with MinGW or Cygwin; but if you intend to build with Microsoft's Visual C++, see the main documentation instead.

## Getting Started

The following is a quick summary of how to get PostgreSQL up and running once installed. The main documentation contains more information.

1. Create a user account for the PostgreSQL server. This is the user the server will run as. For production use you should create a separate, unprivileged account (postgres is commonly used). If you do not have root access or just want to play around, your own user account is enough, but running the server as root is a security risk and will not work.

       adduser postgres

2. Create a database installation with the `initdb` command. To run `initdb` you must be logged in to your PostgreSQL server account. It will not work as root.

       root# mkdir /usr/local/pgsql/data
       root# chown postgres /usr/local/pgsql/data
       root# su - postgres
       postgres$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

   The `-D` option specifies the location where the data will be stored. You can use any path you want, it does not have to be under the installation directory. Just make sure that the server account can write to the directory (or create it, if it doesn't already exist) before starting `initdb`, as illustrated here.

3. At this point, if you did not use the `initdb` `-A` option, you might want to modify `pg_hba.conf` to control local access to the server before you start it. The default is to trust all local users.

4. The previous `initdb` step should have told you how to start up the database server. Do so now. The command should look something like:

       /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data start

   To stop a server running in the background you can type:

       /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data stop

5. Create a database:

       /usr/local/pgsql/bin/createdb testdb

   Then enter:

       /usr/local/pgsql/bin/psql testdb

   to connect to that database. At the prompt you can enter SQL commands and start experimenting.

## What Now?

- The PostgreSQL distribution contains a comprehensive documentation set, which you should read sometime. After installation, the documentation can be accessed by pointing your browser to `/usr/local/pgsql/doc/html/index.html`, unless you changed the installation directories.

  The first few chapters of the main documentation are the Tutorial, which should be your first reading if you are completely new to SQL databases. If you are familiar with database concepts then you want to proceed with part on server administration, which contains information about how to set up the database server, database users, and authentication.

- Usually, you will want to modify your computer so that it will automatically start the database server whenever it boots. Some suggestions for this are in the documentation.

- Run the regression tests against the installed server (using `make installcheck`). If you didn't run the tests before installation, you should definitely do it now. This is also explained in the documentation.

- By default, PostgreSQL is configured to run on minimal hardware. This allows it to start up with almost any hardware configuration. The default configuration is, however, not designed for optimum performance. To achieve optimum performance, several server parameters must be adjusted, the two most common being `shared_buffers` and `work_mem`. Other parameters mentioned in the documentation also affect performance.