Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying CSV to Amazon RDS hosted Postgresql database

I have a database hosted using Amazon's RDS service and I am attempting to write a web service that will update said database. The problem I am having is that it will not let me use the COPY command as I get this error: "ERROR: must be superuser to COPY to or from a file". I am using the only user I have made for the database and I am fairly certain it has superuser access. I can, however, use PGAdmin's import tool to import the data which, when looking at the log, uses almost the exact same command as I do. The only difference is instead of the file path it has stdin. How can I fix this error?

like image 264
Scott Gibson Avatar asked Aug 08 '14 14:08

Scott Gibson


People also ask

How do I copy a CSV file into a Postgres table?

After creating the sample CSV file and table, you can now easily execute the PostgreSQL Import CSV task via any of the following methods: Method 1: Perform PostgreSQL Import CSV Job using the COPY Command. Method 2: Perform PostgreSQL Import CSV Job using PgAdmin.

Can we import data into an RDS instance?

To import data from an existing database to an RDS DB instance: Export data from the source database. Upload the exported data. Import the uploaded data into an RDS DB instance.

What is the best way to transfer the data in a PostgreSQL database?

Data export with pg_dump The idea behind this dump method is to generate a file with SQL commands that, when fed back to the server, will recreate the database in the same state as it was at the time of the dump. PostgreSQL provides the utility program pg_dump for this purpose.


1 Answers

You're using:

COPY tablename FROM 'filename';

this won't work - RDS has no idea what 'filename' is.

You must use the psql command's \copy, which copies from the local client, or PgAdmin-III's "import data" option.

The RDS manual covers this in more detail.

like image 75
Craig Ringer Avatar answered Oct 19 '22 15:10

Craig Ringer