PostgreSQL, storing encrypted data or encrypt database with pgcrypto - what is more secure?
Yes - it is certainly possible that a key used in pgcrypto function would end up in server logs or leak somewhere else.

Postgres could be configured to log long running queries (and for example password hash functions are long running by design) or even all of them. There are utilities that show current running queries. Or an error in a query can leak it in an error message.

So, if I had a choice, I'd use cryptographic functions from a frontend language.