.\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . .TH "PGLOADER" "1" "December 2016" "ff" "" . .SH "NAME" \fBpgloader\fR \- PostgreSQL data loader . .SH "SYNOPSIS" . .nf pgloader [] []\.\.\. pgloader [] SOURCE TARGET . .fi . .SH "DESCRIPTION" pgloader loads data from various sources into PostgreSQL\. It can transform the data it reads on the fly and submit raw SQL before and after the loading\. It uses the \fBCOPY\fR PostgreSQL protocol to stream the data into the server, and manages errors by filling a pair of \fIreject\.dat\fR and \fIreject\.log\fR files\. . .P pgloader operates either using commands which are read from files: . .IP "" 4 . .nf pgloader commands\.load . .fi . .IP "" 0 . .P or by using arguments and options all provided on the command line: . .IP "" 4 . .nf pgloader SOURCE TARGET . .fi . .IP "" 0 . .SH "ARGUMENTS" The pgloader arguments can be as many load files as needed, or a couple of connection strings to a specific input file\. . .SS "SOURCE CONNECTION STRING" The source connection string format is as follows: . .IP "" 4 . .nf format:///absolute/path/to/file\.ext format://\./relative/path/to/file\.ext . .fi . .IP "" 0 . .P Where format might be one of \fBcsv\fR, \fBfixed\fR, \fBcopy\fR, \fBdbf\fR, \fBdb3\fR or \fBixf\fR\. . .IP "" 4 . .nf db://user:pass@host:port/dbname . .fi . .IP "" 0 . .P Where db might be of \fBsqlite\fR, \fBmysql\fR or \fBmssql\fR\. . .P When using a file based source format, pgloader also support natively fetching the file from an http location and decompressing an archive if needed\. In that case it\'s necessary to use the \fB\-\-type\fR option to specify the expected format of the file\. See the examples below\. . .P Also note that some file formats require describing some implementation details such as columns to be read and delimiters and quoting when loading from csv\. . .P For more complex loading scenarios, you will need to write a full fledge load command in the syntax described later in this document\. . .SS "TARGET CONNECTION STRING" The target connection string format is described in details later in this document, see Section Connection String\. . .SH "OPTIONS" . .SS "INQUIRY OPTIONS" Use these options when you want to know more about how to use \fBpgloader\fR, as those options will cause \fBpgloader\fR not to load any data\. . .TP \fB\-h\fR, \fB\-\-help\fR Show command usage summary and exit\. . .TP \fB\-V\fR, \fB\-\-version\fR Show pgloader version string and exit\. . .TP \fB\-E\fR, \fB\-\-list\-encodings\fR List known encodings in this version of pgloader\. . .TP \fB\-U\fR, \fB\-\-upgrade\-config\fR Parse given files in the command line as \fBpgloader\.conf\fR files with the \fBINI\fR syntax that was in use in pgloader versions 2\.x, and output the new command syntax for pgloader on standard output\. . .SS "GENERAL OPTIONS" Those options are meant to tweak \fBpgloader\fR behavior when loading data\. . .IP "\(bu" 4 \fB\-v\fR, \fB\-\-verbose\fR: Be verbose\. . .IP "\(bu" 4 \fB\-q\fR, \fB\-\-quiet\fR: Be quiet\. . .IP "\(bu" 4 \fB\-d\fR, \fB\-\-debug\fR: Show debug level information messages\. . .IP "\(bu" 4 \fB\-D\fR, \fB\-\-root\-dir\fR: Set the root working directory (default to "/tmp/pgloader")\. . .IP "\(bu" 4 \fB\-L\fR, \fB\-\-logfile\fR: Set the pgloader log file (default to "/tmp/pgloader\.log")\. . .IP "\(bu" 4 \fB\-\-log\-min\-messages\fR: Minimum level of verbosity needed for log message to make it to the logfile\. One of critical, log, error, warning, notice, info or debug\. . .IP "\(bu" 4 \fB\-\-client\-min\-messages\fR: Minimum level of verbosity needed for log message to make it to the console\. One of critical, log, error, warning, notice, info or debug\. . .IP "\(bu" 4 \fB\-S\fR, \fB\-\-summary\fR: A filename where to copy the summary output\. When relative, the filename is expanded into \fB*root\-dir*\fR\. . .IP The format of the filename defaults to being \fIhuman readable\fR\. It is possible to have the output in machine friendly formats such as \fICSV\fR, \fICOPY\fR (PostgreSQL\'s own COPY format) or \fIJSON\fR by specifying a filename with the extension resp\. \fB\.csv\fR, \fB\.copy\fR or \fB\.json\fR\. . .IP "\(bu" 4 \fB\-l \fR, \fB\-\-load\-lisp\-file \fR: Specify a lisp \fIfile\fR to compile and load into the pgloader image before reading the commands, allowing to define extra transformation function\. Those functions should be defined in the \fBpgloader\.transforms\fR package\. This option can appear more than once in the command line\. . .IP "\(bu" 4 \fB\-\-dry\-run\fR: . .IP Allow testing a \fB\.load\fR file without actually trying to load any data\. It\'s useful to debug it until it\'s ok, in particular to fix connection strings\. . .IP "\(bu" 4 \fB\-\-on\-error\-stop\fR . .IP Alter pgloader behavior: rather than trying to be smart about error handling and continue loading good data, separating away the bad one, just stop as soon as PostgreSQL refuses anything sent to it\. Useful to debug data processing, transformation function and specific type casting\. . .IP "\(bu" 4 \fB\-\-self\-upgrade \fR: . .IP Specify a \fIdirectory\fR where to find pgloader sources so that one of the very first things it does is dynamically loading\-in (and compiling to machine code) another version of itself, usually a newer one like a very recent git checkout\. . .IP "" 0 . .SS "COMMAND LINE ONLY OPERATIONS" Those options are meant to be used when using \fBpgloader\fR from the command line only, rather than using a command file and the rich command clauses and parser\. In simple cases, it can be much easier to use the \fISOURCE\fR and \fITARGET\fR directly on the command line, then tweak the loading with those options: . .IP "\(bu" 4 \fB\-\-with "option"\fR: . .IP Allows setting options from the command line\. You can use that option as many times as you want\. The option arguments must follow the \fIWITH\fR clause for the source type of the \fBSOURCE\fR specification, as described later in this document\. . .IP "\(bu" 4 \fB\-\-set "guc_name=\'value\'"\fR . .IP Allows setting PostgreSQL configuration from the command line\. Note that the option parsing is the same as when used from the \fISET\fR command clause, in particular you must enclose the guc value with single\-quotes\. . .IP "\(bu" 4 \fB\-\-field "\.\.\."\fR . .IP Allows setting a source field definition\. Fields are accumulated in the order given on the command line\. It\'s possible to either use a \fB\-\-field\fR option per field in the source file, or to separate field definitions by a comma, as you would do in the \fIHAVING FIELDS\fR clause\. . .IP "\(bu" 4 \fB\-\-cast "\.\.\."\fR . .IP Allows setting a specific casting rule for loading the data\. . .IP "\(bu" 4 \fB\-\-type csv|fixed|db3|ixf|sqlite|mysql|mssql\fR . .IP Allows forcing the source type, in case when the \fISOURCE\fR parsing isn\'t satisfying\. . .IP "\(bu" 4 \fB\-\-encoding \fR . .IP Set the encoding of the source file to load data from\. . .IP "\(bu" 4 \fB\-\-before \fR . .IP Parse given filename for SQL queries and run them against the target database before loading the data from the source\. The queries are parsed by pgloader itself: they need to be terminated by a semi\-colon (;) and the file may include \fB\ei\fR or \fB\eir\fR commands to \fIinclude\fR another file\. . .IP "\(bu" 4 \fB\-\-after \fR . .IP Parse given filename for SQL queries and run them against the target database after having loaded the data from the source\. The queries are parsed in the same way as with the \fB\-\-before\fR option, see above\. . .IP "" 0 . .SS "MORE DEBUG INFORMATION" To get the maximum amount of debug information, you can use both the \fB\-\-verbose\fR and the \fB\-\-debug\fR switches at the same time, which is equivalent to saying \fB\-\-client\-min\-messages data\fR\. Then the log messages will show the data being processed, in the cases where the code has explicit support for it\. . .SH "USAGE EXAMPLES" Review the command line options and pgloader\'s version: . .IP "" 4 . .nf pgloader \-\-help pgloader \-\-version . .fi . .IP "" 0 . .SS "Loading from a complex command" Use the command file as the pgloader command argument, pgloader will parse that file and execute the commands found in it: . .IP "" 4 . .nf pgloader \-\-verbose \./test/csv\-districts\.load . .fi . .IP "" 0 . .SS "CSV" Load data from a CSV file into a pre\-existing table in your database: . .IP "" 4 . .nf pgloader \-\-type csv \e \-\-field id \-\-field field \e \-\-with truncate \e \-\-with "fields terminated by \',\'" \e \./test/data/matching\-1\.csv \e postgres:///pgloader?tablename=matching . .fi . .IP "" 0 . .P In that example the whole loading is driven from the command line, bypassing the need for writing a command in the pgloader command syntax entirely\. As there\'s no command though, the extra inforamtion needed must be provided on the command line using the \fB\-\-type\fR and \fB\-\-field\fR and \fB\-\-with\fR switches\. . .P For documentation about the available syntaxes for the \fB\-\-field\fR and \fB\-\-with\fR switches, please refer to the CSV section later in the man page\. . .P Note also that the PostgreSQL URI includes the target \fItablename\fR\. . .SS "Reading from STDIN" File based pgloader sources can be loaded from the standard input, as in the following example: . .IP "" 4 . .nf pgloader \-\-type csv \e \-\-field "usps,geoid,aland,awater,aland_sqmi,awater_sqmi,intptlat,intptlong" \e \-\-with "skip header = 1" \e \-\-with "fields terminated by \'\et\'" \e \- \e postgresql:///pgloader?districts_longlat \e < test/data/2013_Gaz_113CDs_national\.txt . .fi . .IP "" 0 . .P The dash (\fB\-\fR) character as a source is used to mean \fIstandard input\fR, as usual in Unix command lines\. It\'s possible to stream compressed content to pgloader with this technique, using the Unix pipe: . .IP "" 4 . .nf gunzip \-c source\.gz | pgloader \-\-type csv \.\.\. \- pgsql:///target?foo . .fi . .IP "" 0 . .SS "Loading from CSV available through HTTP" The same command as just above can also be run if the CSV file happens to be found on a remote HTTP location: . .IP "" 4 . .nf pgloader \-\-type csv \e \-\-field "usps,geoid,aland,awater,aland_sqmi,awater_sqmi,intptlat,intptlong" \e \-\-with "skip header = 1" \e \-\-with "fields terminated by \'\et\'" \e http://pgsql\.tapoueh\.org/temp/2013_Gaz_113CDs_national\.txt \e postgresql:///pgloader?districts_longlat . .fi . .IP "" 0 . .P Some more options have to be used in that case, as the file contains a one\-line header (most commonly that\'s column names, could be a copyright notice)\. Also, in that case, we specify all the fields right into a single \fB\-\-field\fR option argument\. . .P Again, the PostgreSQL target connection string must contain the \fItablename\fR option and you have to ensure that the target table exists and may fit the data\. Here\'s the SQL command used in that example in case you want to try it yourself: . .IP "" 4 . .nf create table districts_longlat ( usps text, geoid text, aland bigint, awater bigint, aland_sqmi double precision, awater_sqmi double precision, intptlat double precision, intptlong double precision ); . .fi . .IP "" 0 . .P Also notice that the same command will work against an archived version of the same data, e\.g\. http://pgsql\.tapoueh\.org/temp/2013_Gaz_113CDs_national\.txt\.gz\. . .P Finally, it\'s important to note that pgloader first fetches the content from the HTTP URL it to a local file, then expand the archive when it\'s recognized to be one, and only then processes the locally expanded file\. . .P In some cases, either because pgloader has no direct support for your archive format or maybe because expanding the archive is not feasible in your environment, you might want to \fIstream\fR the content straight from its remote location into PostgreSQL\. Here\'s how to do that, using the old battle tested Unix Pipes trick: . .IP "" 4 . .nf curl http://pgsql\.tapoueh\.org/temp/2013_Gaz_113CDs_national\.txt\.gz \e | gunzip \-c \e | pgloader \-\-type csv \e \-\-field "usps,geoid,aland,awater,aland_sqmi,awater_sqmi,intptlat,intptlong" \-\-with "skip header = 1" \e \-\-with "fields terminated by \'\et\'" \e \- \e postgresql:///pgloader?districts_longlat . .fi . .IP "" 0 . .P Now the OS will take care of the streaming and buffering between the network and the commands and pgloader will take care of streaming the data down to PostgreSQL\. . .SS "Migrating from SQLite" The following command will open the SQLite database, discover its tables definitions including indexes and foreign keys, migrate those definitions while \fIcasting\fR the data type specifications to their PostgreSQL equivalent and then migrate the data over: . .IP "" 4 . .nf createdb newdb pgloader \./test/sqlite/sqlite\.db postgresql:///newdb . .fi . .IP "" 0 . .SS "Migrating from MySQL" Just create a database where to host the MySQL data and definitions and have pgloader do the migration for you in a single command line: . .IP "" 4 . .nf createdb pagila pgloader mysql://user@localhost/sakila postgresql:///pagila . .fi . .IP "" 0 . .SS "Fetching an archived DBF file from a HTTP remote location" It\'s possible for pgloader to download a file from HTTP, unarchive it, and only then open it to discover the schema then load the data: . .IP "" 4 . .nf createdb foo pgloader \-\-type dbf http://www\.insee\.fr/fr/methodes/nomenclatures/cog/telechargement/2013/dbf/historiq2013\.zip postgresql:///foo . .fi . .IP "" 0 . .P Here it\'s not possible for pgloader to guess the kind of data source it\'s being given, so it\'s necessary to use the \fB\-\-type\fR command line switch\. . .SH "BATCHES AND RETRY BEHAVIOUR" To load data to PostgreSQL, pgloader uses the \fBCOPY\fR streaming protocol\. While this is the faster way to load data, \fBCOPY\fR has an important drawback: as soon as PostgreSQL emits an error with any bit of data sent to it, whatever the problem is, the whole data set is rejected by PostgreSQL\. . .P To work around that, pgloader cuts the data into \fIbatches\fR of 25000 rows each, so that when a problem occurs it\'s only impacting that many rows of data\. Each batch is kept in memory while the \fBCOPY\fR streaming happens, in order to be able to handle errors should some happen\. . .P When PostgreSQL rejects the whole batch, pgloader logs the error message then isolates the bad row(s) from the accepted ones by retrying the batched rows in smaller batches\. To do that, pgloader parses the \fICONTEXT\fR error message from the failed COPY, as the message contains the line number where the error was found in the batch, as in the following example: . .IP "" 4 . .nf CONTEXT: COPY errors, line 3, column b: "2006\-13\-11" . .fi . .IP "" 0 . .P Using that information, pgloader will reload all rows in the batch before the erroneous one, log the erroneous one as rejected, then try loading the remaining of the batch in a single attempt, which may or may not contain other erroneous data\. . .P At the end of a load containing rejected rows, you will find two files in the \fIroot\-dir\fR location, under a directory named the same as the target database of your setup\. The filenames are the target table, and their extensions are \fB\.dat\fR for the rejected data and \fB\.log\fR for the file containing the full PostgreSQL client side logs about the rejected data\. . .P The \fB\.dat\fR file is formatted in PostgreSQL the text COPY format as documented in http://www\.postgresql\.org/docs/9\.2/static/sql\-copy\.html#AEN66609 \fI\fR\. . .SH "A NOTE ABOUT PERFORMANCE" pgloader has been developed with performance in mind, to be able to cope with ever growing needs in loading large amounts of data into PostgreSQL\. . .P The basic architecture it uses is the old Unix pipe model, where a thread is responsible for loading the data (reading a CSV file, querying MySQL, etc) and fills pre\-processed data into a queue\. Another threads feeds from the queue, apply some more \fItransformations\fR to the input data and stream the end result to PostgreSQL using the COPY protocol\. . .P When given a file that the PostgreSQL \fBCOPY\fR command knows how to parse, and if the file contains no erroneous data, then pgloader will never be as fast as just using the PostgreSQL \fBCOPY\fR command\. . .P Note that while the \fBCOPY\fR command is restricted to read either from its standard input or from a local file on the server\'s file system, the command line tool \fBpsql\fR implements a \fB\ecopy\fR command that knows how to stream a file local to the client over the network and into the PostgreSQL server, using the same protocol as pgloader uses\. . .SH "A NOTE ABOUT PARALLELISM" pgloader uses several concurrent tasks to process the data being loaded: . .IP "\(bu" 4 a reader task reads the data in, . .IP "\(bu" 4 at least one transformer task is responsible for applying the needed transformations to given data so that it fits PostgreSQL expectations, those transformations include CSV like user\-defined \fIprojections\fR, database \fIcasting\fR (default and user given), and PostgreSQL specific \fIformatting\fR of the data for the COPY protocol and in unicode, . .IP "\(bu" 4 at least one writer task is responsible for sending the data down to PostgreSQL using the COPY protocol\. . .IP "" 0 . .P The idea behind having the transformer task do the \fIformatting\fR is so that in the event of bad rows being rejected by PostgreSQL the retry process doesn\'t have to do that step again\. . .P At the moment, the number of transformer and writer tasks are forced into being the same, which allows for a very simple \fIqueueing\fR model to be implemented: the reader task fills in one queue per transformer task, which then pops from that queue and pushes to a writer queue per COPY task\. . .P The parameter \fIworkers\fR allows to control how many worker threads are allowed to be active at any time (that\'s the parallelism level); and the parameter \fIconcurrency\fR allows to control how many tasks are started to handle the data (they may not all run at the same time, depending on the \fIworkers\fR setting)\. . .P With a \fIconcurrency\fR of 2, we start 1 reader thread, 2 transformer threads and 2 writer tasks, that\'s 5 concurrent tasks to schedule into \fIworkers\fR threads\. . .P So with \fBworkers = 4, concurrency = 2\fR, the parallel scheduler will maintain active only 4 of the 5 tasks that are started\. . .P With \fBworkers = 8, concurrency = 1\fR, we then are able to work on several units of work at the same time\. In the database sources, a unit of work is a table, so those settings allow pgloader to be active on as many as 3 tables at any time in the load process\. . .P The defaults are \fBworkers = 4, concurrency = 1\fR when loading from a database source, and \fBworkers = 8, concurrency = 2\fR when loading from something else (currently, a file)\. Those defaults are arbitrary and waiting for feedback from users, so please consider providing feedback if you play with the settings\. . .P As the \fBCREATE INDEX\fR threads started by pgloader are only waiting until PostgreSQL is done with the real work, those threads are \fINOT\fR counted into the concurrency levels as detailed here\. . .P By default, as many \fBCREATE INDEX\fR threads as the maximum number of indexes per table are found in your source schema\. It is possible to set the \fBmax parallel create index\fR \fIWITH\fR option to another number in case there\'s just too many of them to create\. . .SH "SOURCE FORMATS" pgloader supports the following input formats: . .IP "\(bu" 4 csv, which includes also tsv and other common variants where you can change the \fIseparator\fR and the \fIquoting\fR rules and how to \fIescape\fR the \fIquotes\fR themselves; . .IP "\(bu" 4 fixed columns file, where pgloader is flexible enough to accomodate with source files missing columns (\fIragged fixed length column files\fR do exist); . .IP "\(bu" 4 PostgreSLQ COPY formatted files, following the COPY TEXT documentation of PostgreSQL, such as the reject files prepared by pgloader; . .IP "\(bu" 4 dbase files known as db3 or dbf file; . .IP "\(bu" 4 ixf formated files, ixf being a binary storage format from IBM; . .IP "\(bu" 4 sqlite databases with fully automated discovery of the schema and advanced cast rules; . .IP "\(bu" 4 mysql databases with fully automated discovery of the schema and advanced cast rules; . .IP "\(bu" 4 MS SQL databases with fully automated discovery of the schema and advanced cast rules\. . .IP "" 0 . .SH "PGLOADER COMMANDS SYNTAX" pgloader implements a Domain Specific Language allowing to setup complex data loading scripts handling computed columns and on\-the\-fly sanitization of the input data\. For more complex data loading scenarios, you will be required to learn that DSL\'s syntax\. It\'s meant to look familiar to DBA by being inspired by SQL where it makes sense, which is not that much after all\. . .P The pgloader commands follow the same global grammar rules\. Each of them might support only a subset of the general options and provide specific options\. . .IP "" 4 . .nf LOAD FROM [ HAVING FIELDS ] INTO [ TARGET COLUMNS ] [ WITH ] [ SET ] [ BEFORE LOAD [ DO | EXECUTE ] \.\.\. ] [ AFTER LOAD [ DO | EXECUTE ] \.\.\. ] ; . .fi . .IP "" 0 . .P The main clauses are the \fBLOAD\fR, \fBFROM\fR, \fBINTO\fR and \fBWITH\fR clauses that each command implements\. Some command then implement the \fBSET\fR command, or some specific clauses such as the \fBCAST\fR clause\. . .SH "COMMON CLAUSES" Some clauses are common to all commands: . .IP "\(bu" 4 \fIFROM\fR . .IP The \fIFROM\fR clause specifies where to read the data from, and each command introduces its own variant of sources\. For instance, the \fICSV\fR source supports \fBinline\fR, \fBstdin\fR, a filename, a quoted filename, and a \fIFILENAME MATCHING\fR clause (see above); whereas the \fIMySQL\fR source only supports a MySQL database URI specification\. . .IP In all cases, the \fIFROM\fR clause is able to read its value from an environment variable when using the form \fBGETENV \'varname\'\fR\. . .IP "\(bu" 4 \fIINTO\fR . .IP The PostgreSQL connection URI must contains the name of the target table where to load the data into\. That table must have already been created in PostgreSQL, and the name might be schema qualified\. . .IP The \fIINTO\fR target database connection URI can be parsed from the value of an environment variable when using the form \fBGETENV \'varname\'\fR\. . .IP Then \fIINTO\fR option also supports an optional comma separated list of target columns, which are either the name of an input \fIfield\fR or the white space separated list of the target column name, its PostgreSQL data type and a \fIUSING\fR expression\. . .IP The \fIUSING\fR expression can be any valid Common Lisp form and will be read with the current package set to \fBpgloader\.transforms\fR, so that you can use functions defined in that package, such as functions loaded dynamically with the \fB\-\-load\fR command line parameter\. . .IP Each \fIUSING\fR expression is compiled at runtime to native code\. . .IP This feature allows pgloader to load any number of fields in a CSV file into a possibly different number of columns in the database, using custom code for that projection\. . .IP "\(bu" 4 \fIWITH\fR . .IP Set of options to apply to the command, using a global syntax of either: . .IP "\(bu" 4 \fIkey = value\fR . .IP "\(bu" 4 \fIuse option\fR . .IP "\(bu" 4 \fIdo not use option\fR . .IP "" 0 . .IP See each specific command for details\. . .IP All data sources specific commands support the following options: . .IP "\(bu" 4 \fIbatch rows = R\fR . .IP "\(bu" 4 \fIbatch size = \.\.\. MB\fR . .IP "\(bu" 4 \fIbatch concurrency = \.\.\.\fR . .IP "" 0 . .IP See the section BATCH BEHAVIOUR OPTIONS for more details\. . .IP In addition, the following settings are available: . .IP "\(bu" 4 \fIworkers = W\fR . .IP "\(bu" 4 \fIconcurrency = C\fR . .IP "\(bu" 4 \fImax parallel create index = I\fR . .IP "" 0 . .IP See section A NOTE ABOUT PARALLELISM for more details\. . .IP "\(bu" 4 \fISET\fR . .IP This clause allows to specify session parameters to be set for all the sessions opened by pgloader\. It expects a list of parameter name, the equal sign, then the single\-quoted value as a comma separated list\. . .IP The names and values of the parameters are not validated by pgloader, they are given as\-is to PostgreSQL\. . .IP "\(bu" 4 \fIBEFORE LOAD DO\fR . .IP You can run SQL queries against the database before loading the data from the \fBCSV\fR file\. Most common SQL queries are \fBCREATE TABLE IF NOT EXISTS\fR so that the data can be loaded\. . .IP Each command must be \fIdollar\-quoted\fR: it must begin and end with a double dollar sign, \fB$$\fR\. Dollar\-quoted queries are then comma separated\. No extra punctuation is expected after the last SQL query\. . .IP "\(bu" 4 \fIBEFORE LOAD EXECUTE\fR . .IP Same behaviour as in the \fIBEFORE LOAD DO\fR clause\. Allows you to read the SQL queries from a SQL file\. Implements support for PostgreSQL dollar\-quoting and the \fB\ei\fR and \fB\eir\fR include facilities as in \fBpsql\fR batch mode (where they are the same thing)\. . .IP "\(bu" 4 \fIAFTER LOAD DO\fR . .IP Same format as \fIBEFORE LOAD DO\fR, the dollar\-quoted queries found in that section are executed once the load is done\. That\'s the right time to create indexes and constraints, or re\-enable triggers\. . .IP "\(bu" 4 \fIAFTER LOAD EXECUTE\fR . .IP Same behaviour as in the \fIAFTER LOAD DO\fR clause\. Allows you to read the SQL queries from a SQL file\. Implements support for PostgreSQL dollar\-quoting and the \fB\ei\fR and \fB\eir\fR include facilities as in \fBpsql\fR batch mode (where they are the same thing)\. . .IP "" 0 . .SS "Connection String" The \fB\fR parameter is expected to be given as a \fIConnection URI\fR as documented in the PostgreSQL documentation at http://www\.postgresql\.org/docs/9\.3/static/libpq\-connect\.html#LIBPQ\-CONNSTRING\. . .IP "" 4 . .nf postgresql://[user[:password]@][netloc][:port][/dbname][?option=value&\.\.\.] . .fi . .IP "" 0 . .P Where: . .IP "\(bu" 4 \fIuser\fR . .IP Can contain any character, including colon (\fB:\fR) which must then be doubled (\fB::\fR) and at\-sign (\fB@\fR) which must then be doubled (\fB@@\fR)\. . .IP When omitted, the \fIuser\fR name defaults to the value of the \fBPGUSER\fR environment variable, and if it is unset, the value of the \fBUSER\fR environment variable\. . .IP "\(bu" 4 \fIpassword\fR . .IP Can contain any character, including the at sign (\fB@\fR) which must then be doubled (\fB@@\fR)\. To leave the password empty, when the \fIuser\fR name ends with at at sign, you then have to use the syntax user:@\. . .IP When omitted, the \fIpassword\fR defaults to the value of the \fBPGPASSWORD\fR environment variable if it is set, otherwise the password is left unset\. . .IP "\(bu" 4 \fInetloc\fR . .IP Can be either a hostname in dotted notation, or an ipv4, or an Unix domain socket path\. Empty is the default network location, under a system providing \fIunix domain socket\fR that method is preferred, otherwise the \fInetloc\fR default to \fBlocalhost\fR\. . .IP It\'s possible to force the \fIunix domain socket\fR path by using the syntax \fBunix:/path/to/where/the/socket/file/is\fR, so to force a non default socket path and a non default port, you would have: . .IP "" 4 . .nf postgresql://unix:/tmp:54321/dbname . .fi . .IP "" 0 . .IP The \fInetloc\fR defaults to the value of the \fBPGHOST\fR environment variable, and if it is unset, to either the default \fBunix\fR socket path when running on a Unix system, and \fBlocalhost\fR otherwise\. . .IP "\(bu" 4 \fIdbname\fR . .IP Should be a proper identifier (letter followed by a mix of letters, digits and the punctuation signs comma (\fB,\fR), dash (\fB\-\fR) and underscore (\fB_\fR)\. . .IP When omitted, the \fIdbname\fR defaults to the value of the environment variable \fBPGDATABASE\fR, and if that is unset, to the \fIuser\fR value as determined above\. . .IP "\(bu" 4 \fIoptions\fR . .IP The optional parameters must be supplied with the form \fBname=value\fR, and you may use several parameters by separating them away using an ampersand (\fB&\fR) character\. . .IP Only some options are supported here, \fItablename\fR (which might be qualified with a schema name) \fIsslmode\fR, \fIhost\fR, \fIport\fR, \fIdbname\fR, \fIuser\fR and \fIpassword\fR\. . .IP The \fIsslmode\fR parameter values can be one of \fBdisable\fR, \fBallow\fR, \fBprefer\fR or \fBrequire\fR\. . .IP For backward compatibility reasons, it\'s possible to specify the \fItablename\fR option directly, without spelling out the \fBtablename=\fR parts\. . .IP The options override the main URI components when both are given, and using the percent\-encoded option parameters allow using passwords starting with a colon and bypassing other URI components parsing limitations\. . .IP "" 0 . .SS "Regular Expressions" Several clauses listed in the following accept \fIregular expressions\fR with the following input rules: . .IP "\(bu" 4 A regular expression begins with a tilde sign (\fB~\fR), . .IP "\(bu" 4 is then followed with an opening sign, . .IP "\(bu" 4 then any character is allowed and considered part of the regular expression, except for the closing sign, . .IP "\(bu" 4 then a closing sign is expected\. . .IP "" 0 . .P The opening and closing sign are allowed by pair, here\'s the complete list of allowed delimiters: . .IP "" 4 . .nf ~// ~[] ~{} ~() ~<> ~"" ~\'\' ~|| ~## . .fi . .IP "" 0 . .P Pick the set of delimiters that don\'t collide with the \fIregular expression\fR you\'re trying to input\. If your expression is such that none of the solutions allow you to enter it, the places where such expressions are allowed should allow for a list of expressions\. . .SS "Comments" Any command may contain comments, following those input rules: . .IP "\(bu" 4 the \fB\-\-\fR delimiter begins a comment that ends with the end of the current line, . .IP "\(bu" 4 the delimiters \fB/*\fR and \fB*/\fR respectively start and end a comment, which can be found in the middle of a command or span several lines\. . .IP "" 0 . .P Any place where you could enter a \fIwhitespace\fR will accept a comment too\. . .SS "Batch behaviour options" All pgloader commands have support for a \fIWITH\fR clause that allows for specifying options\. Some options are generic and accepted by all commands, such as the \fIbatch behaviour options\fR, and some options are specific to a data source kind, such as the CSV \fIskip header\fR option\. . .P The global batch behaviour options are: . .IP "\(bu" 4 \fIbatch rows\fR . .IP Takes a numeric value as argument, used as the maximum number of rows allowed in a batch\. The default is \fB25 000\fR and can be changed to try having better performance characteristics or to control pgloader memory usage; . .IP "\(bu" 4 \fIbatch size\fR . .IP Takes a memory unit as argument, such as \fI20 MB\fR, its default value\. Accepted multipliers are \fIkB\fR, \fIMB\fR, \fIGB\fR, \fITB\fR and \fIPB\fR\. The case is important so as not to be confused about bits versus bytes, we\'re only talking bytes here\. . .IP "\(bu" 4 \fIbatch concurrency\fR . .IP Takes a numeric value as argument, defaults to \fB10\fR\. That\'s the number of batches that pgloader is allows to build in memory in each reader thread\. See the \fIworkers\fR setting for how many reader threads are allowed to run at the same time: each of them is allowed as many as \fIbatch concurrency\fR batches\. . .IP "" 0 . .P Other options are specific to each input source, please refer to specific parts of the documentation for their listing and covering\. . .P A batch is then closed as soon as either the \fIbatch rows\fR or the \fIbatch size\fR threshold is crossed, whichever comes first\. In cases when a batch has to be closed because of the \fIbatch size\fR setting, a \fIdebug\fR level log message is printed with how many rows did fit in the \fIoversized\fR batch\. . .SH "LOAD CSV" This command instructs pgloader to load data from a \fBCSV\fR file\. Here\'s an example: . .IP "" 4 . .nf LOAD CSV FROM \'GeoLiteCity\-Blocks\.csv\' WITH ENCODING iso\-646\-us HAVING FIELDS ( startIpNum, endIpNum, locId ) INTO postgresql://user@localhost:54393/dbname?geolite\.blocks TARGET COLUMNS ( iprange ip4r using (ip\-range startIpNum endIpNum), locId ) WITH truncate, skip header = 2, fields optionally enclosed by \'"\', fields escaped by backslash\-quote, fields terminated by \'\et\' SET work_mem to \'32 MB\', maintenance_work_mem to \'64 MB\'; . .fi . .IP "" 0 . .P The \fBcsv\fR format command accepts the following clauses and options: . .IP "\(bu" 4 \fIFROM\fR . .IP Filename where to load the data from\. Accepts an \fIENCODING\fR option\. Use the \fB\-\-list\-encodings\fR option to know which encoding names are supported\. . .IP The filename may be enclosed by single quotes, and could be one of the following special values: . .IP "\(bu" 4 \fIinline\fR . .IP The data is found after the end of the parsed commands\. Any number of empty lines between the end of the commands and the beginning of the data is accepted\. . .IP "\(bu" 4 \fIstdin\fR . .IP Reads the data from the standard input stream\. . .IP "\(bu" 4 \fIFILENAMES MATCHING\fR . .IP The whole \fImatching\fR clause must follow the following rule: . .IP "" 4 . .nf [ ALL FILENAMES | [ FIRST ] FILENAME ] MATCHING regexp [ IN DIRECTORY \'\.\.\.\' ] . .fi . .IP "" 0 . .IP The \fImatching\fR clause applies given \fIregular expression\fR (see above for exact syntax, several options can be used here) to filenames\. It\'s then possible to load data from only the first match of all of them\. . .IP The optional \fIIN DIRECTORY\fR clause allows specifying which directory to walk for finding the data files, and can be either relative to where the command file is read from, or absolute\. The given directory must exists\. . .IP "" 0 . .IP The \fIFROM\fR option also supports an optional comma separated list of \fIfield\fR names describing what is expected in the \fBCSV\fR data file, optionally introduced by the clause \fBHAVING FIELDS\fR\. . .IP Each field name can be either only one name or a name following with specific reader options for that field, enclosed in square brackets and comma\-separated\. Supported per\-field reader options are: . .IP "\(bu" 4 \fIterminated by\fR . .IP See the description of \fIfield terminated by\fR below\. . .IP The processing of this option is not currently implemented\. . .IP "\(bu" 4 \fIdate format\fR . .IP When the field is expected of the date type, then this option allows to specify the date format used in the file\. . .IP Date format string are template strings modeled against the PostgreSQL \fBto_char\fR template strings support, limited to the following patterns: . .IP "\(bu" 4 YYYY, YYY, YY for the year part . .IP "\(bu" 4 MM for the numeric month part . .IP "\(bu" 4 DD for the numeric day part . .IP "\(bu" 4 HH, HH12, HH24 for the hour part . .IP "\(bu" 4 am, AM, a\.m\., A\.M\. . .IP "\(bu" 4 pm, PM, p\.m\., P\.M\. . .IP "\(bu" 4 MI for the minutes part . .IP "\(bu" 4 SS for the seconds part . .IP "\(bu" 4 MS for the milliseconds part (4 digits) . .IP "\(bu" 4 US for the microseconds part (6 digits) . .IP "\(bu" 4 unparsed punctuation signs: \- \. * # @ T / \e and space . .IP "" 0 . .IP Here\'s an example of a \fIdate format\fR specification: . .IP "" 4 . .nf column\-name [date format \'YYYY\-MM\-DD HH24\-MI\-SS\.US\'] . .fi . .IP "" 0 . .IP "\(bu" 4 \fInull if\fR . .IP This option takes an argument which is either the keyword \fIblanks\fR or a double\-quoted string\. . .IP When \fIblanks\fR is used and the field value that is read contains only space characters, then it\'s automatically converted to an SQL \fBNULL\fR value\. . .IP When a double\-quoted string is used and that string is read as the field value, then the field value is automatically converted to an SQL \fBNULL\fR value\. . .IP "\(bu" 4 \fItrim both whitespace\fR, \fItrim left whitespace\fR, \fItrim right whitespace\fR . .IP This option allows to trim whitespaces in the read data, either from both sides of the data, or only the whitespace characters found on the left of the streaing, or only those on the right of the string\. . .IP "" 0 . .IP "\(bu" 4 \fIWITH\fR . .IP When loading from a \fBCSV\fR file, the following options are supported: . .IP "\(bu" 4 \fItruncate\fR . .IP When this option is listed, pgloader issues a \fBTRUNCATE\fR command against the PostgreSQL target table before reading the data file\. . .IP "\(bu" 4 \fIdrop indexes\fR . .IP When this option is listed, pgloader issues \fBDROP INDEX\fR commands against all the indexes defined on the target table before copying the data, then \fBCREATE INDEX\fR commands once the \fBCOPY\fR is done\. . .IP In order to get the best performance possible, all the indexes are created in parallel and when done the primary keys are built again from the unique indexes just created\. This two step process allows creating the primary key index in parallel with the other indexes, as only the \fBALTER TABLE\fR command needs an \fIaccess exclusive lock\fR on the target table\. . .IP "\(bu" 4 \fIdisable triggers\fR . .IP When this option is listed, pgloader issues an \fBALTER TABLE \.\.\. DISABLE TRIGGER ALL\fR command against the PostgreSQL target table before copying the data, then the command \fBALTER TABLE \.\.\. ENABLE TRIGGER ALL\fR once the \fBCOPY\fR is done\. . .IP This option allows loading data into a pre\-existing table ignoring the \fIforeign key constraints\fR and user defined triggers and may result in invalid \fIforeign key constraints\fR once the data is loaded\. Use with care\. . .IP "\(bu" 4 \fIskip header\fR . .IP Takes a numeric value as argument\. Instruct pgloader to skip that many lines at the beginning of the input file\. . .IP "\(bu" 4 \fIcsv header\fR . .IP Use the first line read after \fIskip header\fR as the list of csv field names to be found in the CSV file, using the same CSV parameters as for the CSV data\. . .IP "\(bu" 4 \fItrim unquoted blanks\fR . .IP When reading unquoted values in the \fBCSV\fR file, remove the blanks found in between the separator and the value\. That behaviour is the default\. . .IP "\(bu" 4 \fIkeep unquoted blanks\fR . .IP When reading unquoted values in the \fBCSV\fR file, keep blanks found in between the separator and the value\. . .IP "\(bu" 4 \fIfields optionally enclosed by\fR . .IP Takes a single character as argument, which must be found inside single quotes, and might be given as the printable character itself, the special value \et to denote a tabulation character, or \fB0x\fR then an hexadecimal value read as the ASCII code for the character\. . .IP This character is used as the quoting character in the \fBCSV\fR file, and defaults to double\-quote\. . .IP "\(bu" 4 \fIfields not enclosed\fR . .IP By default, pgloader will use the double\-quote character as the enclosing character\. If you have a CSV file where fields are not enclosed and are using double\-quote as an expected ordinary character, then use the option \fIfields not enclosed\fR for the CSV parser to accept those values\. . .IP "\(bu" 4 \fIfields escaped by\fR . .IP Takes either the special value \fIbackslash\-quote\fR or \fIdouble\-quote\fR, or any value supported by the \fIfields terminated by\fR option (see below)\. This value is used to recognize escaped field separators when they are to be found within the data fields themselves\. Defaults to \fIdouble\-quote\fR\. . .IP "\(bu" 4 \fIcsv escape mode\fR . .IP Takes either the special value \fIquote\fR (the default) or \fIfollowing\fR and allows the CSV parser to parse either only escaped field separator or any character (including CSV data) when using the \fIfollowing\fR value\. . .IP "\(bu" 4 \fIfields terminated by\fR . .IP Takes a single character as argument, which must be found inside single quotes, and might be given as the printable character itself, the special value \et to denote a tabulation character, or \fB0x\fR then an hexadecimal value read as the ASCII code for the character\. . .IP This character is used as the \fIfield separator\fR when reading the \fBCSV\fR data\. . .IP "\(bu" 4 \fIlines terminated by\fR . .IP Takes a single character as argument, which must be found inside single quotes, and might be given as the printable character itself, the special value \et to denote a tabulation character, or \fB0x\fR then an hexadecimal value read as the ASCII code for the character\. . .IP This character is used to recognize \fIend\-of\-line\fR condition when reading the \fBCSV\fR data\. . .IP "" 0 . .IP "" 0 . .SH "LOAD FIXED COLS" This command instructs pgloader to load data from a text file containing columns arranged in a \fIfixed size\fR manner\. Here\'s an example: . .IP "" 4 . .nf LOAD FIXED FROM inline ( a from 0 for 10, b from 10 for 8, c from 18 for 8, d from 26 for 17 [null if blanks, trim right whitespace] ) INTO postgresql:///pgloader?fixed ( a, b, c time using (time\-with\-no\-separator c), d ) WITH truncate SET work_mem to \'14MB\', standard_conforming_strings to \'on\' BEFORE LOAD DO $$ drop table if exists fixed; $$, $$ create table fixed ( a integer, b date, c time, d text ); $$; 01234567892008052011431250firstline 01234562008052115182300left blank\-padded 12345678902008052208231560another line 2345609872014092914371500 2345678902014092914371520 . .fi . .IP "" 0 . .P The \fBfixed\fR format command accepts the following clauses and options: . .IP "\(bu" 4 \fIFROM\fR . .IP Filename where to load the data from\. Accepts an \fIENCODING\fR option\. Use the \fB\-\-list\-encodings\fR option to know which encoding names are supported\. . .IP The filename may be enclosed by single quotes, and could be one of the following special values: . .IP "\(bu" 4 \fIinline\fR . .IP The data is found after the end of the parsed commands\. Any number of empty lines between the end of the commands and the beginning of the data is accepted\. . .IP "\(bu" 4 \fIstdin\fR . .IP Reads the data from the standard input stream\. . .IP "\(bu" 4 \fIFILENAMES MATCHING\fR . .IP The whole \fImatching\fR clause must follow the following rule: . .IP "" 4 . .nf [ ALL FILENAMES | [ FIRST ] FILENAME ] MATCHING regexp [ IN DIRECTORY \'\.\.\.\' ] . .fi . .IP "" 0 . .IP The \fImatching\fR clause applies given \fIregular expression\fR (see above for exact syntax, several options can be used here) to filenames\. It\'s then possible to load data from only the first match of all of them\. . .IP The optional \fIIN DIRECTORY\fR clause allows specifying which directory to walk for finding the data files, and can be either relative to where the command file is read from, or absolute\. The given directory must exists\. . .IP "" 0 . .IP The \fIFROM\fR option also supports an optional comma separated list of \fIfield\fR names describing what is expected in the \fBFIXED\fR data file\. . .IP Each field name is composed of the field name followed with specific reader options for that field\. Supported per\-field reader options are the following, where only \fIstart\fR and \fIlength\fR are required\. . .IP "\(bu" 4 \fIstart\fR . .IP Position in the line where to start reading that field\'s value\. Can be entered with decimal digits or \fB0x\fR then hexadecimal digits\. . .IP "\(bu" 4 \fIlength\fR . .IP How many bytes to read from the \fIstart\fR position to read that field\'s value\. Same format as \fIstart\fR\. . .IP "" 0 . .IP Those optional parameters must be enclosed in square brackets and comma\-separated: . .IP "\(bu" 4 \fIterminated by\fR . .IP See the description of \fIfield terminated by\fR below\. . .IP The processing of this option is not currently implemented\. . .IP "\(bu" 4 \fIdate format\fR . .IP When the field is expected of the date type, then this option allows to specify the date format used in the file\. . .IP Date format string are template strings modeled against the PostgreSQL \fBto_char\fR template strings support, limited to the following patterns: . .IP "\(bu" 4 YYYY, YYY, YY for the year part . .IP "\(bu" 4 MM for the numeric month part . .IP "\(bu" 4 DD for the numeric day part . .IP "\(bu" 4 HH, HH12, HH24 for the hour part . .IP "\(bu" 4 am, AM, a\.m\., A\.M\. . .IP "\(bu" 4 pm, PM, p\.m\., P\.M\. . .IP "\(bu" 4 MI for the minutes part . .IP "\(bu" 4 SS for the seconds part . .IP "\(bu" 4 MS for the milliseconds part (4 digits) . .IP "\(bu" 4 US for the microseconds part (6 digits) . .IP "\(bu" 4 unparsed punctuation signs: \- \. * # @ T / \e and space . .IP "" 0 . .IP Here\'s an example of a \fIdate format\fR specification: . .IP "" 4 . .nf column\-name [date format \'YYYY\-MM\-DD HH24\-MI\-SS\.US\'] . .fi . .IP "" 0 . .IP "\(bu" 4 \fInull if\fR . .IP This option takes an argument which is either the keyword \fIblanks\fR or a double\-quoted string\. . .IP When \fIblanks\fR is used and the field value that is read contains only space characters, then it\'s automatically converted to an SQL \fBNULL\fR value\. . .IP When a double\-quoted string is used and that string is read as the field value, then the field value is automatically converted to an SQL \fBNULL\fR value\. . .IP "\(bu" 4 \fItrim both whitespace\fR, \fItrim left whitespace\fR, \fItrim right whitespace\fR . .IP This option allows to trim whitespaces in the read data, either from both sides of the data, or only the whitespace characters found on the left of the streaing, or only those on the right of the string\. . .IP "" 0 . .IP "\(bu" 4 \fIWITH\fR . .IP When loading from a \fBFIXED\fR file, the following options are supported: . .IP "\(bu" 4 \fItruncate\fR . .IP When this option is listed, pgloader issues a \fBTRUNCATE\fR command against the PostgreSQL target table before reading the data file\. . .IP "\(bu" 4 \fIdisable triggers\fR . .IP When this option is listed, pgloader issues an \fBALTER TABLE \.\.\. DISABLE TRIGGER ALL\fR command against the PostgreSQL target table before copying the data, then the command \fBALTER TABLE \.\.\. ENABLE TRIGGER ALL\fR once the \fBCOPY\fR is done\. . .IP This option allows loading data into a pre\-existing table ignoring the \fIforeign key constraints\fR and user defined triggers and may result in invalid \fIforeign key constraints\fR once the data is loaded\. Use with care\. . .IP "\(bu" 4 \fIskip header\fR . .IP Takes a numeric value as argument\. Instruct pgloader to skip that many lines at the beginning of the input file\. . .IP "" 0 . .IP "" 0 . .SH "LOAD COPY FORMATTED FILES" This commands instructs pgloader to load from a file containing COPY TEXT data as described in the PostgreSQL documentation\. Here\'s an example: . .IP "" 4 . .nf LOAD COPY FROM copy://\./data/track\.copy ( trackid, track, album, media, genre, composer, milliseconds, bytes, unitprice ) INTO postgresql:///pgloader?track_full WITH truncate SET work_mem to \'14MB\', standard_conforming_strings to \'on\' BEFORE LOAD DO $$ drop table if exists track_full; $$, $$ create table track_full ( trackid bigserial, track text, album text, media text, genre text, composer text, milliseconds bigint, bytes bigint, unitprice numeric ); $$; . .fi . .IP "" 0 . .P The \fBCOPY\fR format command accepts the following clauses and options: . .IP "\(bu" 4 \fIFROM\fR . .IP Filename where to load the data from\. This support local files, HTTP URLs and zip files containing a single dbf file of the same name\. Fetch such a zip file from an HTTP address is of course supported\. . .IP "\(bu" 4 \fIinline\fR . .IP The data is found after the end of the parsed commands\. Any number of empty lines between the end of the commands and the beginning of the data is accepted\. . .IP "\(bu" 4 \fIstdin\fR . .IP Reads the data from the standard input stream\. . .IP "\(bu" 4 \fIFILENAMES MATCHING\fR . .IP The whole \fImatching\fR clause must follow the following rule: . .IP "" 4 . .nf [ ALL FILENAMES | [ FIRST ] FILENAME ] MATCHING regexp [ IN DIRECTORY \'\.\.\.\' ] . .fi . .IP "" 0 . .IP The \fImatching\fR clause applies given \fIregular expression\fR (see above for exact syntax, several options can be used here) to filenames\. It\'s then possible to load data from only the first match of all of them\. . .IP The optional \fIIN DIRECTORY\fR clause allows specifying which directory to walk for finding the data files, and can be either relative to where the command file is read from, or absolute\. The given directory must exists\. . .IP "" 0 . .IP "\(bu" 4 \fIWITH\fR . .IP When loading from a \fBCOPY\fR file, the following options are supported: . .IP "\(bu" 4 \fIdelimiter\fR . .IP Takes a single character as argument, which must be found inside single quotes, and might be given as the printable character itself, the special value \et to denote a tabulation character, or \fB0x\fR then an hexadecimal value read as the ASCII code for the character\. . .IP This character is used as the \fIdelimiter\fR when reading the data, in a similar way to the PostgreSQL \fBCOPY\fR option\. . .IP "\(bu" 4 \fInull\fR . .IP Takes a quoted string as an argument (quotes can be either double quotes or single quotes) and uses that string as the \fBNULL\fR representation in the data\. . .IP This is similar to the \fInull\fR \fBCOPY\fR option in PostgreSQL\. . .IP "\(bu" 4 \fItruncate\fR . .IP When this option is listed, pgloader issues a \fBTRUNCATE\fR command against the PostgreSQL target table before reading the data file\. . .IP "\(bu" 4 \fIdisable triggers\fR . .IP When this option is listed, pgloader issues an \fBALTER TABLE \.\.\. DISABLE TRIGGER ALL\fR command against the PostgreSQL target table before copying the data, then the command \fBALTER TABLE \.\.\. ENABLE TRIGGER ALL\fR once the \fBCOPY\fR is done\. . .IP This option allows loading data into a pre\-existing table ignoring the \fIforeign key constraints\fR and user defined triggers and may result in invalid \fIforeign key constraints\fR once the data is loaded\. Use with care\. . .IP "\(bu" 4 \fIskip header\fR . .IP Takes a numeric value as argument\. Instruct pgloader to skip that many lines at the beginning of the input file\. . .IP "" 0 . .IP "" 0 . .SH "LOAD DBF" This command instructs pgloader to load data from a \fBDBF\fR file\. Here\'s an example: . .IP "" 4 . .nf LOAD DBF FROM http://www\.insee\.fr/fr/methodes/nomenclatures/cog/telechargement/2013/dbf/reg2013\.dbf INTO postgresql://user@localhost/dbname WITH truncate, create table; . .fi . .IP "" 0 . .P The \fBdbf\fR format command accepts the following clauses and options: . .IP "\(bu" 4 \fIFROM\fR . .IP Filename where to load the data from\. This support local files, HTTP URLs and zip files containing a single dbf file of the same name\. Fetch such a zip file from an HTTP address is of course supported\. . .IP "\(bu" 4 \fIWITH\fR . .IP When loading from a \fBDBF\fR file, the following options are supported: . .IP "\(bu" 4 \fItruncate\fR . .IP When this option is listed, pgloader issues a \fBTRUNCATE\fR command against the PostgreSQL target table before reading the data file\. . .IP "\(bu" 4 \fIdisable triggers\fR . .IP When this option is listed, pgloader issues an \fBALTER TABLE \.\.\. DISABLE TRIGGER ALL\fR command against the PostgreSQL target table before copying the data, then the command \fBALTER TABLE \.\.\. ENABLE TRIGGER ALL\fR once the \fBCOPY\fR is done\. . .IP This option allows loading data into a pre\-existing table ignoring the \fIforeign key constraints\fR and user defined triggers and may result in invalid \fIforeign key constraints\fR once the data is loaded\. Use with care\. . .IP "\(bu" 4 \fIcreate table\fR . .IP When this option is listed, pgloader creates the table using the meta data found in the \fBDBF\fR file, which must contain a list of fields with their data type\. A standard data type conversion from DBF to PostgreSQL is done\. . .IP "\(bu" 4 \fItable name\fR . .IP This options expects as its value the possibly qualified name of the table to create\. . .IP "" 0 . .IP "" 0 . .SH "LOAD IXF" This command instructs pgloader to load data from an IBM \fBIXF\fR file\. Here\'s an example: . .IP "" 4 . .nf LOAD IXF FROM data/nsitra\.test1\.ixf INTO postgresql:///pgloader?nsitra\.test1 WITH truncate, create table, timezone UTC BEFORE LOAD DO $$ create schema if not exists nsitra; $$, $$ drop table if exists nsitra\.test1; $$; . .fi . .IP "" 0 . .P The \fBixf\fR format command accepts the following clauses and options: . .IP "\(bu" 4 \fIFROM\fR . .IP Filename where to load the data from\. This support local files, HTTP URLs and zip files containing a single ixf file of the same name\. Fetch such a zip file from an HTTP address is of course supported\. . .IP "\(bu" 4 \fIWITH\fR . .IP When loading from a \fBIXF\fR file, the following options are supported: . .IP "\(bu" 4 \fItruncate\fR . .IP When this option is listed, pgloader issues a \fBTRUNCATE\fR command against the PostgreSQL target table before reading the data file\. . .IP "\(bu" 4 \fIdisable triggers\fR . .IP When this option is listed, pgloader issues an \fBALTER TABLE \.\.\. DISABLE TRIGGER ALL\fR command against the PostgreSQL target table before copying the data, then the command \fBALTER TABLE \.\.\. ENABLE TRIGGER ALL\fR once the \fBCOPY\fR is done\. . .IP This option allows loading data into a pre\-existing table ignoring the \fIforeign key constraints\fR and user defined triggers and may result in invalid \fIforeign key constraints\fR once the data is loaded\. Use with care\. . .IP "\(bu" 4 \fIcreate table\fR . .IP When this option is listed, pgloader creates the table using the meta data found in the \fBDBF\fR file, which must contain a list of fields with their data type\. A standard data type conversion from DBF to PostgreSQL is done\. . .IP "\(bu" 4 \fItable name\fR . .IP This options expects as its value the possibly qualified name of the table to create\. . .IP "\(bu" 4 \fItimezone\fR . .IP This options allows to specify which timezone is used when parsing timestamps from an IXF file, and defaults to \fIUTC\fR\. Expected values are either \fBUTC\fR, \fBGMT\fR or a single quoted location name such as \fB\'Universal\'\fR or \fB\'Europe/Paris\'\fR\. . .IP "" 0 . .IP "" 0 . .SH "LOAD ARCHIVE" This command instructs pgloader to load data from one or more files contained in an archive\. Currently the only supported archive format is \fIZIP\fR, and the archive might be downloaded from an \fIHTTP\fR URL\. . .P Here\'s an example: . .IP "" 4 . .nf LOAD ARCHIVE FROM /Users/dim/Downloads/GeoLiteCity\-latest\.zip INTO postgresql:///ip4r BEFORE LOAD DO $$ create extension if not exists ip4r; $$, $$ create schema if not exists geolite; $$, EXECUTE \'geolite\.sql\' LOAD CSV FROM FILENAME MATCHING ~/GeoLiteCity\-Location\.csv/ WITH ENCODING iso\-8859\-1 ( locId, country, region null if blanks, city null if blanks, postalCode null if blanks, latitude, longitude, metroCode null if blanks, areaCode null if blanks ) INTO postgresql:///ip4r?geolite\.location ( locid,country,region,city,postalCode, location point using (format nil "(~a,~a)" longitude latitude), metroCode,areaCode ) WITH skip header = 2, fields optionally enclosed by \'"\', fields escaped by double\-quote, fields terminated by \',\' AND LOAD CSV FROM FILENAME MATCHING ~/GeoLiteCity\-Blocks\.csv/ WITH ENCODING iso\-8859\-1 ( startIpNum, endIpNum, locId ) INTO postgresql:///ip4r?geolite\.blocks ( iprange ip4r using (ip\-range startIpNum endIpNum), locId ) WITH skip header = 2, fields optionally enclosed by \'"\', fields escaped by double\-quote, fields terminated by \',\' FINALLY DO $$ create index blocks_ip4r_idx on geolite\.blocks using gist(iprange); $$; . .fi . .IP "" 0 . .P The \fBarchive\fR command accepts the following clauses and options: . .IP "\(bu" 4 \fIFROM\fR . .IP Filename or HTTP URI where to load the data from\. When given an HTTP URL the linked file will get downloaded locally before processing\. . .IP If the file is a \fBzip\fR file, the command line utility \fBunzip\fR is used to expand the archive into files in \fB$TMPDIR\fR, or \fB/tmp\fR if \fB$TMPDIR\fR is unset or set to a non\-existing directory\. . .IP Then the following commands are used from the top level directory where the archive has been expanded\. . .IP "\(bu" 4 command [ \fIAND\fR command \.\.\. ] . .IP A series of commands against the contents of the archive, at the moment only \fBCSV\fR,\fB\'FIXED\fR and \fBDBF\fR commands are supported\. . .IP Note that commands are supporting the clause \fIFROM FILENAME MATCHING\fR which allows the pgloader command not to depend on the exact names of the archive directories\. . .IP The same clause can also be applied to several files with using the spelling \fIFROM ALL FILENAMES MATCHING\fR and a regular expression\. . .IP The whole \fImatching\fR clause must follow the following rule: . .IP "" 4 . .nf FROM [ ALL FILENAMES | [ FIRST ] FILENAME ] MATCHING . .fi . .IP "" 0 . .IP "\(bu" 4 \fIFINALLY DO\fR . .IP SQL Queries to run once the data is loaded, such as \fBCREATE INDEX\fR\. . .IP "" 0 . .SH "LOAD MYSQL DATABASE" This command instructs pgloader to load data from a database connection\. The only supported database source is currently \fIMySQL\fR, and pgloader supports dynamically converting the schema of the source database and the indexes building\. . .P A default set of casting rules are provided and might be overloaded and appended to by the command\. . .P Here\'s an example: . .IP "" 4 . .nf LOAD DATABASE FROM mysql://root@localhost/sakila INTO postgresql://localhost:54393/sakila WITH include drop, create tables, create indexes, reset sequences, workers = 8, concurrency = 1 SET maintenance_work_mem to \'128MB\', work_mem to \'12MB\', search_path to \'sakila\' CAST type datetime to timestamptz drop default drop not null using zero\-dates\-to\-null, type date drop not null drop default using zero\-dates\-to\-null, \-\- type tinyint to boolean using tinyint\-to\-boolean, type year to integer MATERIALIZE VIEWS film_list, staff_list \-\- INCLUDING ONLY TABLE NAMES MATCHING ~/film/, \'actor\' \-\- EXCLUDING TABLE NAMES MATCHING ~ \-\- DECODING TABLE NAMES MATCHING ~/messed/, ~/encoding/ AS utf8 \-\- ALTER TABLE NAMES MATCHING \'film\' RENAME TO \'films\' \-\- ALTER TABLE NAMES MATCHING ~/_list$/ SET SCHEMA \'mv\' BEFORE LOAD DO $$ create schema if not exists sakila; $$; . .fi . .IP "" 0 . .P The \fBdatabase\fR command accepts the following clauses and options: . .IP "\(bu" 4 \fIFROM\fR . .IP Must be a connection URL pointing to a MySQL database\. . .IP If the connection URI contains a table name, then only this table is migrated from MySQL to PostgreSQL\. . .IP See the \fBSOURCE CONNECTION STRING\fR section above for details on how to write the connection string\. Environment variables described in \fIhttp://dev\.mysql\.com/doc/refman/5\.0/en/environment\-variables\.html\fR can be used as default values too\. If the user is not provided, then it defaults to \fBUSER\fR environment variable value\. The password can be provided with the environment variable \fBMYSQL_PWD\fR\. The host can be provided with the environment variable \fBMYSQL_HOST\fR and otherwise defaults to \fBlocalhost\fR\. The port can be provided with the environment variable \fBMYSQL_TCP_PORT\fR and otherwise defaults to \fB3306\fR\. . .IP "\(bu" 4 \fIWITH\fR . .IP When loading from a \fBMySQL\fR database, the following options are supported, and the efault \fIWITH\fR clause is: \fIno truncate\fR, \fIcreate tables\fR, \fIinclude drop\fR, \fIcreate indexes\fR, \fIreset sequences\fR, \fIforeign keys\fR, \fIdowncase identifiers\fR\. . .IP \fIWITH\fR options: . .IP "\(bu" 4 \fIinclude drop\fR . .IP When this option is listed, pgloader drops all the tables in the target PostgreSQL database whose names appear in the MySQL database\. This option allows for using the same command several times in a row until you figure out all the options, starting automatically from a clean environment\. Please note that \fBCASCADE\fR is used to ensure that tables are dropped even if there are foreign keys pointing to them\. This is precisely what \fBinclude drop\fR is intended to do: drop all target tables and recreate them\. . .IP Great care needs to be taken when using \fBinclude drop\fR, as it will cascade to \fIall\fR objects referencing the target tables, possibly including other tables that are not being loaded from the source DB\. . .IP "\(bu" 4 \fIinclude no drop\fR . .IP When this option is listed, pgloader will not include any \fBDROP\fR statement when loading the data\. . .IP "\(bu" 4 \fItruncate\fR . .IP When this option is listed, pgloader issue the \fBTRUNCATE\fR command against each PostgreSQL table just before loading data into it\. . .IP "\(bu" 4 \fIno truncate\fR . .IP When this option is listed, pgloader issues no \fBTRUNCATE\fR command\. . .IP "\(bu" 4 \fIdisable triggers\fR . .IP When this option is listed, pgloader issues an \fBALTER TABLE \.\.\. DISABLE TRIGGER ALL\fR command against the PostgreSQL target table before copying the data, then the command \fBALTER TABLE \.\.\. ENABLE TRIGGER ALL\fR once the \fBCOPY\fR is done\. . .IP This option allows loading data into a pre\-existing table ignoring the \fIforeign key constraints\fR and user defined triggers and may result in invalid \fIforeign key constraints\fR once the data is loaded\. Use with care\. . .IP "\(bu" 4 \fIcreate tables\fR . .IP When this option is listed, pgloader creates the table using the meta data found in the \fBMySQL\fR file, which must contain a list of fields with their data type\. A standard data type conversion from DBF to PostgreSQL is done\. . .IP "\(bu" 4 \fIcreate no tables\fR . .IP When this option is listed, pgloader skips the creation of table before loading data, target tables must then already exist\. . .IP Also, when using \fIcreate no tables\fR pgloader fetches the metadata from the current target database and checks type casting, then will remove constraints and indexes prior to loading the data and install them back again once the loading is done\. . .IP "\(bu" 4 \fIcreate indexes\fR . .IP When this option is listed, pgloader gets the definitions of all the indexes found in the MySQL database and create the same set of index definitions against the PostgreSQL database\. . .IP "\(bu" 4 \fIcreate no indexes\fR . .IP When this option is listed, pgloader skips the creating indexes\. . .IP "\(bu" 4 \fIuniquify index names\fR, \fIpreserve index names\fR . .IP MySQL index names are unique per\-table whereas in PostgreSQL index names have to be unique per\-schema\. The default for pgloader is to change the index name by prefixing it with \fBidx_OID\fR where \fBOID\fR is the internal numeric identifier of the table the index is built against\. . .IP In somes cases like when the DDL are entirely left to a framework it might be sensible for pgloader to refrain from handling index unique names, that is achieved by using the \fIpreserve index names\fR option\. . .IP The default is to \fIuniquify index names\fR\. . .IP Even when using the option \fIpreserve index names\fR, MySQL primary key indexes named "PRIMARY" will get their names uniquified\. Failing to do so would prevent the primary keys to be created again in PostgreSQL where the index names must be unique per schema\. . .IP "\(bu" 4 \fIforeign keys\fR . .IP When this option is listed, pgloader gets the definitions of all the foreign keys found in the MySQL database and create the same set of foreign key definitions against the PostgreSQL database\. . .IP "\(bu" 4 \fIno foreign keys\fR . .IP When this option is listed, pgloader skips creating foreign keys\. . .IP "\(bu" 4 \fIreset sequences\fR . .IP When this option is listed, at the end of the data loading and after the indexes have all been created, pgloader resets all the PostgreSQL sequences created to the current maximum value of the column they are attached to\. . .IP The options \fIschema only\fR and \fIdata only\fR have no effects on this option\. . .IP "\(bu" 4 \fIreset no sequences\fR . .IP When this option is listed, pgloader skips resetting sequences after the load\. . .IP The options \fIschema only\fR and \fIdata only\fR have no effects on this option\. . .IP "\(bu" 4 \fIdowncase identifiers\fR . .IP When this option is listed, pgloader converts all MySQL identifiers (table names, index names, column names) to \fIdowncase\fR, except for PostgreSQL \fIreserved\fR keywords\. . .IP The PostgreSQL \fIreserved\fR keywords are determined dynamically by using the system function \fBpg_get_keywords()\fR\. . .IP "\(bu" 4 \fIquote identifiers\fR . .IP When this option is listed, pgloader quotes all MySQL identifiers so that their case is respected\. Note that you will then have to do the same thing in your application code queries\. . .IP "\(bu" 4 \fIschema only\fR . .IP When this option is listed pgloader refrains from migrating the data over\. Note that the schema in this context includes the indexes when the option \fIcreate indexes\fR has been listed\. . .IP "\(bu" 4 \fIdata only\fR . .IP When this option is listed pgloader only issues the \fBCOPY\fR statements, without doing any other processing\. . .IP "" 0 . .IP "\(bu" 4 \fICAST\fR . .IP The cast clause allows to specify custom casting rules, either to overload the default casting rules or to amend them with special cases\. . .IP A casting rule is expected to follow one of the forms: . .IP "" 4 . .nf type [ \.\.\. ] to [