For deployments other than Cloud and Sourcegraph.com please use the information here to access the database.
We currently run two separate databases. The
sg-cloud database is the primary database, and the code-intel team uses the
You can also directly view the database in GCP.
There are two ways of connecting: either using the
gcloud beta sql connect command, which will use the
pgsql client, or running the
cloud_sql_proxy on a port locally to utilize your preferred tools.
For read-only access, there is also an option of using BigQuery and their
Using BigQuery, if you want to run a query
SELECT name::text,created_at::text FROM repo LIMIT 5;
against the Prod CloudSQL database, you need to run
SELECT * FROM EXTERNAL_QUERY("sourcegraph-dev.us.sg-cloud", "SELECT name::text,created_at::text FROM repo LIMIT 5;");
in the BigQuery editor (passing the PostgreSQL query in the second parameter to EXTERNAL_QUERY).
If you didn’t yet, install Google Cloud SDK. Ensure, that
gcloud command is reachable on your path.
Install the Cloud SQL proxy by running this command with
gcloud components install cloud_sql_proxy
You may use these gcloud commands to connect directly to the databases:
cloud_sql_proxy against our production instance
Now, in a new terminal, run the command below. The database will be running on
export PGPASSWORD='<$PASSWORD>' psql -h localhost -p 5555 -d sg -U 'dev-readonly'
Note, that to connect to
localhost:5555 you still need to supply the postgres password stored in 1Password (mentioned above).
- See all fields on a table (ie the
- See the total number of rows in the
SELECT COUNT(*) FROM repo;
We run a PgHero deployment as well you can use to analyze slow queries and overall database performance.
kubectl port-forward -n monitoring deploy/pghero 8080:8080
And then navigate to http://localhost:8080 to view the dashboard
See additional Postgres tips in our incident docs
Dogfood runs Sourcegraph completely on Kubernetes. You can port-forward the pgsql deployment:
kubectl port-forward -n dogfood-k8s deploy/pgsql 8080:5432
And access it locally:
pgcli -h localhost -p 8080 -d sg -U 'sg'