Database privileges
Document Engine connects to PostgreSQL with two kinds of accounts: one that runs database migrations, and one that its nodes use at runtime. They can be the same account. This guide describes the schema Document Engine uses and the privileges each account needs. For the connection and migration options, refer to the database options.
Database and schema
Use a PostgreSQL database dedicated to Document Engine. Document Engine stores its database objects in the public schema. A different schema can’t be configured.
Put public first on the search_path of the migration account, because Document Engine creates its tables in that schema. The account that Document Engine nodes connect as needs public on its search_path too.
Migration account
The account that runs migrations (PG_ADMIN_USER, or PGUSER when it’s not set) needs to:
- Use and create objects in the
publicschema. - Create temporary tables in the database.
- Own the existing Document Engine objects, or inherit the privileges of their owner, when it migrates an existing database.
- Create the PostgreSQL extensions that migrations install, unless they’re already installed (
pg_buffercache,pg_freespacemap,pgrowlocks,pg_stat_statements,pgstattuple,pg_visibility,btree_gist,btree_gin,intarray, anduuid-ossp). Migrations skippg_freespacemapandpg_visibilitywhen the server doesn’t offer them. On self-managed PostgreSQL, the first six require a superuser, and the others requireCREATEon the database. Managed database services have their own extension permissions. If the migration account can’t install them, a database administrator must install them in the Document Engine database before migration. - Create the database, if it doesn’t exist yet. This requires the
CREATEDBattribute and theen_US.UTF-8locale on the server. Otherwise, create the database yourself with UTF-8 encoding.
To check the schema and temporary table privileges, run this read-only query in the Document Engine database. Replace migrator with the migration account:
SELECT has_schema_privilege('migrator', 'public', 'USAGE') AND has_schema_privilege('migrator', 'public', 'CREATE') AS can_create_in_public, has_database_privilege('migrator', current_database(), 'TEMP') AS can_create_temp_tables;Both columns return true when the privileges are in place.
Runtime account
The intended runtime account is PGUSER. This is usually the same account as PG_OPERATION_USER, which defaults to PGUSER. If PG_ADMIN_USER and PG_ADMIN_PASSWORD are set on nodes that don’t run migrations, they override PGUSER and PGPASSWORD. The node then connects with the migration account’s credentials. The runtime account needs:
CONNECTon the database andUSAGEonpublic.SELECT,INSERT,UPDATE, andDELETEon Document Engine’s tables inpublic.SELECT,USAGE, andUPDATEon Document Engine’s sequences inpublic.EXECUTEon the functions Document Engine uses, such asuuid_generate_v4(), if you revoked it fromPUBLIC.
When you use a dedicated migration job (ENABLE_DATABASE_MIGRATIONS and EXIT_AFTER_DATABASE_MIGRATIONS set to true), schema migrations can complete before runtime privilege configuration fails. Before starting runtime nodes, make sure the runtime account has all the privileges listed above.