Using gdb for command-line debugging still feels inconvenient. I initially wanted to find a simpler way to directly debug the PostgreSQL source code under Windows. After searching for a while, I found that Visual Studio (VS) was the only option available, but it is heavy and the steps are quite complex. Since most real environments run on Linux, it is better to debug the PostgreSQL source code under Linux.
I used Ubuntu Linux environment, the first step we might need to install pre-requirement tool for PostgreSQL build.
sudo apt-get update
download PostgreSQL source code.
we would need to make sure the path (
--prefix) exist in your system.
./configure --prefix=/home/daniel/postgresql-14.8/pgsql --with-icu --with-openssl --with-systemd --with-libxml --enable-debug
we must build with
--enable-debugparameter, otherwise we can’t debug with our source code.
Here are commands we would use later.
I would recommend setup PostgreSQL environment path, after we build & install PostgreSQL program from source code that would assist with us easier our next steps.
Identify your shell: Determine which shell you are using by running the following command:
It will display the path to your current shell.
Locate the configuration file: The configuration file you need to modify depends on your shell. Here are the common ones:
- Bash: ~/.bashrc or ~/.bash_profile
- Zsh: ~/.zshrc or ~/.zprofile
- Fish: ~/.config/fish/config.fish
Open the configuration file: Use a text editor, such as nano or vim, to open the configuration file. For example, if you are using Bash and the file is
~/.bashrc, you can
please modify with your environment
PATH setting align with your PostgreSQL build bin & data path.
because my build parameter used
--prefix=/home/daniel/postgresql-14.8/pgsqlso the setting would be align with that.
Update the environment: To apply the changes to your current session, run the following command in your terminal:
source ~/.bashrc # or the appropriate file for your shell
To create the keys, a preferred command is ssh-keygen, which is available with OpenSSH utilities.
ssh-keygen -m PEM -t rsa -b 4096
When you create an Azure VM by specifying the public key, Azure copies the public key (in the .pub format) to the
~/.ssh/authorized_keys folder on the VM. SSH keys in
~/.ssh/authorized_keys ensure that connecting clients present the corresponding private key during an SSH connection.
danielkey (pem file) to your local machine, then you might login via the pem file.
Confirm that the permissions of the
.ssh directory and the authorized_keys file on the server are set correctly. Run the following commands on the server:
chmod 700 ~/.ssh
These commands ensure that the directory has read, write, and execute permissions only for the user, and the
authorized_keys file has read and write permissions only for the user.
Please follow below config
Modify “program” column with PostgreSQL binary file path from json file
Final used ssh with pem file to login your VM via VsCode.
Here is the demo for vscode debug PostgreSQL running process by sourcecode.
Regarding to Troubleshoot attaching to processes using GDB
Run the following command as super user:
echo 0| sudo tee /proc/sys/kernel/yama/ptrace_scope
This will set the ptrace level to 0, after this just with user permissions you can attach to processes which are not launched by the debugger.
postgresdebuger:~$ echo 0| sudo tee /proc/sys/kernel/yama/ptrace_scope-
版權聲明：本博客所有文章除特別聲明外，均採用 CC BY-NC-SA 3.0 TW 許可協議。轉載請註明出處！