mirror of https://github.com/postgres/postgres
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.7 KiB
53 lines
1.7 KiB
![]()
2 years ago
|
# Test Transparent Data Encryption
|
||
|
|
||
![]()
10 months ago
|
Enabling `pg_tde` extension for a database creates the table access method `tde_heap` . This access method enables you to encrypt the data.
|
||
![]()
10 months ago
|
|
||
![]()
10 months ago
|
Here's how to do it:
|
||
![]()
2 years ago
|
|
||
![]()
10 months ago
|
1. Create a table in the database for which you have [enabled `pg_tde`](setup.md) using the `tde_heap` access method as follows:
|
||
![]()
11 months ago
|
|
||
![]()
10 months ago
|
```
|
||
![]()
10 months ago
|
CREATE TABLE <table_name> (<field> <datatype>) USING tde_heap;
|
||
|
```
|
||
![]()
11 months ago
|
|
||
![]()
10 months ago
|
<i warning>:material-information: Warning:</i> Example for testing purposes only:
|
||
|
|
||
![]()
10 months ago
|
```
|
||
![]()
10 months ago
|
CREATE TABLE albums (
|
||
|
album_id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||
|
artist_id INTEGER,
|
||
|
title TEXT NOT NULL,
|
||
|
released DATE NOT NULL
|
||
|
) USING tde_heap;
|
||
|
```
|
||
![]()
10 months ago
|
|
||
|
Learn more about table access methods and how you can enable data encryption by default in the [Table access methods](table-access-method.md) section.
|
||
![]()
10 months ago
|
|
||
![]()
10 months ago
|
2. To check if the data is encrypted, run the following function:
|
||
![]()
11 months ago
|
|
||
![]()
10 months ago
|
```
|
||
![]()
10 months ago
|
SELECT pg_tde_is_encrypted('table_name');
|
||
|
```
|
||
![]()
11 months ago
|
|
||
![]()
10 months ago
|
The function returns `t` if the table is encrypted and `f` - if not.
|
||
![]()
11 months ago
|
|
||
![]()
10 months ago
|
3. Rotate the principal key when needed:
|
||
![]()
11 months ago
|
|
||
![]()
10 months ago
|
```
|
||
![]()
10 months ago
|
SELECT pg_tde_rotate_principal_key(); -- uses automatic key versionin
|
||
|
-- or
|
||
|
SELECT pg_tde_rotate_principal_key('new-principal-key', NULL); -- specify new key name
|
||
|
-- or
|
||
|
SELECT pg_tde_rotate_principal_key('new-principal-key', 'new-provider'); -- changeprovider
|
||
|
```
|
||
![]()
11 months ago
|
|
||
![]()
10 months ago
|
4. You can encrypt an existing table. It requires rewriting the table, so for large tables, it might take a considerable amount of time.
|
||
![]()
10 months ago
|
|
||
![]()
10 months ago
|
```
|
||
![]()
10 months ago
|
ALTER TABLE table_name SET access method tde_heap;
|
||
|
```
|
||
|
|
||
![]()
11 months ago
|
!!! hint
|
||
|
|
||
![]()
10 months ago
|
If you no longer wish to use `pg_tde` or wish to switch to using the `tde_heap_basic` access method, see how you can [decrypt your data](decrypt.md).
|