1

I'm currently working to move some plaintext data in Postgres to an encrypted format. I'm using Go and most cryptographic functions intake and output byte arrays. I also need to support key rotation and will generally by using the byte format to pack additional data at the front of values for metadata.

The columns are currently TEXT in Postgres 12.

Would there be any advantage to storing the output directly as BYTEA (in a new column) or would base64 encoding the values and storing them back into the same column provide better performance (faster reads/writes).

Both approaches would require an equal amount of refactoring to support other SELECT statements in the code.

2
  • 1
    I don't have a specific answer for you, but base64-encoding the bytes increases the required storage space by around 25%, and of course requires an encoding/decoding step in each direction. From those facts alone I would expect a BYTEA column to be more performant. Commented Sep 9, 2020 at 0:33
  • @larsks, 33%. 8 bits of output (one ASCII character) for every 6 bits of input (2**6 = 64). Commented Sep 9, 2020 at 8:00

1 Answer 1

5

Definitely go with bytea. Converting to and from Base-64 is just an unnecessary waste of CPU time, and the result will waste storage space.

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

Comments

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.