The octet_length function returns the length in bytes size of a bytea field. From the docs: “Number of bytes in binary string”.

More binary string functions