# Licensing

<TierCallout>
	Supported on [Enterprise](/pricing/plans/enterprise) plans.
	<user>Available via the Web app.</user>
</TierCallout>

Sourcegraph requires a valid license key to enable many of its more prominent features.

License keys should not be shared across instances of Sourcegraph. If an additional license key is required for something like a dev environment, please contact [support@sourcegraph.com](mailto:support@sourcegraph.com) for an additional license key.

## FAQ

### What happens if our Sourcegraph license expires?

Users who are not administrators see a **Sourcegraph subscription invalid** page and can't use Sourcegraph. Administrators can still sign in, so that they can [enter a new license key](#how-can-we-update-our-license-key).

Starting 7 days before the license expires, Sourcegraph shows a banner with a link to the **Product license** page.

### How can we update our license key?

<Callout type="note">
	On [Sourcegraph Cloud](/cloud/#how-do-we-update-our-license-key), Sourcegraph manages your license key. To apply a new or renewed license, contact your Sourcegraph account team or [support@sourcegraph.com](mailto:support@sourcegraph.com).
</Callout>

On a self-hosted instance, go to **Administration → Configuration → Product license** (`/admin/license`). Here, you can update your license key, view details of your current license, and more.

The new license takes effect as soon as it's applied. You don't need to restart Sourcegraph.

If your advanced configuration is loaded from the `SITE_CONFIG` or `SITE_CONFIG_FILE` environment variable, the form is disabled. Set `licenseKey` in that configuration instead, as described in [Loading configuration via the file system](/self-hosted/advanced-config-file#advanced-configuration):

```json
  "licenseKey": "<your_key_here>",
```

### We have set up a new Sourcegraph instance by replicating an existing instance, how can we generate a new site ID to ensure the instances are unique?

The site ID of a Sourcegraph instance can be updated by running the following SQL query against the database:

```sql
UPDATE global_state SET site_id = gen_random_uuid();
```

You will still require a unique license key for each site ID.

### How does Sourcegraph calculate user licenses?

Sourcegraph calculates user license numbers using several key values:

1. `currentUserCount`: Which represents the total number of users currently on the Sourcegraph.

2. `license.userCount`: Which is the total number of user licenses allowed by the current subscription.

3. `actualUserCount`: Which represents the maximum number of users that have ever been active on the Sourcegraph instance for the current license.

The component displays these numbers in the following format:

```
"{currentUserCount} currently used / {license.userCount - currentUserCount} remaining ({actualUserCount} maximum ever used)"
```

These values are fetched from the GraphQL API using the `queryProductLicenseInfo` function, which queries the site's product subscription information and user count.

The component also checks if the number of users exceeds the licensed amount `(license.userCount - actualUserCount < 0)` and displays a warning if this is the case.

This approach allows Sourcegraph to provide clear information about license usage and encourage upgrades and scaling licenses when necessary.
