Skip to content

Latest commit

 

History

History
76 lines (51 loc) · 2.41 KB

quickstart_2_initialize_database.md

File metadata and controls

76 lines (51 loc) · 2.41 KB

Quickstart step 2: Initialize your database

Without Docker

You need a fresh Postgres database and a database user that has full ownership of that database.

  1. Create a database for the current Unix user

    # For Linux users, first access the postgres user shell
    sudo su - postgres
    # For Mac OS users
    sudo su - _postgres
    
    createdb
    
  2. Create the Sourcegraph user and password

    createuser --superuser sourcegraph
    psql -c "ALTER USER sourcegraph WITH PASSWORD 'sourcegraph';"
    
  3. Create the Sourcegraph database

    createdb --owner=sourcegraph --encoding=UTF8 --template=template0 sourcegraph
    
  4. Configure database settings in your environment

    The Sourcegraph server reads PostgreSQL connection configuration from the PG* environment variables.

    The startup script sets default values that work with the setup described here, but if you are using different values you can overwrite them, for example, in your ~/.bashrc:

    export PGPORT=5432
    export PGHOST=localhost
    export PGUSER=sourcegraph
    export PGPASSWORD=sourcegraph
    export PGDATABASE=sourcegraph
    export PGSSLMODE=disable
    

    You can also use a tool like envdir or a .dotenv file to source these env vars on demand when you start the server.

With Docker

The Sourcegraph server reads PostgreSQL connection configuration from the PG* environment variables.

The development server startup script as well as the docker compose file provide default settings, so it will work out of the box.

You can overwrite these settings e.g. via your ~/.bashrc:

export PGUSER=sourcegraph
export PGPASSWORD=sourcegraph
export PGDATABASE=sourcegraph

You can also use the PGDATA_DIR environment variable to specify a local folder (instead of a volume) to store the database files. See the dev/redis-postgres.yml file for more details.

More info

For more information about data storage, read our full PostgreSQL page.

Migrations are applied automatically.

< Previous | Next >