This page in other versions: 9.1 / 9.2 / 9.3 / 9.4 / current (9.5)  |  Development versions: devel  |  Unsupported versions: 7.2 / 7.3 / 7.4 / 8.0 / 8.1 / 8.2 / 8.3 / 8.4 / 9.0

Chapter 1. Getting Started

1.1. Installation

Before you can use PostgreSQL you need to install it, of course. It is possible that PostgreSQL is already installed at your site, either because it was included in your operating system distribution or because the system administrator already installed it. If that is the case, you should obtain information from the operating system documentation or your system administrator about how to access PostgreSQL.

If you are not sure whether PostgreSQL is already available or whether you can use it for your experimentation then you can install it yourself. Doing so is not hard and it can be a good exercise. PostgreSQL can be installed by any unprivileged user; no superuser (root) access is required.

If you are installing PostgreSQL yourself, then refer to Chapter 14 for instructions on installation, and return to this guide when the installation is complete. Be sure to follow closely the section about setting up the appropriate environment variables.

If your site administrator has not set things up in the default way, you may have some more work to do. For example, if the database server machine is a remote machine, you will need to set the PGHOST environment variable to the name of the database server machine. The environment variable PGPORT may also have to be set. The bottom line is this: if you try to start an application program and it complains that it cannot connect to the database, you should consult your site administrator or, if that is you, the documentation to make sure that your environment is properly set up. If you did not understand the preceding paragraph then read the next section.


Aug. 22, 2006, 7:55 p.m.

Here are the steps to run a postgresql server as an unprivileged user in a local directory.
This was tested on debian (ubuntu 6.06.1 LTS).

This setup is great in that an application has complete control of the database server, creates it on the fly, starts it on demand.
Everything is self-contained.

#First I had to add the PostgreSQL administration commands to the PATH:
export PATH=$PATH:/usr/lib/postgresql/8.1/bin

#LOCAL_DB is the directory that will contain everything.
export LOCAL_DB=$PWD

#Setup the server
export PGDATA=$LOCAL_DB/data

#Start the server (no spaces in $LOCAL_DB !)
pg_ctl -w -l server.log start -o "-c listen_addresses= -c unix_socket_directory=$LOCAL_DB"

#Create a database and an unprivileged user
createdb base
createuser -SDR client

#Run client commands
psql base client

Privacy Policy | About PostgreSQL
Copyright © 1996-2016 The PostgreSQL Global Development Group