Use this guide when you still have a single database directory (for example base/15647) or when the PostgreSQL instance cannot start. PDU can read that directory directly to export your data without launching PostgreSQL.
When to Use This Method
Only a single database directory remains (for example base/15647) and you need to export its data
The PostgreSQL instance cannot start, and you need to unload data from the affected database
The database directory files are still accessible on disk
Use the restore db command to initialize a specific database directory for recovery:
Command Syntax:
restore db <database_name> <path>;
Example:
PDU.public=# restore db mydb /home/pg/data/base/24576;[Initializing] Restoring the table structure for database 'mydb'... -pg_schema:</home/pg/data/base/24576/2615> -pg_class:</home/pg/data/base/24576/1259> Total 11213 rows -pg_attribute:</home/pg/data/base/24576/1249> Total 189519 rows Schemas: ▌ public 1071 tablesTable bak_sys_config is missing column information ▌ app 193 tables ▌ sales 66 tables ▌ demo 10 tables ▌ hr 221 tables ▌ finance 90 tables
Directory Conflict
If a directory with the same database name already exists under PDU, you'll see this error:
PDU.public=# restore db mydb /home/pg/data/base/24576;
Path <mydb> is not empty. Please confirm the input format is `restore db database_name path_name`,
or delete the folder <mydb> under PDU.
Solution: Manually delete or rename the existing directory before proceeding.
When PDU exports a schema, it generates three types of files:
CSV Data Files
Contains the actual table data
mydb/public/*.csv0
COPY Statements
SQL commands to import CSV data
mydb/COPY/public_copy.sql
DDL Statements
CREATE TABLE statements
mydb/DDL/public_ddl.sql
DDL Limitations
The DDL statements generated by PDU only include CREATE TABLE statements. Other objects such as indexes, views, sequences, functions, and triggers are NOT exported.
To export all schemas in a database, repeat the u sch command for each schema:
mydb.public=# u sch public;... (export completes) ...mydb.public=# set app;mydb.app=# u sch app;... (export completes) ...mydb.app=# set sales;mydb.sales=# u sch sales;... (export completes) ...
Tip
Use the 'set schema_name;' command to switch between schemas before running the export command.