/
postgresql.md
72 lines (52 loc) · 2.49 KB
/
postgresql.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
title: "PostgreSQL"
date: 2021-08-04
tags: ["SQL", "PostgreSQL", "SQLite", "Configuration", "Dashboard", "Production", "Database"]
description: "How to configure the Tyk Dashboard with a SQL database"
weight: 3
menu:
main:
parent: "Database Settings"
aliases:
- /planning-for-production/database-settings/sql
---
## Introduction
How you configure your PostgreSQL installation depends on whether you are installing Tyk from fresh using PostgreSQL, or are migrating from an existing MongoDB instance.
## Supported Versions
{{< include "sql-versions-include" >}}
## Migrating from an existing MongoDB instance
For v4.0 we have provided a migration command that will help you migrate all data from the main storage layer (APIs, Policies, Users, UserGroups, Webhooks, Certificates, Portal Settings, Portal Catalogues, Portal Pages, Portal CSS etc.).
{{< note success >}}
**Note**
The migration tool will not migrate any Logs, Analytics or Uptime analytics data.
{{< /note >}}
1. Make sure your new SQL platform and the existing MongoDB instance are both running
2. Configure the `main` part of `storage` section of your `tyk-analytics.conf`:
```yaml
{
...
"storage": {
...
"main": {
"type": "postgres",
"connection_string": "user=root password=admin database=tyk-demo-db host=tyk-db port=5432"
}
}
}
```
3. Run the following command:
```console
./tyk-analytics migrate-sql
```
You will see output listing the transfer of each database table. For example: `Migrating 'tyk_apis' collection. Records found: 7`.
4. You can now remove your `mongo_url` (or `TYK_DB_MONGOURL` environment variable) from your `tyk-analytics.conf`
5. Restart your Tyk Dashboard
## PostgreSQL sizing
The aggregate record size depends on the number of APIs and Keys you have. Each counter size ~50b, and every aggregated value has its own counter.
So an hourly aggregate record is computed like this: 50 * active_apis + 50 * api_versions + 50 * active_api_keys + 50 * oauth_keys, etc.
The average aggregate record size (created hourly) on our cloud is about ~ 40KB (a single record includes all the aggregate stats mentioned above).
So for 1 million requests per day, it will generate 1KB * 1M request stats (1GB) + 24 * 40KB aggregate stats (~1MB).
Per month: 30GB request logs + 30MB aggregate logs
## PostgreSQL Database Storage Calculator
You can calculate your PostgreSQL storage requirements by entering your known values in the middle section of the calculator settings below:
{{< database-calculator >}}