GPDB Data Unloading Options

Post date: Nov 21, 2014 2:24:10 PM

1. COPY TO: Copy to command is quick and easy postgresql way to unload data. For example  

COPY ( SELECT * FROM sales) TO ‘/tmp/sales.dat’;

Advantage:

2. External Writeable: The advantage of Greenplum writable external table are,

Allows only INSERT operations

Unload Using a File Based Writable External Table

=# CREATE WRITABLE EXTERNAL TABLE unload_expenses

( LIKE expenses )

LOCATION ('gpfdist://etlhost-1:8081/expenses1.out',

'gpfdist://etlhost-2:8081/expenses2.out')

FORMAT 'TEXT' (DELIMITER ',')

DISTRIBUTED BY (exp_id);

psql –c ‘INSERT INTO unload_expenses SELECT * FROM expenses;’

Unload Using a Writable External Web Table

Command based

– Use EXECUTE to specify a shell command, script, or application

=# CREATE WRITABLE EXTERNAL WEB TABLE output (output text)

EXECUTE 'export PATH=$PATH:/home/gpadmin/programs; myprogram.sh'

FORMAT 'TEXT'

DISTRIBUTED RANDOMLY;

3. gpcrondump: 

backup data using Greenplum crondump which dmps database into SQL script files then restore. For example,

gpcrondump -x sachi