Skip to content

How to run a PostgreSQL server?

Alan L. Wong edited this page Apr 12, 2019 · 7 revisions

Note: you need to have PostgreSQL 9.4+ in order to get Kinto working! Check which version of PostgreSQL you have by running postgres --version.

Debian/Ubuntu

In Ubuntu/Debian based:

Update and Install PostgreSQL 9.5:

sudo apt-get update
sudo apt-get install postgresql-9.5

By default, the postgres user has no password and can hence only connect if ran by the postgres system user. The following command will assign it:

sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
sudo -u postgres psql -c "CREATE DATABASE testdb;"
sudo -u postgres psql -c "ALTER DATABASE testdb SET TIMEZONE TO 'UTC';"

Start

 sudo service postgresql start

Initialize kinto:

 kinto init

You will be asked which backend you would like to use:

 $ Select the backend you would like to use: (1 - postgresql, 2 - redis, default - memory)

select either 1 or 2 and click enter.In this case we are supposed to use postgresql so select 1 and click enter.

MacOS

Assuming brew is installed:

brew update
brew install postgresql

Create the initial database:

initdb /usr/local/var/postgres

Start the database server:

pg_ctl -D /usr/local/var/postgres -l logfile start

Create the user 'postgres' with super user privileges:

createuser --superuser=postgres

Create the test data base:

createdb --owner=postgres testdb

You can now start the kinto server and run the tests. After the tests have run, stop the postgres server:

pg_ctl -D /usr/local/var/postgres stop

Using Docker

Install Docker:

On Ubuntu you can do:

sudo apt-get install docker.io

Run the official PostgreSQL container locally:

postgres=$(sudo docker run -e POSTGRES_PASSWORD=postgres -d -p 5432:5432 postgres)

Tag and save the current state with::

sudo docker commit $postgres kinto-db

In the future, run the tagged version of the container

kintodb=$(sudo docker run -e POSTGRES_PASSWORD=postgres -d -p 5432:5432 kinto-db)
# ... Use it!
sudo docker stop $kintodb