Search code examples
postgresqlcsvrdbmsbulk-load

Get time to populate a POSTGRES table from csv file


Is there any way to determine the time which the Postgres takes to populate a table from a csv file. I tried using 'time' command but it did not work.

time copy TABLE_NAME from /home/ankit/Documents/file.csv delimiter ',' csv header ;

The error was: ERROR: syntax error at or near "time"

I am using Ubuntu 16.04


Solution

  • This depends on how you're submitting the query to Postgres. If you're using the psql command line client in a shell you can add the time command before it. So for example it would be something like the following:

    time psql -c "copy TABLE_NAME from /home/ankit/Documents/file.csv delimiter ',' csv header ;"
    

    You might also need to add connection parameters to the command.

    Another way if you're using psql is to use the following command and psql will print how much time each query takes:

    \timing