Skip to content

Commit 92e07cf

Browse files
authored
Merge d64c0ab into 45f8fc2
2 parents 45f8fc2 + d64c0ab commit 92e07cf

File tree

5 files changed

+53
-29
lines changed

5 files changed

+53
-29
lines changed

ydb/docs/en/core/postgresql/docker-connect.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Connecting via PostgreSQL Protocol
22

3+
{% include [./_includes/alert.md](./_includes/alert_preview.md) %}
4+
35
## Running {{ ydb-short-name }} with PostgreSQL compatibility enabled
46

57
Currently, the PostgreSQL compatibility feature is available for testing in the Docker image: `ghcr.io/ydb-platform/local-ydb:nightly`.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# PostgreSQL functions
22

3+
{% include [./_includes/alert.md](./_includes/alert_preview.md) %}
4+
35
This section contains PostgreSQL functions supported in the {{ ydb-short-name }} mode of compatibility with PostgreSQL. The original structure of the PostgreSQL documentation and examples of function application are preserved in the section. This article is automatically supplemented and tested.
46

57
{% include [functions](./_includes/functions.md) %}

ydb/docs/en/core/postgresql/import.md

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Dump data form PostgreSQL
22

3+
{% include [./_includes/alert.md](./_includes/alert_preview.md) %}
4+
35
Data from PostgreSQL can be migrated to {{ ydb-short-name }} using utilities such as [pg_dump](https://www.postgresql.org/docs/current/app-pgdump.html), [psql](https://www.postgresql.org/docs/current/app-psql.html), and [{{ ydb-short-name }} CLI](../reference/ydb-cli/index.md). The [pg_dump](https://www.postgresql.org/docs/current/app-pgdump.html) and [psql](https://www.postgresql.org/docs/current/app-psql.html) utilities are installed with PostgreSQL. [{{ ydb-short-name }} CLI](../reference/ydb-cli/index.md) is {{ ydb-short-name }}'s command-line client, which is [installed separately](../reference/ydb-cli/install.md).
46

57
To do this, you need to:
@@ -26,8 +28,8 @@ The `ydb tools pg-convert` command reads a dump file or standard input created b
2628
* Deleting the `WITH (...)` section in `CREATE TABLE`.
2729
* Commenting out unsupported constructs (optionally):
2830

29-
* `SELECT pg_catalog.set_config.*`
30-
* `ALTER TABLE`
31+
* `SELECT pg_catalog.set_config.*`
32+
* `ALTER TABLE`
3133

3234
If the CLI cannot find a table's primary key, it will automatically create a [BIGSERIAL](https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-SERIAL) column named `__ydb_stub_id` as the primary key.
3335

@@ -60,26 +62,33 @@ As an example, data generated by [pgbench](https://www.postgresql.org/docs/curre
6062

6163
1. Start Docker containers with PostgreSQL and {{ ydb-short-name }}:
6264

63-
```bash
64-
docker run -d --rm -e POSTGRES_USER=root -e POSTGRES_PASSWORD=1234 \
65-
-e POSTGRES_DB=local --name postgres postgres:14
66-
docker run --name ydb-postgres -d --pull always -p 5432:5432 -p 8765:8765 \
67-
-e POSTGRES_USER=root -e POSTGRES_PASSWORD=1234 \
68-
-e YDB_FEATURE_FLAGS=enable_temp_tables \
69-
-e YDB_USE_IN_MEMORY_PDISKS=true \
70-
ghcr.io/ydb-platform/ydb-local:latest
71-
```
65+
```bash
66+
docker run --name postgres_container \
67+
-e POSTGRES_USER=pgroot -e POSTGRES_PASSWORD=1234 \
68+
-e POSTGRES_DB=local \
69+
-p 5433:5433 -d postgres:14 -c 'port=5433'
70+
docker run --name ydb-postgres -d --pull always -p 5432:5432 -p 8765:8765 \
71+
-e POSTGRES_USER=ydbroot -e POSTGRES_PASSWORD=4321 \
72+
-e YDB_FEATURE_FLAGS=enable_temp_tables,enable_table_pg_types \
73+
-e YDB_USE_IN_MEMORY_PDISKS=true \
74+
ghcr.io/ydb-platform/local-ydb:latest
75+
```
7276

7377
2. Generate data through [pgbench](https://www.postgresql.org/docs/current/pgbench.html):
7478

75-
```bash
76-
docker exec postgres pgbench -i postgres://root:1234@localhost/local
77-
```
79+
```bash
80+
docker exec postgres_container pgbench postgres://pgroot:1234@localhost:5433/local -i
81+
```
82+
83+
3. Create a dump of the database using [pg_dump](https://www.postgresql.org/docs/current/app-pgdump.html):
84+
85+
```bash
86+
docker exec postgres_container pg_dump postgres://pgroot:1234@localhost:5433/local --inserts \
87+
--column-inserts --encoding=utf_8 --rows-per-insert=1000 > dump.sql
88+
```
7889

79-
3. Create a dump of the database using [pg_dump](https://www.postgresql.org/docs/current/app-pgdump.html) and load it into {{ ydb-short-name }}:
90+
4. Load the dump into {{ ydb-short-name }}:
8091

81-
```bash
82-
docker exec postgres pg_dump -U root --format=c --file=/var/lib/postgresql/data/dump.sql local
83-
docker cp postgres:/var/lib/postgresql/data/dump.sql .
84-
cat dump.sql | docker exec -i ydb-postgres psql -U root -d local
85-
```
92+
```bash
93+
ydb tools pg-convert --ignore-unsupported -i dump.sql | psql postgresql://ydbroot:4321@localhost:5432/local
94+
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# PostgreSQL функции
22

3+
{% include [./_includes/alert.md](./_includes/alert_preview.md) %}
4+
35
В данном разделе содержатся PostgreSQL функции, поддерживаемые в режиме совместимости {{ ydb-short-name }} с PostgreSQL. В разделе сохранены оригинальная структура документации PostgreSQL и примеры применения функций. Данная статья автоматически пополняется и тестируется, поэтому текст представлен только на английском языке.
46

57
{% include [functions](./_includes/functions.md) %}

ydb/docs/ru/core/postgresql/import.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Импорт данных из PostgreSQL
22

3+
{% include [./_includes/alert.md](./_includes/alert_preview.md) %}
4+
35
Данные из PostgreSQL в {{ ydb-name }} можно импортировать различными способами:
46

57
- С помощью [pg-dump](#pg-dump).
@@ -78,25 +80,32 @@
7880
1. Поднять докер-контейнеры с PostgreSQL и {{ ydb-short-name }}:
7981

8082
```bash
81-
docker run -d --rm -e POSTGRES_USER=root -e POSTGRES_PASSWORD=1234 \
82-
-e POSTGRES_DB=local --name postgres postgres:14
83+
docker run --name postgres_container \
84+
-e POSTGRES_USER=pgroot -e POSTGRES_PASSWORD=1234 \
85+
-e POSTGRES_DB=local \
86+
-p 5433:5433 -d postgres:14 -c 'port=5433'
8387
docker run --name ydb-postgres -d --pull always -p 5432:5432 -p 8765:8765 \
84-
-e POSTGRES_USER=root -e POSTGRES_PASSWORD=1234 \
85-
-e YDB_FEATURE_FLAGS=enable_temp_tables \
88+
-e POSTGRES_USER=ydbroot -e POSTGRES_PASSWORD=4321 \
89+
-e YDB_FEATURE_FLAGS=enable_temp_tables,enable_table_pg_types \
8690
-e YDB_USE_IN_MEMORY_PDISKS=true \
87-
ghcr.io/ydb-platform/local-ydb:nightly
91+
ghcr.io/ydb-platform/local-ydb:latest
8892
```
8993

9094
2. Сгенерировать данные через [pgbench](https://www.postgresql.org/docs/current/pgbench.html):
9195

9296
```bash
93-
docker exec postgres pgbench postgres://root:1234@localhost/local -i
97+
docker exec postgres_container pgbench postgres://pgroot:1234@localhost:5433/local -i
9498
```
9599

96-
3. Сделать дамп базы через [pg_dump](https://www.postgresql.org/docs/current/app-pgdump.html) и загрузить его в {{ ydb-short-name }}:
100+
3. Сделать дамп базы через [pg_dump](https://www.postgresql.org/docs/current/app-pgdump.html):
97101

98102
```bash
99-
docker exec postgres pg_dump postgres://root:1234@localhost/local --inserts \
103+
docker exec postgres_container pg_dump postgres://pgroot:1234@localhost:5433/local --inserts \
100104
--column-inserts --encoding=utf_8 --rows-per-insert=1000 > dump.sql
101-
ydb tools pg-convert -i dump.sql | psql postgresql://root:1234@localhost/local
102105
```
106+
107+
4. Загрузить дамп базы в {{ ydb-short-name }}:
108+
109+
```bash
110+
ydb tools pg-convert --ignore-unsupported -i dump.sql | psql postgresql://ydbroot:4321@localhost:5432/local
111+
```

0 commit comments

Comments
 (0)