## 17.6. 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/postgres -D /usr/local/pgsql/data

   This will start the server in the foreground. To put the server in the background use something like:

       nohup /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data \
           </dev/null >>server.log 2>&1 </dev/null &

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

       kill `cat /usr/local/pgsql/data/postmaster.pid`

5. Create a database:

       createdb testdb

   Then enter:

       psql testdb

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