PostgreSQL
Specific configuration for PostgreSQL.
PostgreSQL is fully supported by the Portabase agent. We use native pg_dump tools to ensure consistent and reliable backups.
Two modes are available:
postgresql: Single database backup usingpg_dump. Targets one specific database.postgresql-cluster: Full cluster backup usingpg_dumpall. Dumps every database in the instance plus global objects (roles, ownership, grants, tablespaces). Useful when advanced roles and ownership are configured at the cluster level.
Configuration
When running portabase db add, select postgresql as the database type.
Specific parameters asked:
- Database Name: The exact name of the database to backup (e.g.,
app_db). Unlike other engines, you must target a specific database.
In your databases.json (or .toml) file, configure the following block.
{
"name": "Database - PostgreSQL",
"type": "postgresql",
"host": "postgres",
"port": 5432,
"username": "postgres",
"password": "mysecretpassword",
"database": "app_db",
"generated_id": "..."
}Generating...Specific Parameters:
- database: (Required) The exact name of the database to dump.
Options
The following optional fields can be set under an options key in the database configuration.
| Option | Type | Default | Description |
|---|---|---|---|
keep_ownership | boolean | false | When true, omits --no-owner and --no-privileges from the dump. Ownership and role assignments are preserved in the output. By default these flags are applied, keeping restores portable across different users and environments, for example, when migrating from one database instance to another. |
{
"name": "Database - PostgreSQL",
"type": "postgresql",
"host": "postgres",
"port": 5432,
"username": "postgres",
"password": "mysecretpassword",
"database": "app_db",
"generated_id": "...",
"options": {
"keep_ownership": true
}
}Cluster Backup (pg_dumpall)
Use the cluster mode when you need to back up the entire instance: all databases together with global objects such as roles, ownership and grants. This is the recommended choice when advanced roles and ownership are configured at the database cluster level, since a single pg_dump does not capture cluster-wide global objects.
User specified in the configuration must be a superadmin for pg_dumpall to dump all databases and global objects.
When running portabase db add, select postgresql-cluster as the database type.
Specific parameters asked:
- Database Name: The exact name of the database to backup (e.g.,
app_db). Unlike other engines, you must target a specific database.
In your databases.json (or .toml) file, configure the following block.
{
"name": "Database - PostgreSQL Cluster",
"type": "postgresql-cluster",
"host": "postgres",
"port": 5432,
"username": "postgres",
"password": "mysecretpassword",
"database": "app_db",
"generated_id": "..."
}Generating...Specific Parameters:
- username: (Required) Must be a superuser to dump all databases and global objects.
- database: (Optional) The connection database used to run
pg_dumpall. Defaults to"postgres"if omitted. This does not limit the dump scope —pg_dumpallalways dumps every database in the instance regardless of this value.
Cluster backups can be significantly larger and slower than single-database backups, since every database in the instance is included. Restoring a pg_dumpall output recreates roles and ownership globally.
Docker Compose Example
Here is how to configure a PostgreSQL service alongside the agent.
services:
postgres:
image: postgres:15-alpine
container_name: my-postgres
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: mysecretpassword
POSTGRES_DB: app_db
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- portabase
agent:
image: portabase/agent:latest
# ... agent configuration ...
depends_on:
- postgres
networks:
- portabase
networks:
portabase:
external: true
volumes:
postgres_data:Note that in this example, the host (host) to enter in the agent configuration will be postgres (the service name), not localhost.
Last updated on