1

I'm going to deploy my application on Heroku, for this purpose I created a database there. As Hibernate's option hibernate.hbm2ddl.auto=create didn't work I wrote a SQL queries manually. Everything went good until I tried to insert a BLOB to the database.

I have a table photo:

CREATE TABLE photo (
  id      SERIAL PRIMARY KEY,
  content BYTEA
);

and I'm doing such insertion query:

INSERT INTO photo (content) VALUES (pg_read_file('./files/images/01_Tomato-Soup.jpg')::BYTEA);

After this step I get an error:

[2016-07-15 18:57:01] [42501] ERROR: must be superuser to read files

Inserting of other entities also fails as they have a foreign key to photo table.

What is this error about, is it possible to insert BLOBs in Heroku database not being a superuser?

1 Answer 1

2

Server-side file access is super-user-only because it runs with the file permissions of the server. If you can read file you could, for example read database files in and store that. And you could destroy data through writes.

The file access functions on the server are thus relatively limited to things like administrative actions. For your application you want to do something different. For bytea, use whatever client-side libraries you would to do the escaping. This will be dependent on language (it is different in Perl, PHP, Java, etc).

One thing to note is that the escaping and unescaping of bytea fields takes quite a bit of RAM so figure it may take 8 or more times the ram than the file is large. So that is just one thing to think about.

Sign up to request clarification or add additional context in comments.

6 Comments

Do you mean I need to convert byte array into a String? I use Java. So is it impossible to store BYTEA in database on Heroku?
Every driver I have ever worked with has facilities to do the conversion for you. JDBC is no different.
Read it into a byte[] in java and then save that in the db? See stackoverflow.com/questions/3677380/…
the problem was that pg_read_file reads file from the SERVER, not my LOCAL file as I thought. Now everything works perfectly! Thank you again.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.