-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostgresql.1
More file actions
553 lines (553 loc) · 13.2 KB
/
postgresql.1
File metadata and controls
553 lines (553 loc) · 13.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
.Dd April 1, 2025
.Dt PLAKAR-POSTGRESQL 1
.Os
.Sh NAME
.Nm plakar-postgresql
.Nd PostgreSQL backup and restoration connector for Plakar
.Sh DESCRIPTION
The
.Nm
integration package provides two independent backup strategies for PostgreSQL.
.Bl -tag -width "postgres+bin://"
.It Li postgres://
Logical backup and restore using
.Xr pg_dump 1 ,
.Xr pg_dumpall 1 ,
.Xr pg_restore 1 ,
and
.Xr psql 1 .
Produces portable, version-independent SQL dumps.
.It Li postgres+bin://
Physical backup using
.Xr pg_basebackup 1 .
Streams a binary copy of the entire PostgreSQL data directory.
Restore is performed by any file-restore connector.
.El
.Sh LOGICAL BACKUP
.Ss How it works
When a
.Ar database
is specified the source connector runs
.Xr pg_dump 1
.Fl F Ns Li c
to produce a custom-format dump
.Pq Li <dbname>.dump
and
.Xr pg_dumpall 1
.Fl -globals-only
to capture roles and tablespaces
.Pq Li globals.sql .
.Pp
When no database is specified the source connector runs
.Xr pg_dumpall 1
to produce a plain-SQL dump of every database on the server
.Pq Li all.sql ,
which already includes global objects.
.Pp
The destination connector dispatches on filename:
.Xr pg_restore 1
is used for
.Li .dump
files;
.Xr psql 1
is used for
.Li .sql
files.
.Ss Prerequisites
The following programs must be present in
.Ev PATH
on the machine running Plakar:
.Pp
.Bl -tag -width "pg_dumpall" -compact
.It pg_dump
Single-database backups.
.It pg_dumpall
Full-server backups and globals-only dumps.
.It pg_restore
Restoring single-database dumps.
.It psql
Restoring full-server dumps and connectivity checks.
.El
.Pp
The backup user should be a superuser so that
.Xr pg_dumpall 1
can read
.Li pg_authid
and include role passwords.
On managed services such as Amazon RDS the administrative user is a
restricted superuser that cannot read
.Li pg_authid .
The importer detects this automatically and falls back to
.Fl -no-role-passwords ,
and logs a warning.
The dump is otherwise complete, but restored roles will have no password set.
.Ss Source options
.Bl -tag -width "schema_only"
.It Ar location
Connection URI:
.Li postgres://[user[:password]@]host[:port][/database] .
.It Ar host
Server hostname (default:
.Li localhost ) .
Overrides the URI host.
.It Ar port
Server port (default:
.Li 5432 ) .
Overrides the URI port.
.It Ar username
Authentication username.
Overrides the URI user.
.It Ar password
Authentication password, passed via
.Ev PGPASSWORD .
Overrides the URI password.
.It Ar database
Database to back up.
If omitted, all databases are backed up via
.Xr pg_dumpall 1 .
Overrides the URI path.
.It Ar compress
Enable
.Xr pg_dump 1
compression (default:
.Li false ) .
Disabled by default so that Plakar's own compression operates on
uncompressed data.
.It Ar schema_only
Dump only the schema, no data (default:
.Li false ) .
Mutually exclusive with
.Ar data_only .
.It Ar data_only
Dump only the data, no schema (default:
.Li false ) .
Mutually exclusive with
.Ar schema_only .
.It Ar pg_bin_dir
Directory containing the PostgreSQL client binaries
.Pq pg_dump , pg_dumpall , psql .
When omitted, binaries are resolved via
.Ev PATH .
Useful when multiple PostgreSQL versions are installed.
.It Ar ssl_mode
SSL mode for the connection (default:
.Li prefer ) .
Accepted values:
.Li disable ,
.Li allow ,
.Li prefer ,
.Li require ,
.Li verify-ca ,
.Li verify-full .
Passed via
.Ev PGSSLMODE .
.It Ar ssl_cert
Path to the client SSL certificate file (PEM format).
Passed via
.Ev PGSSLCERT .
.It Ar ssl_cert_data
Inline PEM content of the client SSL certificate.
Alternative to
.Ar ssl_cert .
.It Ar ssl_key
Path to the client SSL private key file (PEM format).
Passed via
.Ev PGSSLKEY .
.It Ar ssl_key_data
Inline PEM content of the client SSL private key.
Alternative to
.Ar ssl_key .
.It Ar ssl_root_cert
Path to the root CA certificate used to verify the server (PEM format).
Passed via
.Ev PGSSLROOTCERT .
.It Ar ssl_root_cert_data
Inline PEM content of the root CA certificate.
Alternative to
.Ar ssl_root_cert .
.El
.Ss Destination options
.Bl -tag -width "no_globals"
.It Ar location
Connection URI:
.Li postgres://[user[:password]@]host[:port][/database] .
.It Ar host
Server hostname (default:
.Li localhost ) .
Overrides the URI host.
.It Ar port
Server port (default:
.Li 5432 ) .
Overrides the URI port.
.It Ar username
Authentication username.
Overrides the URI user.
.It Ar password
Authentication password, passed via
.Ev PGPASSWORD .
Overrides the URI password.
.It Ar database
Target database for
.Xr pg_restore 1 .
If omitted, the name is inferred from the dump filename.
See
.Ar create_db
for how this interacts with database creation.
.It Ar create_db
When
.Li false
(default),
.Fl d
names the target database, which must already exist.
When
.Li true ,
passes
.Fl C
to
.Xr pg_restore 1
so the database is created from the archive metadata;
.Fl d
then names only the initial connection database (defaults to
.Li postgres
if unset).
.It Ar no_globals
When
.Li true ,
skips feeding the globals file
.Li ( globals.sql
or
.Li 00000-globals.sql )
to
.Xr psql 1 .
By default globals are restored automatically when present (default:
.Li false ) .
.It Ar no_owner
Pass
.Fl -no-owner
to
.Xr pg_restore 1 ,
skipping
.Li ALTER OWNER
statements (default:
.Li false ) .
.It Ar exit_on_error
Stop on the first restore error (default:
.Li false ) .
Passes
.Fl e
to
.Xr pg_restore 1
and
.Li ON_ERROR_STOP=1
to
.Xr psql 1 .
.It Ar schema_only
Restore only the schema, no data (default:
.Li false ) .
Mutually exclusive with
.Ar data_only .
Not applicable to
.Xr pg_dumpall 1
restores.
.It Ar data_only
Restore only the data, no schema (default:
.Li false ) .
Mutually exclusive with
.Ar schema_only .
Not applicable to
.Xr pg_dumpall 1
restores.
.It Ar pg_bin_dir
Directory containing the PostgreSQL client binaries
.Pq pg_restore , psql .
When omitted, binaries are resolved via
.Ev PATH .
Useful when multiple PostgreSQL versions are installed.
.It Ar ssl_mode
SSL mode for the connection (default:
.Li prefer ) .
Accepted values:
.Li disable ,
.Li allow ,
.Li prefer ,
.Li require ,
.Li verify-ca ,
.Li verify-full .
Passed via
.Ev PGSSLMODE .
.It Ar ssl_cert
Path to the client SSL certificate file (PEM format).
Passed via
.Ev PGSSLCERT .
.It Ar ssl_cert_data
Inline PEM content of the client SSL certificate.
Alternative to
.Ar ssl_cert .
.It Ar ssl_key
Path to the client SSL private key file (PEM format).
Passed via
.Ev PGSSLKEY .
.It Ar ssl_key_data
Inline PEM content of the client SSL private key.
Alternative to
.Ar ssl_key .
.It Ar ssl_root_cert
Path to the root CA certificate used to verify the server (PEM format).
Passed via
.Ev PGSSLROOTCERT .
.It Ar ssl_root_cert_data
Inline PEM content of the root CA certificate.
Alternative to
.Ar ssl_root_cert .
.El
.Sh MANIFEST
Every snapshot produced by this integration contains a
.Pa /manifest.json
record (schema version 2) written before the backup data begins.
It captures the cluster state at the moment the backup was initiated.
.Pp
Top-level fields include the server version, host, port,
.Li pg_dump_version
.Pq logical backups ,
.Li pg_basebackup_version
.Pq physical backups ,
.Li cluster_system_identifier
.Pq unique cluster ID from pg_control_system() ,
.Li in_recovery
.Pq true when backup was taken from a hot standby ,
target database, dump format, and backup options.
.Bl -tag -width "cluster_config"
.It Li cluster_config
Key server GUCs:
.Li data_directory ,
.Li timezone ,
.Li max_connections ,
.Li wal_level ,
.Li server_encoding ,
.Li data_checksums ,
.Li block_size ,
.Li wal_block_size ,
.Li shared_preload_libraries ,
.Li lc_collate ,
.Li lc_ctype ,
.Li archive_mode ,
.Li archive_command_set
.Pq boolean; the command itself is not stored to avoid leaking credentials .
.It Li roles
All PostgreSQL roles with:
.Li superuser ,
.Li replication ,
.Li can_login ,
.Li create_db ,
.Li create_role ,
.Li inherit ,
.Li bypass_rls ,
.Li connection_limit ,
.Li valid_until ,
and
.Li member_of
.Pq list of parent roles .
.It Li tablespaces
All tablespaces with name, owner, filesystem location, and storage options.
.It Li databases
One entry per database: name, owner, encoding, collation,
.Li default_tablespace ,
.Li connection_limit ,
installed extensions
.Pq name, version, schema ,
schemas
.Pq name, owner ,
and a
.Li relations
array.
.It Li relations
One entry per relation (ordinary table, partitioned table, foreign table,
view, materialized view, sequence).
Each entry carries: schema, name, owner, persistence, kind, tablespace,
row estimates
.Pq Li row_estimate No from Li reltuples No and Li live_row_estimate No from autovacuum ,
column count, primary-key and trigger flags, row-level security flags,
partitioning metadata
.Pq Li is_partition No / Li partition_parent No / Li partition_strategy ,
storage options
.Pq reloptions ,
last vacuum and analyze timestamps,
.Li columns
.Pq position, name, type, nullable, default ,
.Li constraints
.Pq name, type code, column names ,
and
.Li indexes
.Pq name, method, definition, is_unique, is_primary, is_valid, is_partial, constraint_name .
.El
.Pp
Row counts are estimates from
.Li reltuples
.Pq pg_class
and
.Li n_live_tup
.Pq pg_stat_user_tables ,
not exact values.
Exact counts would require a full sequential scan of every table.
.Pp
Metadata collection is best-effort: if a query fails the affected field is
omitted and the backup continues normally.
.Sh PHYSICAL BACKUP
.Ss How it works
The source connector runs
.Xr pg_basebackup 1
.Fl D Fl Li - Fl F Li tar Fl X Li fetch ,
streaming a tar archive of the entire PostgreSQL data directory directly
from the server's replication interface.
Each file in the archive is stored as an individual record under
.Li data/
in the snapshot.
.Pp
No subpath may be specified in the URI:
.Xr pg_basebackup 1
always backs up the entire cluster.
.Pp
A
.Pa /manifest.json
record is written to the snapshot before the backup stream begins.
It contains the same full metadata as a logical backup: cluster config,
roles, tablespaces, database list, and per-database relation detail
.Pq schemas, tables, columns, indexes .
The
.Li pg_basebackup_version
field records the version of
.Xr pg_basebackup 1
used.
.Pp
There is no dedicated destination connector.
The snapshot contains plain files and can be restored with any
file-restore connector.
The restored directory is a valid PostgreSQL data directory that can be
started directly with a PostgreSQL binary of the same major version.
.Ss Prerequisites
.Xr pg_basebackup 1
must be present in
.Ev PATH .
The PostgreSQL server must have:
.Bl -bullet -compact
.It
.Li wal_level = replica
or higher in
.Pa postgresql.conf .
.It
A user with the
.Li REPLICATION
privilege (or a superuser).
.It
.Pa pg_hba.conf
allowing a replication connection from the backup host.
.El
.Ss Source options
.Bl -tag -width "pg_basebackup"
.It Ar location
Connection URI:
.Li postgres+bin://[user[:password]@]host[:port] .
A subpath is not allowed.
.It Ar host
Server hostname (default:
.Li localhost ) .
Overrides the URI host.
.It Ar port
Server port (default:
.Li 5432 ) .
Overrides the URI port.
.It Ar username
Replication username.
Overrides the URI user.
.It Ar password
Authentication password, passed via
.Ev PGPASSWORD .
Overrides the URI password.
.It Ar pg_bin_dir
Directory containing the PostgreSQL client binaries
.Pq pg_basebackup , psql .
When omitted, binaries are resolved via
.Ev PATH .
Useful when multiple PostgreSQL versions are installed.
.It Ar ssl_mode
SSL mode for the connection (default:
.Li prefer ) .
Accepted values:
.Li disable ,
.Li allow ,
.Li prefer ,
.Li require ,
.Li verify-ca ,
.Li verify-full .
Passed via
.Ev PGSSLMODE .
.It Ar ssl_cert
Path to the client SSL certificate file (PEM format).
Passed via
.Ev PGSSLCERT .
.It Ar ssl_cert_data
Inline PEM content of the client SSL certificate.
Alternative to
.Ar ssl_cert .
.It Ar ssl_key
Path to the client SSL private key file (PEM format).
Passed via
.Ev PGSSLKEY .
.It Ar ssl_key_data
Inline PEM content of the client SSL private key.
Alternative to
.Ar ssl_key .
.It Ar ssl_root_cert
Path to the root CA certificate used to verify the server (PEM format).
Passed via
.Ev PGSSLROOTCERT .
.It Ar ssl_root_cert_data
Inline PEM content of the root CA certificate.
Alternative to
.Ar ssl_root_cert .
.El
.Sh EXAMPLES
Back up a single database:
.Bd -literal -offset indent
$ plakar source add mypg postgres://postgres:secret@db.example.com/myapp
$ plakar backup @mypg
.Ed
.Pp
Back up all databases:
.Bd -literal -offset indent
$ plakar source add mypg postgres://postgres:secret@db.example.com
$ plakar backup @mypg
.Ed
.Pp
Restore a single database (created automatically from archive metadata):
.Bd -literal -offset indent
$ plakar destination add mypgdst postgres://postgres:secret@db.example.com \e
create_db=true
$ plakar restore -to @mypgdst <snapid>
.Ed
.Pp
Restore all databases to a fresh server:
.Bd -literal -offset indent
$ plakar destination add mypgdst postgres://postgres:secret@db.example.com
$ plakar restore -to @mypgdst <snapid>
.Ed
.Pp
Physical backup of the entire cluster:
.Bd -literal -offset indent
$ plakar source add mypg postgres+bin://replicator:secret@db.example.com
$ plakar backup @mypg
.Ed
.Pp
Restore a physical backup to a local directory and start with Docker:
.Bd -literal -offset indent
$ plakar restore -to ./pgdata <snapid>
$ docker run --rm \e
-v "$PWD/pgdata:/var/lib/postgresql/data" \e
postgres:17
.Ed
.Sh SEE ALSO
.Xr pg_basebackup 1 ,
.Xr pg_dump 1 ,
.Xr pg_dumpall 1 ,
.Xr pg_restore 1 ,
.Xr psql 1