Sova Kefirova
Sova Kefirova

Reputation: 201

What functions are called when working with the Postgres database

I need to implement transparent encryption in Postgres (TDE). To do this, I found which functions are called when INSERT and SELECT are triggered. Used LLVM-LLDB on SELECT.

I'm trying to do the same with INSERT - does not work

the base process stops and does not allow insertion. I did everything about one manual https://eax.me/lldb/.

What could be wrong? how to find out which functions are called upon insertion (in the case of SELECT, this is secure_read, etc.)? And, if anyone knows how to change the function code in the source?

First, the client and server are located on the same machine, the same user adds data and reads them

Unfortunately I do not have enough reputation to add a screenshots.

Upvotes: 0

Views: 88

Answers (2)

Laurenz Albe
Laurenz Albe

Reputation: 246463

The SQL statements are the wrong level to start debugging. You should look at the code where blocks are read and written. That would be in src/backend/storage/smgr. Look at the functions mdread and mdwrite in md.c. This is probably where you'd start hacking.

PostgreSQL v12 has introduced “pluggable storage”, so you can write your own storage manager. See the documentation. If you don't want to patch PostgreSQL, but have an extension that will work with standard PostgreSQL, that would be the direction to take.

So far I have only covered block storage, but you must not forget WAL. Encrypting that will require hacking PostgreSQL.

Upvotes: 1

pifor
pifor

Reputation: 7882

This is a complex question which you should post to PostgreSQL hackers distribution list https://www.postgresql.org/list/pgsql-hackers/.

You could start by setting a GDB breakpoint in Executor_Start in execMain.c

Upvotes: 0

Related Questions