Сервис базы данных
Сервисы/PostgreSQL (PostGIS)

Сервис PostgreSQL (PostGIS)

Самостоятельно размещаемый сервис базы данных PostgreSQL с расширениями PostGIS для геопространственных данных и пространственных запросов внутри стека.

Вы добавляете этот сервис в стек и выбираете там его версию и ресурсы. Каждое окружение может их переопределить.

В StackMaster

Как PostgreSQL (PostGIS) работает в StackMaster

What Wodby and the image set up for this database service. Check it before creating databases, roles or extensions by hand, or adding connection settings to an application.

Database, user and passwords

Wodby manages the database and its user; the application does not create them.

  • One database and one user are created for the environment, both named after the application and the environment. The database is UTF8 with the en_US.utf8 locale.
  • The user's password and the password of the administrator postgres are generated once per environment (tokens password and root_password).
  • Further databases and users are added on Wodby, which runs the same create and grant actions. A role created by hand with a name Wodby later needs, but another password, makes the create action fail rather than replace it.

Ownership inside a database

Each managed database is owned by its own role named <database>:owner, which cannot log in. Granting a user access makes it a member of that role, and the user's sessions in that database act as that role. What follows from it:

  • Objects are created in the public schema and belong to the owner role, whichever user created them. All users granted access to the database share its data.
  • In such a session current_user is the owner role; session_user is the user that logged in. Code that compares current_user with the login name sees the owner role instead.
  • Only users granted access can connect to the database.
  • A backup carries no role names and no grants, so it can be imported into a database with another name and other users.

How a linked service reaches it

  • Host: the name of this app service inside the environment. Port: 5432.
  • A service linked to this one receives the host, port, database name, user name and password as environment variables defined by its own link (for example DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD on the PHP service). Read those in the application; do not hardcode them and do not connect as postgres from the application.

Extensions

Wodby creates extensions as the administrator. POSTGRES_DB_EXTENSIONS on this service is a comma-separated list of extensions created in a database when Wodby creates it. pgvector is bundled in the image but not enabled: add vector to that list. The label pgvector on the service means the library is present, not that the extension exists in the database.

Server configuration

The container writes /etc/postgresql/postgresql.conf on every start from a template and environment variables. Two ways to change settings, neither of them editing the generated file:

  • Set a variable on this service: POSTGRES_MAX_CONNECTIONS, POSTGRES_SHARED_BUFFERS, POSTGRES_WORK_MEM, POSTGRES_MAINTENANCE_WORK_MEM, POSTGRES_EFFECTIVE_CACHE_SIZE, POSTGRES_MAX_WAL_SIZE, POSTGRES_TIMEZONE, POSTGRES_SHARED_PRELOAD_LIBRARIES.
  • Set the setting Max prepared transactions (POSTGRES_MAX_PREPARED_TRANSACTIONS, default 0) above 0 for applications that use two-phase commit (PREPARE TRANSACTION). PostgreSQL restarts to apply it.
  • Override the service's config file config ("PostgreSQL config"), which replaces the template, for a setting no variable covers.

A change applies with the next deployment of the service. The service runs a single instance.

Data, backups and imports

  • Data is on the data volume.
  • The backup is a gzipped SQL dump of the environment's database. Tables matching its "excluded table contents" option keep their definition and lose their rows.
  • The database import replaces the data volume: the dump is loaded while a new, empty data directory is initialized, and the imported objects are handed to the database's owner role. It accepts .gz, .tar.gz, .tgz and .zip. Roles a dump names that this server does not have exist only while the dump is loaded.

Check the result

In the database container:

  • PGPASSWORD="$POSTGRES_PASSWORD" psql -h localhost -U postgres -c '\l' lists the databases and their owner roles.
  • PGPASSWORD="$POSTGRES_PASSWORD" psql -h localhost -U postgres -d <database> -c '\dx' lists the extensions in a database.

PostgreSQL (PostGIS) on Wodby

What this service adds to the PostgreSQL service it is based on.

  • The image bundles PostGIS, and POSTGRES_DB_EXTENSIONS has a default: postgis, postgis_raster, postgis_sfcgal, fuzzystrmatch, address_standardizer, address_standardizer_data_us, postgis_tiger_geocoder and postgis_topology. These extensions are created in a database when Wodby creates it; the application does not run CREATE EXTENSION postgis.
  • Setting POSTGRES_DB_EXTENSIONS on this service replaces the whole default list. To add an extension such as vector, repeat the PostGIS extensions that are needed and append it.

Everything else, including the database, user, ownership, configuration, backups and imports, is as in the PostgreSQL service.

Check the result

In the database container, PGPASSWORD="$POSTGRES_PASSWORD" psql -h localhost -U postgres -d <database> -c 'SELECT postgis_full_version();' shows the PostGIS version in a database.

Обзор

Технический профиль PostgreSQL (PostGIS)

Здесь перечислены версии, которые можно выбрать для PostgreSQL (PostGIS) в стеке или окружении. Сам сервис публикуется ревизиями, и стек ссылается на конкретную ревизию.

Тип сервиса

Сервис базы данных

Версии

18, 17

Постоянные тома

Data

Стеки

Стеки, в которые входит PostgreSQL (PostGIS)

PostgreSQL (PostGIS) входит в этот публичный стек. Можно создать приложение из публичного стека как есть или добавить сервис в собственный стек.

Данные

Резервные копии и импорт данных: PostgreSQL (PostGIS)

Сервис PostgreSQL (PostGIS) определяет, как создаются резервные копии его данных и как они импортируются. Резервное копирование и импорт запускаются из окружения, которому принадлежит сервис.

Резервные копии вручную и по расписанию

Создавайте резервную копию, когда она нужна, или задайте расписание в пресете резервного копирования.

Импорт из архива, по URL или из резервной копии

Источником импорта может быть загруженный архив, публичный URL или готовая резервная копия совместимого сервиса.

Где хранятся архивы

StackMaster записывает каждый архив в StackMaster Blob Storage или в бакет у провайдера хранилища, подключённого как интеграция.

Конфигурация

Конфигурация сервиса PostgreSQL (PostGIS)

Сервис PostgreSQL (PostGIS) объявляет следующее. Если значение можно изменить, его задаёт стек, а каждое окружение может его переопределить.

Тома

Data

Файлы конфигурации

2 файла конфигурации, которые стек или окружение могут переопределить.

Настройки

1 настройка, которую стек или окружение могут изменить.

Связанные базы данных

Связанные сервисы баз данных

Эти сервисы баз данных относятся к тому же семейству, что и PostgreSQL (PostGIS). Ссылки открывают их страницы баз данных.