2

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

Ankit Shubham
  • 2,989
  • 2
  • 36
  • 61

2 Answers2

5

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
Leo
  • 2,088
  • 1
  • 15
  • 14
2

There should be field like "created" of type "timestamp without time zone" in your table and you can also assign default value as now() in the column definition screen.

Then each record will be asseigned with created timestamp either it was loaded from csv or created by any other way.

Or in SQL:

ALTER TABLE mytable ADD COLUMN created TIMESTAMP;
ALTER TABLE mytable ALTER COLUMN created SET DEFAULT now();
Eugene Bartosh
  • 324
  • 3
  • 12