Files
postgrest/docs/install/server.md
T

4.2 KiB

Installation

Installing from Pre-Built Release

The release page has precompiled binaries for Mac OS X, Windows, and several Linux distros. Extract the tarball and run the binary inside with no arguments to see usage instructions:

# Untar the release (available at https://github.com/begriffs/postgrest/releases/latest)

$ tar zxf postgrest-[version]-[platform].tar.xz

# Try running it
$ ./postgrest

# You should see a usage help message

Invitation to Contribute

<p>I currently build the binaries manually for each architecture.
It would be nice to set up an automated build matrix for various
architectures. It should support Mac, Windows and 32- and 64-bit
versions of

<ul><li>Scientific Linux 6</li><li>CentOS</li><li>RHEL 6</li></ul></p>

Building from Source

When a prebuilt binary does not exist for your system you can build the project from source. You'll also need to do this if you want to help with development. Stack makes it easy. It will install any necessary Haskell dependencies on your system.

#ubuntu example
wget -q -O- https://s3.amazonaws.com/download.fpcomplete.com/ubuntu/fpco.key | sudo apt-key add -
echo 'deb http://download.fpcomplete.com/ubuntu/trusty stable main'|sudo tee /etc/apt/sources.list.d/fpco.list
sudo apt-get update && sudo apt-get install stack -y
  • Build & install in one step
git clone https://github.com/begriffs/postgrest.git
cd postgrest
sudo stack install --install-ghc --local-bin-path /usr/local/bin
  • Run the server

If you want to run the test suite, stack can do that too: stack test.

Running the Server

postgrest postgres://user:pass@host:port/db [flags]

The user in the connection string is the "authenticator role," i.e. a role which is used temporarily to switch into other roles depending on the authentication request JWT. For simple API's you can use the same role for authenticator and anonymous.

The possible flags are:

-p, --port
The port on which the server will listen for HTTP requests. Defaults to 3000.
-a, --anonymous
The database role used to execute commands for those requests which provide no JWT authorization.
-s, --schema
The db schema which you want to expose as an API. For historical reasons it defaults to 1, but you're more likely to want to choose a value of public.
-j, --jwt-secret
The secret passphrase used to encrypt JWT tokens. Defaults to secret but do not use the default in production! Load-balanced PostgREST servers should share the same secret.
-p, --pool
Max connections to use in db pool. Defaults to to 10, but you should find an optimal value for your db by running the SQL command show max_connections;

Hiding Password from Process List

<p>Passing the database password and JWT secret as naked
parameters might not be a good idea because the parameters are
visible in a <code>ps</code> listing. One solution is to set
environment variables such as PASS and use <code>$PASS</code>
in the connection string.  Another is to use a user-specific
<a
href="http://www.postgresql.org/docs/current/static/libpq-pgpass.html">.pgpass</a>
file.</p>

Installing PostgreSQL

To use PostgREST you will need an underlying database (PostgreSQL version 9.3 or greater is required). You can use something like Amazon RDS but installing your own locally is cheaper and more convenient for development.