A PostgreSQL extension to run the FastTransfer tool from an SQL function, enabling fast data transfer between databases.
- Prerequisites
- FastTransfer Tool Requirement
- Compatibility
- Installation
- SQL Setup
- Function: pg_fasttransfer_encrypt
- Function: xp_RunFastTransfer_secure Usage
- Function Return Structure
- Notes
- Sudo/Administrator privileges on Linux/Windows to copy files to the PostgreSQL installation directory.
- Your FastTransfer tool binaries. This extension requires the tool to be installed separately.
This extension requires the FastTransfer tool to be installed separately.
Download FastTransfer and get a free trial license here: 👉 https://www.arpe.io/get-your-fasttransfer-trial
Once downloaded, extract the archive and provide the folder path using the fasttransfer_path parameter when calling the xp_RunFastTransfer_secure SQL function.
postgres user account.
You must ensure that this user has the appropriate permissions to execute the FastTransfer binary and read the license file.
- The
FastTransferbinary must be executable by thepostgresuser. - The license file (
.lic) must be readable by thepostgresuser.
Example:
# Grant execute permission on the FastTransfer binary
sudo chmod +x /path/to/FastTransfer
# Ensure the postgres user can access it
sudo chown postgres:postgres /path/to/FastTransfer
sudo chmod 750 /path/to/FastTransfer
# Grant read permission on the license file
sudo chown postgres:postgres /path/to/license.lic
sudo chmod 640 /path/to/license.licMake sure that the PostgreSQL service account (by default NT AUTHORITY\NetworkService or postgres if you installed it manually) has:
- Execute permission on the
FastTransfer.exebinary - Read permission on the
.licfile
The pg_fasttransfer extension has been tested and validated on the following environments:
- PostgreSQL 16
- PostgreSQL 17
- PostgreSQL 15
- PostgreSQL 16
- PostgreSQL 17
This section covers how to install the pg_fasttransfer extension.
The easiest way to install the extension on Linux is by using the install-linux.sh script included in the archive.
-
Extract the contents of the archive into a folder. This folder should contain:
pg_fasttransfer.sopg_fasttransfer.controlpg_fasttransfer--1.0.sqlinstall-linux.sh
-
Make the script executable:
chmod +x install-linux.sh- Run the script with administrator privileges:
sudo ./install-linux.shThe script will automatically detect your PostgreSQL installation and copy the files to the correct locations.
If the automated script fails or you prefer to install the files manually, follow these steps:
- Stop your PostgreSQL service:
sudo systemctl stop postgresql- Locate your PostgreSQL installation directory, typically:
/usr/lib/postgresql/<version>
- Copy the files into the appropriate directories:
pg_fasttransfer.so→ PostgreSQLlibdirectorypg_fasttransfer.controlandpg_fasttransfer--1.0.sql→ PostgreSQLshare/extensiondirectory
Example:
sudo cp pg_fasttransfer.so /usr/lib/postgresql/<version>/lib/
sudo cp pg_fasttransfer.control pg_fasttransfer--1.0.sql /usr/share/postgresql/<version>/extension/- Restart your PostgreSQL service:
sudo systemctl start postgresqlThe easiest way to install the extension is by using the install-win.bat script included in the archive.
-
Extract the contents of the ZIP file into a folder. This folder should contain the following files:
pg_fasttransfer.dllpg_fasttransfer.controlpg_fasttransfer--1.0.sqlinstall-win.bat
-
Right-click on the
install-win.batfile and select "Run as administrator". -
The script will automatically detect your PostgreSQL installation and copy the files to the correct locations.
If the automated script fails or you prefer to install the files manually, follow these steps:
- Stop your PostgreSQL service.
- Locate your PostgreSQL installation folder, typically found at:
C:\Program Files\PostgreSQL\<version>
- Copy the
pg_fasttransfer.dllfile into thelibfolder of your PostgreSQL installation. - Copy the
pg_fasttransfer.controlandpg_fasttransfer--1.0.sqlfiles into theshare\extensionfolder. - Restart your PostgreSQL service.
After the files are in place, you need to set up the extension in your database.
DROP EXTENSION IF EXISTS pg_fasttransfer CASCADE;CREATE EXTENSION pg_fasttransfer CASCADE;This function encrypts a given text string using pgp_sym_encrypt and encodes the result in base64.
It is useful for storing sensitive information, such as passwords, in a secure manner within your SQL scripts or configuration.
The xp_RunFastTransfer_secure function will automatically decrypt any values passed to its --sourcepassword and --targetpassword arguments using the same encryption key.
The encryption/decryption key is defined by the PGFT_ENCRYPTION_KEY variable in the C source file (pg_fasttransfer.c)
pg_fasttransfer_encrypt(text_to_encrypt text) RETURNS textSELECT pg_fasttransfer_encrypt('MySecurePassword');
-- Returns: A base64-encoded encrypted string, e.g., "PgP...base64encodedstring=="This is the main function to execute the FastTransfer tool. It takes various parameters to configure the data transfer operation.
Password arguments (sourcepassword, targetpassword) will be automatically decrypted.
xp_RunFastTransfer_secure(
sourceconnectiontype text DEFAULT NULL,
sourceconnectstring text DEFAULT NULL,
sourcedsn text DEFAULT NULL,
sourceprovider text DEFAULT NULL,
sourceserver text DEFAULT NULL,
sourceuser text DEFAULT NULL,
sourcepassword text DEFAULT NULL,
sourcetrusted boolean DEFAULT FALSE,
sourcedatabase text DEFAULT NULL,
sourceschema text DEFAULT NULL,
sourcetable text DEFAULT NULL,
query text DEFAULT NULL,
fileinput text DEFAULT NULL,
targetconnectiontype text DEFAULT NULL,
targetconnectstring text DEFAULT NULL,
targetserver text DEFAULT NULL,
targetuser text DEFAULT NULL,
targetpassword text DEFAULT NULL,
targettrusted boolean DEFAULT FALSE,
targetdatabase text DEFAULT NULL,
targetschema text DEFAULT NULL,
targettable text DEFAULT NULL,
degree integer DEFAULT NULL,
method text DEFAULT NULL,
distributekeycolumn text DEFAULT NULL,
datadrivenquery text DEFAULT NULL,
loadmode text DEFAULT NULL,
batchsize integer DEFAULT NULL,
useworktables boolean DEFAULT FALSE,
runid text DEFAULT NULL,
settingsfile text DEFAULT NULL,
mapmethod text DEFAULT NULL,
license text DEFAULT NULL,
fasttransfer_path text DEFAULT NULL,
debug boolean DEFAULT FALSE
) RETURNS TABLESELECT * FROM xp_RunFastTransfer_secure(
targetconnectiontype := 'msbulk',
sourceconnectiontype := 'pgsql',
sourceserver := 'localhost:5432',
sourceuser := 'pytabextract_pguser',
sourcepassword := pg_fasttransfer_encrypt('MyActualPassword'),
sourcedatabase := 'tpch',
sourceschema := 'tpch_1',
sourcetable := 'orders',
targetserver := 'localhost,1433',
targetuser := 'migadmin',
targetpassword := pg_fasttransfer_encrypt('AnotherSecurePassword'),
targetdatabase := 'target_db',
targetschema := 'tpch_1',
targettable := 'orders',
loadmode := 'Truncate',
license := '/tmp/FastTransfer_linux-x64_v0.13.5/FastTransfer.lic',
fasttransfer_path := '/tmp/FastTransfer_linux-x64_v0.13.5',
debug := true
);SELECT * FROM xp_RunFastTransfer_secure(
sourceconnectiontype := 'mssql',
sourceserver := 'localhost',
sourcepassword := pg_fasttransfer_encrypt('MyWindowsPassword'),
sourceuser := 'FastLogin',
sourcedatabase := 'tpch10',
sourceschema := 'dbo',
sourcetable := 'orders',
targetconnectiontype := 'pgcopy',
targetserver := 'localhost:15433',
targetuser := 'postgres',
targetpassword := pg_fasttransfer_encrypt('MyPostgresPassword'),
targetdatabase := 'postgres',
targetschema := 'public',
targettable := 'orders',
method := 'Ntile',
degree := 12,
distributekeycolumn := 'o_orderkey',
loadmode := 'Truncate',
batchsize := 1048576,
mapmethod := 'Position',
fasttransfer_path := 'D:\sources\FastTransfer',
debug := true
);The debug parameter is a boolean flag that controls whether the full FastTransfer output is returned in the output column.
- When
debug := true,outputcontains the entire log from FastTransfer. - When
debug := false(default),outputis an empty string, buterror_messagewill still contain any error lines.
The function returns a table with the following columns, providing details about the execution:
| Column | Type | Description |
|---|---|---|
| exit_code | integer | The exit code of the FastTransfer process. |
| output | text | The full log output from the FastTransfer tool if the debug parameter is at TRUE. |
| error_message | text | Only the lines containing ERROR from the FastTransfer output. Empty if no errors occurred. |
| total_rows | bigint | The total number of rows transferred. |
| total_columns | integer | The total number of columns transferred. |
| transfer_time_ms | bigint | Transfer time in milliseconds. |
| total_time_ms | bigint | Total execution time in milliseconds. |
- The extension uses
pg_configto locate PostgreSQL paths, so ensure it is available in your PATH if you are running the script.
