PostgreSQL Examples
Comprehensive examples for exporting data from PostgreSQL using native connectors (pgsql, pgcopy).
Connection Types
PostgreSQL exports support three connection types:
- pgsql: Standard PostgreSQL protocol
- pgcopy: PostgreSQL COPY protocol (fastest for bulk exports)
- adbc_pgsql: ADBC FastDriver — ultra-fast, Parquet-only export (see ADBC Examples)
The adbc_pgsql connection type uses the Arpe.io ADBC FastDriver for ultra-fast, Arrow-native Parquet exports. Output is Parquet-only — see the ADBC Examples section below.
Single-threaded Export
Simple export without parallelization.
- Standard Protocol
- COPY Protocol
.\FastBCP.exe `
--connectiontype "pgsql" `
--server "localhost" `
--port "5432" `
--database "postgres" `
--user "postgres" `
--password "postgres" `
--query "SELECT * FROM lineitem LIMIT 1000" `
--directory "C:\temp" `
--fileoutput "pg_lineitem.csv" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8" `
--parallelmethod "None"
.\FastBCP.exe `
--connectiontype "pgcopy" `
--server "localhost" `
--port "5432" `
--database "postgres" `
--user "postgres" `
--password "postgres" `
--query "SELECT * FROM lineitem LIMIT 1000" `
--directory "C:\temp" `
--fileoutput "pg_lineitem.csv" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8" `
--parallelmethod "None"
Parallel Export - Random Method
Export using Random distribution with modulo operation.
- Standard Protocol
- COPY Protocol
.\FastBCP.exe `
--connectiontype "pgsql" `
--server "localhost" `
--port "5432" `
--database "postgres" `
--user "postgres" `
--password "postgres" `
--query "SELECT * FROM lineitem" `
--directory "C:\temp" `
--fileoutput "pg_lineitem_random.csv" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8" `
--parallelmethod "Random" `
--distributekeycolumn "l_linenumber" `
--paralleldegree 8 `
--merge "False" `
--runid "pgsql_to_csv_parallel8_random"
.\FastBCP.exe `
--connectiontype "pgcopy" `
--server "localhost" `
--port "5432" `
--database "postgres" `
--user "postgres" `
--password "postgres" `
--query "SELECT * FROM lineitem" `
--directory "C:\temp" `
--fileoutput "pg_lineitem_random.csv" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8" `
--parallelmethod "Random" `
--distributekeycolumn "l_linenumber" `
--paralleldegree 8 `
--merge "False" `
--runid "pgcopy_to_csv_parallel8_random"
Parallel Export - DataDriven Method
Export using DataDriven distribution based on distinct column values.
- Standard Protocol
- COPY Protocol
.\FastBCP.exe `
--connectiontype "pgsql" `
--server "localhost" `
--port "5432" `
--database "postgres" `
--user "postgres" `
--password "postgres" `
--sourceschema "public" `
--sourcetable "lineitem" `
--directory "C:\temp" `
--fileoutput "pg_lineitem_dd.csv" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8" `
--parallelmethod "DataDriven" `
--distributekeycolumn "l_shipmode" `
--paralleldegree 10 `
--merge "False" `
--runid "pgsql_to_csv_parallel10_datadriven"
.\FastBCP.exe `
--connectiontype "pgcopy" `
--server "localhost" `
--port "5432" `
--database "postgres" `
--user "postgres" `
--password "postgres" `
--sourceschema "public" `
--sourcetable "lineitem" `
--directory "C:\temp" `
--fileoutput "pg_lineitem_dd.csv" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8" `
--parallelmethod "DataDriven" `
--distributekeycolumn "l_shipmode" `
--paralleldegree 10 `
--merge "False" `
--runid "pgcopy_to_csv_parallel10_datadriven"
Parallel Export - Ntile Method
Export using Ntile for evenly distributed chunks.
- Standard Protocol
- COPY Protocol
Full table:
.\FastBCP.exe `
--connectiontype "pgsql" `
--server "localhost" `
--port "5432" `
--database "postgres" `
--user "postgres" `
--password "postgres" `
--sourceschema "public" `
--sourcetable "lineitem" `
--directory "C:\temp" `
--fileoutput "pg_lineitem_ntile.csv" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8" `
--parallelmethod "Ntile" `
--distributekeycolumn "l_orderkey" `
--paralleldegree 12 `
--merge "False" `
--runid "pgsql_to_csv_parallel12_ntile"
With query filter:
.\FastBCP.exe `
--connectiontype "pgsql" `
--server "localhost" `
--port "5432" `
--database "postgres" `
--user "postgres" `
--password "postgres" `
--query "SELECT * FROM lineitem WHERE l_shipdate BETWEEN '1995-01-01' AND '1995-12-31'" `
--directory "C:\temp" `
--fileoutput "pg_lineitem_ntile.csv" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8" `
--parallelmethod "Ntile" `
--distributekeycolumn "l_orderkey" `
--paralleldegree 12 `
--merge "False" `
--runid "pgsql_to_csv_parallel12_ntile_filtered"
Full table:
.\FastBCP.exe `
--connectiontype "pgcopy" `
--server "localhost" `
--port "5432" `
--database "postgres" `
--user "postgres" `
--password "postgres" `
--sourceschema "public" `
--sourcetable "lineitem" `
--directory "C:\temp" `
--fileoutput "pg_lineitem_ntile.csv" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8" `
--parallelmethod "Ntile" `
--distributekeycolumn "l_orderkey" `
--paralleldegree 12 `
--merge "False" `
--runid "pgcopy_to_csv_parallel12_ntile"
With query filter:
.\FastBCP.exe `
--connectiontype "pgcopy" `
--server "localhost" `
--port "5432" `
--database "postgres" `
--user "postgres" `
--password "postgres" `
--query "SELECT * FROM lineitem WHERE l_shipdate BETWEEN '1995-01-01' AND '1995-12-31'" `
--directory "C:\temp" `
--fileoutput "pg_lineitem_ntile.csv" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8" `
--parallelmethod "Ntile" `
--distributekeycolumn "l_orderkey" `
--paralleldegree 12 `
--merge "False" `
--runid "pgcopy_to_csv_parallel12_ntile_filtered"
Parallel Export - Physical Method
Parallel export using the physical row identifier (ctid).
With a PostgreSQL connection type (pgsql, pgcopy, adbc_pgsql), the Physical method resolves to the ctid strategy (formerly --parallelmethod Ctid, now deprecated). It is very efficient for full table exports and does not require a distribute key column. --sourceschema and --sourcetable are required.
- Standard Protocol
- COPY Protocol
.\FastBCP.exe `
--connectiontype "pgsql" `
--server "localhost" `
--port "5432" `
--database "postgres" `
--user "postgres" `
--password "postgres" `
--sourceschema "public" `
--sourcetable "lineitem" `
--directory "C:\temp" `
--fileoutput "pg_lineitem_physical.csv" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8" `
--parallelmethod "Physical" `
--paralleldegree 8 `
--merge "False" `
--runid "pgsql_to_csv_parallel8_physical"
.\FastBCP.exe `
--connectiontype "pgcopy" `
--server "localhost" `
--port "5432" `
--database "postgres" `
--user "postgres" `
--password "postgres" `
--sourceschema "public" `
--sourcetable "lineitem" `
--directory "C:\temp" `
--fileoutput "pg_lineitem_physical.csv" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8" `
--parallelmethod "Physical" `
--paralleldegree 8 `
--merge "False" `
--runid "pgcopy_to_csv_parallel8_physical"
Export to Parquet
Export PostgreSQL data to Parquet format.
- Standard Protocol
- COPY Protocol
Single-threaded:
.\FastBCP.exe `
--connectiontype "pgsql" `
--server "localhost" `
--port "5432" `
--database "postgres" `
--user "postgres" `
--password "postgres" `
--sourceschema "public" `
--sourcetable "lineitem" `
--directory "C:\temp" `
--fileoutput "pg_lineitem.parquet" `
--parallelmethod "None"
Parallel with Physical (Ctid):
.\FastBCP.exe `
--connectiontype "pgsql" `
--server "localhost" `
--port "5432" `
--database "postgres" `
--user "postgres" `
--password "postgres" `
--sourceschema "public" `
--sourcetable "lineitem" `
--directory "C:\temp" `
--fileoutput "pg_lineitem.parquet" `
--parallelmethod "Physical" `
--paralleldegree 10 `
--merge "False"
Single-threaded:
.\FastBCP.exe `
--connectiontype "pgcopy" `
--server "localhost" `
--port "5432" `
--database "postgres" `
--user "postgres" `
--password "postgres" `
--sourceschema "public" `
--sourcetable "lineitem" `
--directory "C:\temp" `
--fileoutput "pg_lineitem.parquet" `
--parallelmethod "None"
Parallel with Physical (Ctid):
.\FastBCP.exe `
--connectiontype "pgcopy" `
--server "localhost" `
--port "5432" `
--database "postgres" `
--user "postgres" `
--password "postgres" `
--sourceschema "public" `
--sourcetable "lineitem" `
--directory "C:\temp" `
--fileoutput "pg_lineitem.parquet" `
--parallelmethod "Physical" `
--paralleldegree 10 `
--merge "False"
ODBC Connection
Using ODBC DSN for PostgreSQL connection.
Single-threaded:
.\FastBCP.exe `
--connectiontype "odbc" `
--dsn "PostgreSQL_DSN" `
--directory "C:\temp" `
--fileoutput "pg_test.csv" `
--query "SELECT * FROM public.test_table" `
--parallelmethod "None" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8"
Parallel Random:
.\FastBCP.exe `
--connectiontype "odbc" `
--dsn "PostgreSQL_DSN" `
--directory "C:\temp" `
--fileoutput "pg_test.csv" `
--query "SELECT * FROM public.test_table" `
--parallelmethod "Random" `
--distributekeycolumn "id" `
--paralleldegree 6 `
--merge "False" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8"
Parallel DataDriven:
.\FastBCP.exe `
--connectiontype "odbc" `
--dsn "PostgreSQL_DSN" `
--directory "C:\temp" `
--fileoutput "pg_test.csv" `
--query "SELECT * FROM public.test_table" `
--parallelmethod "DataDriven" `
--distributekeycolumn "category" `
--paralleldegree 6 `
--merge "False" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8"
ADBC Examples
The adbc_pgsql connection type uses the Arpe.io ADBC FastDriver for ultra-fast, Arrow-native exports. Output is Parquet-only — see Connection Parameters for details.
./FastBCP \
--connectiontype "adbc_pgsql" \
--server "localhost:5432" \
--user "pytabextract_pguser" \
--password "FastPassword" \
--database "tpch" \
--sourceschema "tpch10" \
--sourcetable "lineitem" \
--directory "./" \
--fileoutput "{sourcetable}.parquet" \
--method "None"
Build your command with the Wizard