Connect Bitbucket to PostgreSQL

Still need help?

The Atlassian Community is here for you.

Ask the community

This page describes how to connect Bitbucket Data Center and Server to a PostgreSQL database. 

The overall process for using a PostgreSQL database with Bitbucket is:

  • install PostgreSQL where it is accessible to Bitbucket
  • create a database and user on the PostgreSQL server for Bitbucket to use
  • install Bitbucket on Windows, or on Linux or Mac. See Getting started.
  • Either:
    • at Bitbucket install time, run the Setup Wizard to connect to the PostgreSQL database, or
    • at a later time, migrate Bitbucket to the PostgreSQL database. See Using the Database Migration Wizard.

It is assumed here that you already have PostgreSQL installed and running. For more information about PostgreSQL installation and operation, refer to the PostgreSQL documentation. For additional information review this page on tuning.

PostgreSQL has the idea of schemas. When you create a PostgreSQL database, a 'public' schema is created and set as the default for that database. It is possible to create a different schema (e.g. 'bitbucket') and set that as the default schema. Bitbucket will use whatever schema is set as the default for the logged-in user. Bitbucket does not provide a way for a user to nominate the schema to use; it uses a schema that is set as the PostgreSQL default.

See Supported platforms for the versions of PostgreSQL supported by Bitbucket.

Prerequisites

Backup

If you are migrating your Bitbucket data from the HSQL internal database, back up the home directory.

If you are migrating your Bitbucket data from another external database, back up that database by following the instructions provided by the database vendor before proceeding with these instructions.

See Data recovery and backups.

Create the Bitbucket database

Before you can use Bitbucket with PostgreSQL, you must:

  • Create a role for Bitbucket to use when it connects to the database.
    We strongly recommend that this role be established for Bitbucket's use exclusively; it should not be shared by other applications or people.
  • Create a database in which Bitbucket can store its data.
    The database must be configured to use the UTF-8 character set.
    During normal operation, Bitbucket will acquire 25–30 connections to the database. The maximum number of connections is a configurable system property – see Database pool.
  • Note that Bitbucket requires the database to keep idle connections alive for at least 10 minutes. If the database is configured with less than a 10-minute connection timeout, there will be seemingly random connection errors

Here is an example of how to create a user called bitbucketuser with password jellyfish , and a database called bitbucket , which is configured for use by bitbucketuser. Using a PostgreSQL client application like psql or pgAdmin, run the following commands, replacing the user name, password, and database name with your own values.

CREATE ROLE bitbucketuser WITH LOGIN PASSWORD 'jellyfish' VALID UNTIL 'infinity';
 
CREATE DATABASE bitbucket WITH ENCODING='UTF8' OWNER=bitbucketuser CONNECTION LIMIT=-1;

If the server that is hosting the PostgreSQL database is not the same server as Bitbucket, then please ensure that the Bitbucket server can connect to the database server. Please also refer to the PostgreSQL documentation on how to set up pg_hba.conf. If the pg_hba.conf file is not set properly, remote communication to the PostgreSQL server will fail.

Connect Bitbucket to the PostgreSQL database

You can now connect Bitbucket to the PostgreSQL database, either:

  • when you run the Setup Wizard, at install time,
  • when you wish to migrate to PostgreSQL, either from the embedded HSQL database or from another external database.

When running the Setup Wizard at install time

  1. Select External at the 'Database' step.
  2. Select PostgreSQL for Database Type.
  3. Complete the form. See the table below for details.
  4. Click Next, and follow the instructions in the Bitbucket Setup Wizard.

When migrating to PostgreSQL

  1. In the Bitbucket administration area, click Database (under 'Settings').
  2. Click Migrate database.
  3. Select PostgreSQL for Database Type.
  4. Complete the form. See the table below for details.
  5. Click Start Migration.


Hostname
The hostname or IP address of the computer running the database server.

Port
The TCP port with which Bitbucket can connect to the database server. The default value is the default port that MySQL or MariaDB runs against. You can change that if you know the port that your MySQL or MariaDB instance is using.

Database name
The name of the database that Bitbucket should connect to.

Database username
The username that Bitbucket should use to access the database.

Database password
The password that Bitbucket should use to access the database.


Last modified on Mar 7, 2023

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.