how to convert my PostgreSQL database table into CSV?
On Windows, PostgreSQL runs as "Network Service". "Network Service" will need write permissions to c:\tmp if you want it to write there.

Generally I recommend using psql's \copy command instead of copy, as it doesn't need superuser permission in the db, and can write wherever your shell user can write. 

Open up cmd:

&gt; cd c:\tmp
&gt; set PGDATABASE=$nameOfYourDatabase
&gt; set PGUSER=$pgUsername
&gt; set PGPASSWORD=$thePassword
&gt; psql

&gt; \copy persons to 'persons_db.csv' with (format csv, header true);
&gt; \q