Postgres

Coder ships with a built-in PostgreSQL database, but if you'd like to set up and use your own, refer to the following instructions.

For in-depth information, please see the PostgreSQL documentation.

Step 1: Install and start PostgreSQL

macOS with Homebrew

  1. Install with Homebrew:

    brew install postgres
    
  2. Start PostgreSQL with brew

    brew services start postgresql
    
  3. Connect to PostgreSQL:

    psql postgres
    

Debian/Ubuntu

  1. Install PostgreSQL:

    sudo apt-get install -y postgresql
    
  2. Start PostgreSQL:

    sudo systemctl enable postgresql
    sudo systemctl start postgresql
    
  3. Connect to PostgreSQL:

    sudo -u postgresql psql
    

Step 2: Create a database and user for Coder

  1. Create the coderuser role:

    create role coderuser with login;
    
  2. Create a database called coder and assign the owner:

    create database coder owner coder;
    
  3. Set the password for coderuser:

    \password coder # enter password when prompted
    
  4. Assign rights to the database to your user:

    grant all privileges on database coder to coderuser;
    

Using your PostgreSQL database with Coder

To use your Postgres database with Coder, provide the CODER_PG_CONNECTION_URL variable:

postgresql://[user[:password]@][networkLocation][:port][/dbname][?param1=value1&...]

Append to coder server to start your deployment. For example:

CODER_PG_CONNECTION_URL="postgres://<databaseUsername>@0.0.0.0/<databaseName>?sslmode=disable&password=<password>" \
    coder server -a 0.0.0.0:3000 --verbose

If you installed Coder manually, you can add the CODER_PG_CONNECTION_URL variable to /etc/coder.d/coder.env.

See an opportunity to improve our docs? Make an edit.