diff --git a/ydb/docs/en/core/postgresql/docker-connect.md b/ydb/docs/en/core/postgresql/docker-connect.md index bb38da552a13..e4d97a9fc178 100644 --- a/ydb/docs/en/core/postgresql/docker-connect.md +++ b/ydb/docs/en/core/postgresql/docker-connect.md @@ -1,5 +1,7 @@ # Connecting via PostgreSQL Protocol +{% include [./_includes/alert.md](./_includes/alert_preview.md) %} + ## Running {{ ydb-short-name }} with PostgreSQL compatibility enabled Currently, the PostgreSQL compatibility feature is available for testing in the Docker image: `ghcr.io/ydb-platform/local-ydb:nightly`. diff --git a/ydb/docs/en/core/postgresql/functions.md b/ydb/docs/en/core/postgresql/functions.md index 41e3bb70f9d4..a9f7f03873f2 100644 --- a/ydb/docs/en/core/postgresql/functions.md +++ b/ydb/docs/en/core/postgresql/functions.md @@ -1,5 +1,7 @@ # PostgreSQL functions +{% include [./_includes/alert.md](./_includes/alert_preview.md) %} + 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. {% include [functions](./_includes/functions.md) %} diff --git a/ydb/docs/en/core/postgresql/import.md b/ydb/docs/en/core/postgresql/import.md index b8a8a5541411..bc1daeb76d58 100644 --- a/ydb/docs/en/core/postgresql/import.md +++ b/ydb/docs/en/core/postgresql/import.md @@ -1,5 +1,7 @@ # Dump data form PostgreSQL +{% include [./_includes/alert.md](./_includes/alert_preview.md) %} + 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). 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 * Deleting the `WITH (...)` section in `CREATE TABLE`. * Commenting out unsupported constructs (optionally): - * `SELECT pg_catalog.set_config.*` - * `ALTER TABLE` + * `SELECT pg_catalog.set_config.*` + * `ALTER TABLE` 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. @@ -60,26 +62,46 @@ As an example, data generated by [pgbench](https://www.postgresql.org/docs/curre 1. Start Docker containers with PostgreSQL and {{ ydb-short-name }}: - ```bash - docker run -d --rm -e POSTGRES_USER=root -e POSTGRES_PASSWORD=1234 \ - -e POSTGRES_DB=local --name postgres postgres:14 - docker run --name ydb-postgres -d --pull always -p 5432:5432 -p 8765:8765 \ - -e POSTGRES_USER=root -e POSTGRES_PASSWORD=1234 \ - -e YDB_FEATURE_FLAGS=enable_temp_tables \ - -e YDB_USE_IN_MEMORY_PDISKS=true \ - ghcr.io/ydb-platform/ydb-local:latest - ``` + ```bash + docker run --name postgres_container \ + -e POSTGRES_USER=pgroot -e POSTGRES_PASSWORD=1234 \ + -e POSTGRES_DB=local \ + -p 5433:5433 -d postgres:14 -c 'port=5433' + docker run --name ydb-postgres -d --pull always -p 5432:5432 -p 8765:8765 \ + -e POSTGRES_USER=ydbroot -e POSTGRES_PASSWORD=4321 \ + -e YDB_FEATURE_FLAGS=enable_temp_tables,enable_table_pg_types \ + -e YDB_USE_IN_MEMORY_PDISKS=true \ + ghcr.io/ydb-platform/local-ydb:latest + ``` + + Information about the started Docker containers: + + #| + || Database | PostgreSQL | YDB || + || Container name | postgres_container | ydb-postgres || + || Address | postgres://pgroot:1234@localhost:5433/local | postgresql://ydbroot:4321@localhost:5432/local || + || Port | 5433 | 5432 || + || User name | pgroot | ydbroot || + || Password | 1234 | 4321 || + |# 2. Generate data through [pgbench](https://www.postgresql.org/docs/current/pgbench.html): - ```bash - docker exec postgres pgbench -i postgres://root:1234@localhost/local - ``` + ```bash + docker exec postgres_container pgbench postgres://pgroot:1234@localhost:5433/local -i + ``` + +3. Create a dump of the database using [pg_dump](https://www.postgresql.org/docs/current/app-pgdump.html): + + ```bash + docker exec postgres_container pg_dump postgres://pgroot:1234@localhost:5433/local --inserts \ + --column-inserts --encoding=utf_8 --rows-per-insert=1000 > dump.sql + ``` + +4. Load the dump into {{ ydb-short-name }}: -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 }}: + ```bash + ydb tools pg-convert --ignore-unsupported -i dump.sql | psql postgresql://ydbroot:4321@localhost:5432/local + ``` - ```bash - docker exec postgres pg_dump -U root --format=c --file=/var/lib/postgresql/data/dump.sql local - docker cp postgres:/var/lib/postgresql/data/dump.sql . - cat dump.sql | docker exec -i ydb-postgres psql -U root -d local - ``` + This command uses {{ ydb-short-name }} CLI to convert the dump.sql file to the format readable by the {{ ydb-short-name }} PostgreSQL compatibility layer. The converted dump file is then redirected to the `psql` utility for loading the data into {{ ydb-short-name }} via PostgreSQL protocol. \ No newline at end of file diff --git a/ydb/docs/ru/core/postgresql/functions.md b/ydb/docs/ru/core/postgresql/functions.md index b70aa9df2ee4..f6f9bada2acf 100644 --- a/ydb/docs/ru/core/postgresql/functions.md +++ b/ydb/docs/ru/core/postgresql/functions.md @@ -1,5 +1,7 @@ # PostgreSQL функции +{% include [./_includes/alert.md](./_includes/alert_preview.md) %} + В данном разделе содержатся PostgreSQL функции, поддерживаемые в режиме совместимости {{ ydb-short-name }} с PostgreSQL. В разделе сохранены оригинальная структура документации PostgreSQL и примеры применения функций. Данная статья автоматически пополняется и тестируется, поэтому текст представлен только на английском языке. {% include [functions](./_includes/functions.md) %} \ No newline at end of file diff --git a/ydb/docs/ru/core/postgresql/import.md b/ydb/docs/ru/core/postgresql/import.md index 9a4092dd3657..7df0ec2167e9 100644 --- a/ydb/docs/ru/core/postgresql/import.md +++ b/ydb/docs/ru/core/postgresql/import.md @@ -1,5 +1,7 @@ # Импорт данных из PostgreSQL +{% include [./_includes/alert.md](./_includes/alert_preview.md) %} + Данные из PostgreSQL в {{ ydb-name }} можно импортировать различными способами: - С помощью [pg-dump](#pg-dump). @@ -78,25 +80,45 @@ 1. Поднять докер-контейнеры с PostgreSQL и {{ ydb-short-name }}: ```bash - docker run -d --rm -e POSTGRES_USER=root -e POSTGRES_PASSWORD=1234 \ - -e POSTGRES_DB=local --name postgres postgres:14 + docker run --name postgres_container \ + -e POSTGRES_USER=pgroot -e POSTGRES_PASSWORD=1234 \ + -e POSTGRES_DB=local \ + -p 5433:5433 -d postgres:14 -c 'port=5433' docker run --name ydb-postgres -d --pull always -p 5432:5432 -p 8765:8765 \ - -e POSTGRES_USER=root -e POSTGRES_PASSWORD=1234 \ - -e YDB_FEATURE_FLAGS=enable_temp_tables \ + -e POSTGRES_USER=ydbroot -e POSTGRES_PASSWORD=4321 \ + -e YDB_FEATURE_FLAGS=enable_temp_tables,enable_table_pg_types \ -e YDB_USE_IN_MEMORY_PDISKS=true \ - ghcr.io/ydb-platform/local-ydb:nightly + ghcr.io/ydb-platform/local-ydb:latest ``` + Информация по поднимаемым docker-контейнерам: + + #| + || База данных | PostgreSQL | YDB || + || Имя контейнера | postgres_container | ydb-postgres || + || Адрес | postgres://pgroot:1234@localhost:5433/local | postgresql://ydbroot:4321@localhost:5432/local || + || Порт | 5433 | 5432 || + || Имя пользователя | pgroot | ydbroot || + || Пароль | 1234 | 4321 || + |# + 2. Сгенерировать данные через [pgbench](https://www.postgresql.org/docs/current/pgbench.html): ```bash - docker exec postgres pgbench postgres://root:1234@localhost/local -i + docker exec postgres_container pgbench postgres://pgroot:1234@localhost:5433/local -i ``` -3. Сделать дамп базы через [pg_dump](https://www.postgresql.org/docs/current/app-pgdump.html) и загрузить его в {{ ydb-short-name }}: +3. Сделать дамп базы через [pg_dump](https://www.postgresql.org/docs/current/app-pgdump.html): ```bash - docker exec postgres pg_dump postgres://root:1234@localhost/local --inserts \ + docker exec postgres_container pg_dump postgres://pgroot:1234@localhost:5433/local --inserts \ --column-inserts --encoding=utf_8 --rows-per-insert=1000 > dump.sql - ydb tools pg-convert -i dump.sql | psql postgresql://root:1234@localhost/local ``` + +4. Загрузить дамп базы в {{ ydb-short-name }}: + + ```bash + ydb tools pg-convert --ignore-unsupported -i dump.sql | psql postgresql://ydbroot:4321@localhost:5432/local + ``` + + Эта команда использует {{ ydb-short-name }} CLI для преобразования файла `dump.sql` в формат, поддерживаемый {{ ydb-short-name }} в режиме совместимости с PostgreSQL. Затем преобразованный файл перенаправляется в утилиту `psql` для загрузки данных в {{ ydb-short-name }} по протоколу PostgreSQL. \ No newline at end of file