Using procopy
Consider the following step-by-step scenario to load data from a source database into the analytical Postgres Pro AXE DBMS with procopy.
PostgreSQL → Postgres Pro AXE Transfer
Postgres Pro AXE is an analytical DBMS that stores data in Parquet files and makes it available through the SQL interface. To load data into Postgres Pro AXE, specify axe in the destination.driver_name configuration parameter. In this case, procopy creates Parquet files from the source data, transfers them to the storage specified in the configuration, and registers them in the Postgres Pro AXE metadata catalog.
|
If you set |
procopy cannot create Postgres Pro AXE analytical tables automatically. Before starting the transfer, create the storage and the analytical tables in Postgres Pro AXE, as described in the subsections below. After the transfer is complete, the analytical tables are queried directly.
-
Prepare Postgres Pro AXE
Create the Postgres Pro AXE storage and analytical tables. The exact sequence depends on whether you use a local directory or an S3 bucket as the storage for Parquet files.
-
Prepare Postgres Pro AXE for the S3 storage
Create an S3 bucket for storing Parquet files. Then, connect to the Postgres Pro AXE database and run the following queries:
CREATE EXTENSION pgpro_axe; CREATE ROLE axe_admin WITH LOGIN PASSWORD '_password_'; GRANT ALL ON SCHEMA axe TO axe_admin; ALTER SYSTEM SET axe.postgres_role TO 'axe_admin'; -- Restart the server, then configure the metadata catalog: SELECT axe.create_catalog_secret( 'localhost', '5432', current_database(), 'axe_admin', '_password_' ); SELECT axe.create_simple_secret( type := 'S3', key_id := 'access_key_ID_example', secret := 'secret', url_style := 'path', endpoint := 'localhost:9000', use_ssl := 'false' ); SELECT axe.create_storage('axe_local_storage', 's3://axe/axe/'); SELECT axe.create_folder('axe', 'axe_local_storage', 'in');The
pgpro_axeextension lets you manage the metadata catalog. Theaxe.create_simple_secretstored procedure stores the credentials for accessing the S3 bucket, andaxe.create_storageregisters the S3 storage that will store Parquet files. Theaxe.create_folderstored procedure creates theaxeshared directory inside the storage. Theindirectory path must correspond to thedestination.folder_pathvalue that you set in the configuration file. -
Prepare Postgres Pro AXE for the local storage
Create a local directory for storing Parquet files on the host where procopy and Postgres Pro AXE are deployed. Then, connect to the Postgres Pro AXE database and run the following queries:
CREATE EXTENSION pgpro_axe; CREATE ROLE axe_admin WITH LOGIN PASSWORD '_password_'; GRANT ALL ON SCHEMA axe TO axe_admin; ALTER SYSTEM SET axe.postgres_role TO 'axe_admin'; -- Restart the server, then configure the metadata catalog: SELECT axe.create_catalog_secret( 'localhost', '5432', current_database(), 'axe_admin', '_password_' ); SELECT axe.create_storage('axe_local_storage', 'file:///var/lib/postgresql/axe/'); SELECT axe.create_folder('axe', 'axe_local_storage', 'in');If procopy is deployed on a separate server from Postgres Pro AXE, specify the path on the procopy server for the directory of the Postgres Pro AXE shared directory. For example, through NFS.
After the storage and the shared directory are set up, create the analytical table based on a heap table:
CREATE TABLE main.olap_products ( id integer PRIMARY KEY, name text NOT NULL, price numeric(10,2) NOT NULL, stock integer DEFAULT 0 ) USING axe WITH (storage = 'axe_local_storage');The
CREATE TABLE … USING axestatement creates theolap_productsanalytical table based on thepublic.productsheap table, without loading data (WITH NO DATA). Analytical tables are logical objects that represent Parquet files in the metadata catalog. The table is created in themainschema, which matches the default schema used by procopy for Postgres Pro AXE tables, and its name must match thedestination_tablevalue that you set in the configuration file.
-
-
Create the source table
In the source database, create the table from which the data will be transferred:
CREATE TABLE public.products ( id integer PRIMARY KEY, name text NOT NULL, price numeric(10,2) NOT NULL, stock integer DEFAULT 0 );Insert data into the source table:
INSERT INTO public.products VALUES (1, 'Widget', 9.99, 100); INSERT INTO public.products VALUES (2, 'Gadget', 19.99, 50); INSERT INTO public.products VALUES (3, 'Gizmo', 29.99, 25); -
Prepare the configuration file
Generate the configuration file:
./procopy config generate > progate_axe.yamlEdit the configuration file so that it looks as follows. Specify
axeas the destination driver:version: 1 source: database: progate driver_name: postgresql host: localhost max_conn: 50 options: - sslmode=disable password: "" port: 5431 username: progate destination: driver_name: axe host: localhost port: 5430 database: axedb username: progate password: "" max_conn: 50 path: axe folder_name: axe folder_path: in parquet_connection: local_path: /var/lib/postgresql/axe tasks: - id: tab1 table: source_table: public.products destination_table: main.olap_productsThe
destination.pathparameter defines the path to the Postgres Pro AXE files inside the bucket or in the local file system. Thedestination.folder_nameparameter defines the name of the Postgres Pro AXE shared directory, anddestination.folder_pathdefines the directory path relative todestination.path. Thedestination.parquet_connectionparameter defines where procopy writes Parquet files: to the local directory (local_path) or to an S3 bucket.If you use an S3 bucket to store the Parquet files, replace the
destination.parquet_connectionsection with the following one:parquet_connection: s3: bucket: axe endpoint: http://localhost:9000 access_key: access_key_ID_example secret_key: secret tmp_path: /var/lib/procopy/tmpFor the S3 storage, the
destination.pathanddestination.folder_pathvalues form the path to the files inside the bucket, anddestination.parquet_connection.s3.tmp_pathdefines the directory where procopy temporarily stores the files before uploading them to the bucket. -
Run the data load
Run the command:
./bin/procopy load -f ./bin/progate_axe.yamlprocopy reads data from the source table, creates Parquet files, transfers them to the specified storage, and registers them in the Postgres Pro AXE metadata catalog.
-
Check the destination
After the transfer is complete, the data in the analytical table becomes available for reading through the SQL interface if procopy calls the
axe.add_filesstored procedure. Query the analytical table:SELECT * FROM main.olap_products ORDER BY id; id | name | price | stock ----+--------+-------+------- 1 | Widget | 9.99 | 100 2 | Gadget | 19.99 | 50 3 | Gizmo | 29.99 | 25 (3 rows)