<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Yuya Shinde</title>
    <description>The latest articles on DEV Community by Yuya Shinde (@yuyash).</description>
    <link>https://dev.to/yuyash</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1640165%2Fd3d6f9dc-af60-447b-96d5-2e176671115f.jpeg</url>
      <title>DEV Community: Yuya Shinde</title>
      <link>https://dev.to/yuyash</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yuyash"/>
    <language>en</language>
    <item>
      <title>Using VS Code Tasks for PostgreSQL Development</title>
      <dc:creator>Yuya Shinde</dc:creator>
      <pubDate>Fri, 21 Mar 2025 05:11:27 +0000</pubDate>
      <link>https://dev.to/yuyash/using-vs-code-tasks-for-postgresql-development-4cme</link>
      <guid>https://dev.to/yuyash/using-vs-code-tasks-for-postgresql-development-4cme</guid>
      <description>&lt;p&gt;This post builds upon the content presented in our previous two articles, providing further guidance with additional configurations.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/yuyash/building-and-running-postgresql-from-source-code-55gk"&gt;Building and Running PostgreSQL from Source Code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/yuyash/debugging-postgresql-with-visual-studio-code-5am5"&gt;Debugging PostgreSQL with GDB + Visual Studio Code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/yuyash/setting-up-intellisense-for-postgresql-development-gm"&gt;Setting up IntelliSense for PostgreSQL Development&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When developing with PostgreSQL, it's often necessary to perform various operations such as compiling, installing, initializing the database, starting and stopping the server. In this article, we'll show you how to add these tasks to Visual Studio Code (VS Code) using the Task feature.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Tasks in VS Code?
&lt;/h2&gt;

&lt;p&gt;Tasks in VS Code allow you to automate build scripts and external operations by creating a configuration file called tasks.json. This file is located in the &lt;code&gt;.vscode&lt;/code&gt; directory of your workspace. By defining tasks, you can easily run them from within VS Code, making it easier to manage your development workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Tasks for PostgreSQL Development
&lt;/h2&gt;

&lt;p&gt;To create tasks for PostgreSQL development, we'll need to add a new configuration file named &lt;code&gt;tasks.json&lt;/code&gt; to our workspace. Here's an example of what the file might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Configure",
            "type": "shell",
            "command": "./configure",
            "args": [
                "--prefix=${PG_BUILD_DIR}",
                "--enable-depend",
                "--enable-debug",
                "--enable-cassert",
                "--enable-tap-tests",
                "CFLAGS=-O0"
            ],
            "options": {
                "cwd": "${workspaceFolder}",
                "env": {
                    "PG_BUILD_DIR": "${workspaceFolder}/../build/pgsql/master"
                }
            },
            "group": {
                "kind": "build",
                "isDefault": false
            },
            "problemMatcher": [],
            "presentation": {
                "reveal": "never",
                "revealProblems": "onProblem",
                "showReuseMessage": false,
                "panel": "shared"
            }        
        },
        {
            "label": "Build",
            "type": "shell",
            "command": "make",
            "args": [],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "group": {
                "kind": "build",
                "isDefault": false
            },
            "dependsOn": [
            ],
            "problemMatcher": [],
            "hide": true
        },
        {
            "label": "Build &amp;amp; Install",
            "type": "shell",
            "command": "make",
            "args": [
                "install"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "dependsOn": [
                "Build"
            ],
            "problemMatcher": [],
            "presentation": {
                "reveal": "never",
                "revealProblems": "onProblem",
                "showReuseMessage": false,
                "panel": "shared"
            }        
        },
        {
            "label": "Clean",
            "type": "shell",
            "command": "make",
            "args": [
                "clean"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "group": {
                "kind": "build",
                "isDefault": false
            },
            "problemMatcher": [],
            "presentation": {
                "reveal": "never",
                "revealProblems": "onProblem",
                "showReuseMessage": false,
                "panel": "shared"
            }
        },
        {
            "label": "CleanDataFolder",
            "type": "shell",
            "command": "rm",
            "args": [
                "-rf", "${PG_BUILD_DIR}/data/*"
            ],
            "options": {
                "cwd": "${workspaceFolder}",
                "env": {
                    "PG_BUILD_DIR": "${workspaceFolder}/../build/pgsql/master"
                }
            },
            "group": {
                "kind": "build",
                "isDefault": false
            },
            "problemMatcher": [],
            "hide": true
        },
        {
            "label": "CreateDataFolder",
            "type": "shell",
            "command": "mkdir -p ${PG_BUILD_DIR}/data",
            "args": [
            ],
            "options": {
                "cwd": "${workspaceFolder}",
                "env": {
                    "PG_BUILD_DIR": "${workspaceFolder}/../build/pgsql/master"
                }
            },
            "group": {
                "kind": "test",
                "isDefault": false
            },
            "dependsOn": [
            ],
            "problemMatcher": [],
            "hide": true
        },
        {
            "label": "InitDB",
            "type": "shell",
            "command": "${PG_BUILD_DIR}/bin/initdb -D ${PG_BUILD_DIR}/data",
            "args": [
            ],
            "options": {
                "cwd": "${workspaceFolder}",
                "env": {
                    "PG_BUILD_DIR": "${workspaceFolder}/../build/pgsql/master"
                }
            },
            "group": {
                "kind": "test",
                "isDefault": false
            },
            "dependsOn": [
            ],
            "problemMatcher": [],
            "hide": true
        },
        {
            "label": "Init &amp;amp; Run",
            "type": "shell",
            "command": "sudo",
            "args": [
                "-u", "${USER}",
                "${PG_BUILD_DIR}/bin/pg_ctl",
                "-D", "${PG_BUILD_DIR}/data",
                "-l", "${PG_BUILD_DIR}/data/logfile",
                "start"
            ],
            "options": {
                "cwd": "${workspaceFolder}",
                "env": {
                    "PG_BUILD_DIR": "${workspaceFolder}/../build/pgsql/master"
                }
            },
            "group": {
                "kind": "test",
                "isDefault": false
            },
            "dependsOn": [
                "CleanDataFolder",
                "CreateDataFolder", 
                "InitDB",
            ],
            "problemMatcher": [],
            "presentation": {
                "reveal": "never",
                "revealProblems": "onProblem",
                "showReuseMessage": false,
                "panel": "shared"
            }        
        },
        {
            "label": "Run",
            "type": "shell",
            "command": "sudo",
            "args": [
                "-u", "${USER}",
                "${PG_BUILD_DIR}/bin/pg_ctl",
                "-D", "${PG_BUILD_DIR}/data",
                "-l", "${PG_BUILD_DIR}/data/logfile",
                "start"
            ],
            "options": {
                "cwd": "${workspaceFolder}",
                "env": {
                    "PG_BUILD_DIR": "${workspaceFolder}/../build/pgsql/master"
                }
            },
            "group": {
                "kind": "test",
                "isDefault": false
            },
            "dependsOn": [
            ],
            "problemMatcher": [],
            "presentation": {
                "reveal": "never",
                "revealProblems": "onProblem",
                "showReuseMessage": false,
                "panel": "shared"
            }        
        },
        {
            "label": "Stop",
            "type": "shell",
            "command": "sudo",
            "args": [
                "-u", "${USER}",
                "${PG_BUILD_DIR}/bin/pg_ctl", "stop",
                "-D", "${PG_BUILD_DIR}/data",
                "-m", "smart"
            ],
            "options": {
                "cwd": "${workspaceFolder}",
                "env": {
                    "PG_BUILD_DIR": "${workspaceFolder}/../build/pgsql/master"
                }
            },
            "group": {
                "kind": "test",
                "isDefault": false
            },
            "dependsOn": [],
            "problemMatcher": [],
            "presentation": {
                "reveal": "never",
                "revealProblems": "onProblem",
                "showReuseMessage": false,
                "panel": "shared"
            }
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we've defined several tasks for PostgreSQL development, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Configure&lt;/strong&gt;: runs the ./configure script with various options&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build &amp;amp; Install&lt;/strong&gt;: runs both &lt;code&gt;make&lt;/code&gt; and &lt;code&gt;make install&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clean&lt;/strong&gt;: runs &lt;code&gt;make clean&lt;/code&gt; to delete built objects&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Init &amp;amp; Run&lt;/strong&gt;: initializes the database and starts the server&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run&lt;/strong&gt;: starts the server&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stop&lt;/strong&gt;: stops the server&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each task has a unique label, type, command, and arguments. Details of each option are described on the following &lt;a href="https://code.visualstudio.com/docs/editor/tasks" rel="noopener noreferrer"&gt;page&lt;/a&gt;. The &lt;a href="https://code.visualstudio.com/docs/reference/tasks-appendix" rel="noopener noreferrer"&gt;JSON schema definition&lt;/a&gt; is also useful to understand what you can set in the each attribute.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running Tasks in VS Code
&lt;/h2&gt;

&lt;p&gt;To run a task in VS Code, follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the Command Palette by pressing Cmd+Shift+P (Mac)&lt;/li&gt;
&lt;li&gt;Type "Task: Run Task" and select the task you want to run&lt;/li&gt;
&lt;li&gt;Press Enter to run the task&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Alternatively, you can also run tasks from the Terminal in VS Code by typing task .&lt;/p&gt;

&lt;p&gt;By adding these tasks to your VS Code configuration, you'll be able to easily manage your PostgreSQL development workflow and automate repetitive tasks.&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>postgressql</category>
      <category>vscode</category>
    </item>
    <item>
      <title>Setting up IntelliSense for PostgreSQL Development</title>
      <dc:creator>Yuya Shinde</dc:creator>
      <pubDate>Thu, 20 Mar 2025 04:56:48 +0000</pubDate>
      <link>https://dev.to/yuyash/setting-up-intellisense-for-postgresql-development-gm</link>
      <guid>https://dev.to/yuyash/setting-up-intellisense-for-postgresql-development-gm</guid>
      <description>&lt;p&gt;This post builds upon the content presented in our previous two articles, providing further guidance with additional configurations.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/yuyash/building-and-running-postgresql-from-source-code-55gk"&gt;Building and Running PostgreSQL from Source Code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/yuyash/debugging-postgresql-with-visual-studio-code-5am5"&gt;Debugging PostgreSQL with GDB + Visual Studio Code&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As a developer working on an open source project, it's essential to have a seamless development experience. One way to achieve this is by setting up IntelliSense in Visual Studio Code (VS Code). &lt;a href="https://code.visualstudio.com/docs/editor/intellisense" rel="noopener noreferrer"&gt;IntelliSense&lt;/a&gt; is a Microsoft-developed set of code-completion features, primarily known for its use in Visual Studio and Visual Studio Code, that provides real-time suggestions, auto-completion, and context-aware documentation for various programming languages. &lt;/p&gt;

&lt;p&gt;In this post, we'll explore how to configure IntelliSense to work with PostgreSQL source code and exclude unnecessary files from Git changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1. Configuring IntelliSense
&lt;/h2&gt;

&lt;p&gt;To set up IntelliSense, create a &lt;code&gt;c_cpp_properties.json&lt;/code&gt; file in the &lt;code&gt;.vscode&lt;/code&gt; directory of your project. This file will contain settings for the compiler and include paths. Here's an example configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "env": {
        "myIncludePath": ["${workspaceFolder}/src/include", "${workspaceFolder}/src/interfaces/**"],
        "myDefines": []
    },
    "configurations": [
        {
            "name": "Linux (GCC ARM64)",
            "compilerPath": "/usr/bin/gcc",
            "compilerArgs": ["-D_GNU_SOURCE"],
            "intelliSenseMode": "linux-gcc-arm64",
            "includePath": [ "${myIncludePath}", "/usr/include", "/usr/local/include" ],
            "defines": [ "${myDefines}" ],
            "cStandard": "${default}",
            "configurationProvider": "ms-vscode.cmake-tools",
            "mergeConfigurations": true
          }
    ],
    "version": 4,
    "enableConfigurationSquiggles": true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration sets up the compiler path, include paths for PostgreSQL and standard libraries, and defines. The predefined argument &lt;code&gt;workspaceFolder&lt;/code&gt; points the path of the folder opened in VS Code. VS Code provides some other predefined variables, whose definitions can be found &lt;a href="https://code.visualstudio.com/docs/reference/variables-reference" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;intelliSenseMode&lt;/code&gt; needs to be set appropriately for your platform. This &lt;a href="https://github.com/microsoft/vscode-cpptools/blob/main/Extension/c_cpp_properties.schema.json" rel="noopener noreferrer"&gt;link&lt;/a&gt; has a list of platforms where you can set it.&lt;/p&gt;

&lt;p&gt;Since PostgreSQL depends on GNU functions, setting &lt;code&gt;-D_GNU_SOURCE&lt;/code&gt; is  necessary to get appropriate code-completion. &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2. Excluding Files from Git Changes
&lt;/h2&gt;

&lt;p&gt;When working on a project, you may not want to commit certain files, such as those in the .vscode directory or log files. To exclude these files from Git changes without adding them to the &lt;code&gt;.gitignore&lt;/code&gt; file (which would require committing), you can use the exclude file in the &lt;code&gt;.git/info&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;To exclude the &lt;code&gt;.vscode&lt;/code&gt; directory, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo .vscode/* &amp;gt;&amp;gt; .git/info/exclude
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can verify the excluded files by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat .git/info/exclude
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By following these steps, you'll have IntelliSense set up for your PostgreSQL project and unnecessary files excluded from Git changes. &lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>postgressql</category>
      <category>vscode</category>
    </item>
    <item>
      <title>Debugging PostgreSQL with GDB + Visual Studio Code</title>
      <dc:creator>Yuya Shinde</dc:creator>
      <pubDate>Wed, 19 Mar 2025 05:13:43 +0000</pubDate>
      <link>https://dev.to/yuyash/debugging-postgresql-with-visual-studio-code-5am5</link>
      <guid>https://dev.to/yuyash/debugging-postgresql-with-visual-studio-code-5am5</guid>
      <description>&lt;p&gt;In this article, we will explore how to debug PostgreSQL using Visual Studio Code (VS Code). We will assume that you have a client machine (macOS) and a remote Linux environment where PostgreSQL is built and running. Please refer to &lt;a href="https://dev.to/yuyash/building-and-running-postgresql-from-source-code-55gk"&gt;this article&lt;/a&gt; for how to build PostgreSQL from source code in a Linux environment.&lt;/p&gt;

&lt;p&gt;When doing remote development in Visual Studio, it's common to use SSH public key authentication instead of password authentication. An SSH key consists of a pair of public and private keys, where you keep the private key in a safe place and register the public key with the remote host, allowing you to connect securely without entering a password.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Set up SSH keys
&lt;/h2&gt;

&lt;p&gt;First, we need to create an SSH key. We will do it on the client machine (macOS). We can use the &lt;code&gt;ssh-keygen&lt;/code&gt; command to generate a new key pair. The &lt;code&gt;-C&lt;/code&gt; option specifies the comment for the key, which can be any string (e.g., an email address). The location where the generated key is saved is specified with the &lt;code&gt;-f&lt;/code&gt; option. In this article, we save the key in the &lt;code&gt;~/.ssh&lt;/code&gt; directory with the name &lt;code&gt;id_rasp5&lt;/code&gt;, but you can specify a different location and/or name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-keygen -t ed25519 -C "&amp;lt;YOUR_COMMENT&amp;gt;" -f ~/.ssh/id_rasp5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we need to copy the public key to the remote host's ~/.ssh/authorized_keys file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-copy-id -i ~/.ssh/id_rasp5.pub yuyash@&amp;lt;REMOTE_HOST_IP_ADDRESS&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you cannot access the remote host via SSH, manually add the contents of &lt;code&gt;~/.ssh/id_rasp5.pub&lt;/code&gt; to the &lt;code&gt;~/.ssh/authorized_keys&lt;/code&gt; file on the remote host.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Configure SSH
&lt;/h2&gt;

&lt;p&gt;We need to configure our SSH client to connect to the remote host. We can do this by adding an entry to our ~/.ssh/config file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Host rasp5
  HostName &amp;lt;REMOTE_HOST_IP_ADDRESS&amp;gt;
  User &amp;lt;USERNAME&amp;gt;
  IdentityFile ~/.ssh/id_rasp5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace  and  with your remote host IP address and username. This configuration tells SSH to connect to the remote host with the specified hostname, username, and identity file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Install VS Code and extensions
&lt;/h2&gt;

&lt;p&gt;Install VS Code. You can either download the package from the &lt;a href="https://code.visualstudio.com/download" rel="noopener noreferrer"&gt;website&lt;/a&gt; or use the brew command to install it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install --cask visual-studio-code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We also need to install VS Code extension: &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh" rel="noopener noreferrer"&gt;Remote - SSH&lt;/a&gt; into your client. This extension allows us to connect to a remote host using SSH.&lt;/p&gt;

&lt;p&gt;To install these extensions, open the Extensions view in VS Code by clicking on the Extensions icon in the left sidebar or pressing  Cmd+Shift+X (macOS). Search for the extensions and click the Install button to install them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Connect to the remote host
&lt;/h2&gt;

&lt;p&gt;Once we have installed the Remote - SSH extension, we can connect to our remote host. Open the Command Palette in VS Code by pressing Cmd+Shift+P (macOS) and type "Connect to Host..." in the input field. Select the host we configured earlier.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Install C/C++ extensions on the remote host
&lt;/h2&gt;

&lt;p&gt;After connecting to the remote host, we need to install the C/C++ extension pack on the remote host as well. Follow the same step to open Extensions view and install &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools" rel="noopener noreferrer"&gt;C/C++&lt;/a&gt; extension. This extension provides C/C++ language support for VS Code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Create a launch configuration
&lt;/h2&gt;

&lt;p&gt;To debug PostgreSQL, we need to create a launch configuration. Open the Run view in VS Code by clicking on the Run icon in the left sidebar or pressing Cmd+Shift+D (macOS). Click on the "create a launch.json file" link.&lt;/p&gt;

&lt;p&gt;In the launch.json file, add the following configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Attach",
            "type": "cppdbg",
            "request": "attach",
            "program": "${workspaceFolder}/../build/pgsql/master/bin/postgres",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration tells VS Code to attach to the PostgreSQL process using GDB.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Start PostgreSQL
&lt;/h2&gt;

&lt;p&gt;Start PostgreSQL on the remote host. The location of the &lt;code&gt;pg_ctl&lt;/code&gt; command depends on the &lt;code&gt;--prefix&lt;/code&gt; setting when you built it. This article specifies the same location as in &lt;a href="https://dev.to/yuyash/building-and-running-postgresql-from-source-code-55gk"&gt;this setup steps&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export PG_DIR_PREFIX=${HOME}/Workplace/build/pgsql/master
${PG_DIR_PREFIX}/bin/pg_ctl -D ${PG_DIR_PREFIX}/data -l logfile start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 8: Create a backend process
&lt;/h2&gt;

&lt;p&gt;In this article we will debug a PostgreSQL session. Since PostgreSQL forks a new process for each session, we first make a connection and identify the session's process. Create a backend process by running &lt;code&gt;psql&lt;/code&gt; on the remote host:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PG_DIR_PREFIX}/lib
${PG_DIR_PREFIX}/bin/psql -d postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;psql&lt;/code&gt; prompt, run the following command to get the PID of the backend process:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT pg_backend_pid();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note down the PID (e.g., 444662). If you run the following command in another terminal without closing the &lt;code&gt;psql&lt;/code&gt; session, you will see that the process exists. In the next step, we will debug this process using GDB.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ps -ef | grep postgres | grep 444662
yuyash    444662  444569  0 22:20 ?        00:00:00 postgres: yuyash postgres [local] idle
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 9: Set a breakpoint
&lt;/h2&gt;

&lt;p&gt;Set a breakpoint in the &lt;a href="https://github.com/postgres/postgres/blob/master/src/backend/access/transam/xact.c#L3061" rel="noopener noreferrer"&gt;xact.c&lt;/a&gt; file at the first line of StartTransactionCommand function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx12ajnopl8tujgur2hnz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx12ajnopl8tujgur2hnz.png" alt="Image description" width="481" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 10: Attach to the process
&lt;/h2&gt;

&lt;p&gt;Attach to the backend process using the launch configuration we created earlier. In the Run view, select the "(gdb) Attach" configuration and click on the "Start Debugging" button. VS Code will attach GDB to the process.&lt;/p&gt;

&lt;p&gt;Next, go back to the &lt;code&gt;psql&lt;/code&gt; prompt and execute &lt;code&gt;BEGIN;&lt;/code&gt; as shown below. This will create a transaction on the PostgreSQL side and go through the code path where you set the breakpoint above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;postgres=# BEGIN;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;VS Code's GDB stop at the breakpoint we set earlier. We can now step through the code, inspect variables, and debug PostgreSQL as needed.&lt;/p&gt;

&lt;p&gt;That's it! With these steps, you should be able to debug PostgreSQL using Visual Studio Code.&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>postgressql</category>
      <category>vscode</category>
    </item>
    <item>
      <title>Building and Running PostgreSQL from Source Code</title>
      <dc:creator>Yuya Shinde</dc:creator>
      <pubDate>Tue, 18 Mar 2025 00:42:08 +0000</pubDate>
      <link>https://dev.to/yuyash/building-and-running-postgresql-from-source-code-55gk</link>
      <guid>https://dev.to/yuyash/building-and-running-postgresql-from-source-code-55gk</guid>
      <description>&lt;p&gt;In this article, I'll walk you through the steps to build and run PostgreSQL database server on Linux machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preface
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This article is intended for use on Debian-based Linux systems.&lt;/li&gt;
&lt;li&gt;The steps is intended for PostgreSQL development. For general use, I recommend installing a pre-compiled package from your Linux distribution's repository.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Install Git and Clone the PostgreSQL Repository
&lt;/h2&gt;

&lt;p&gt;The first step is making sure that Git is installed on your system. If it's not already installed, you can install it using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, clone the official PostgreSQL repository. Note: You can clone the repository anywhere; I'm using &lt;code&gt;~/Workplace&lt;/code&gt; in this article.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -p ~/Workplace
cd Workplace/
git clone git://git.postgresql.org/git/postgresql.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Install Required Packages
&lt;/h2&gt;

&lt;p&gt;Before building PostgreSQL database server, you need to install some required packages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install -y build-essential git gdb lcov bison flex \
libkrb5-dev libssl-dev libldap-dev libpam0g-dev python3-dev \
tcl-dev libperl-dev gettext libxml2-dev libxslt1-dev \
libreadline-dev libedit-dev uuid-dev libossp-uuid-dev \
libipc-run-perl perl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;configure&lt;/code&gt; script running in the next step will check for these packages and prompt you to install them if you are missing any other packages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Build and Install PostgreSQL
&lt;/h2&gt;

&lt;p&gt;Now it's time to build and install PostgreSQL. Create a new directory for the build files, set the &lt;code&gt;PG_DIR_PREFIX&lt;/code&gt; environment variable and set it as a value of the &lt;code&gt;--prefix&lt;/code&gt; option. You can set any prefix location, but avoid building inside the cloned repository directory for better organization. &lt;/p&gt;

&lt;p&gt;We also enable debugging and disable optimization to prepare for GDB debugging in the next step.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd postgresql
mkdir -p ${HOME}/Workplace/build/pgsql/master/
export PG_DIR_PREFIX=${HOME}/Workplace/build/pgsql/master
./configure --prefix=${PG_DIR_PREFIX} --enable-depend --enable-debug --enable-cassert --enable-tap-tests CFLAGS=-O0
make
make install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: Initialize and Start PostgreSQL
&lt;/h2&gt;

&lt;p&gt;After building and installing PostgreSQL, initialize the database and start the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -p ${PG_DIR_PREFIX}/data
${PG_DIR_PREFIX}/bin/initdb -D ${PG_DIR_PREFIX}/data
${PG_DIR_PREFIX}/bin/pg_ctl -D ${PG_DIR_PREFIX}/data -l logfile start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 5: Verify that PostgreSQL is Running
&lt;/h2&gt;

&lt;p&gt;To verify that PostgreSQL server is running, check the process list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ps -ef | grep postgres
yuyash     54508       1  0 11:32 ?        00:00:00 /home/yuyash/Workplace/build/pgsql/master/bin/postgres -D /home/yuyash/Workplace/build/pgsql/master/data
yuyash     54509   54508  0 11:32 ?        00:00:00 postgres: checkpointer 
yuyash     54510   54508  0 11:32 ?        00:00:00 postgres: background writer 
yuyash     54512   54508  0 11:32 ?        00:00:00 postgres: walwriter 
yuyash     54513   54508  0 11:32 ?        00:00:00 postgres: autovacuum launcher 
yuyash     54514   54508  0 11:32 ?        00:00:00 postgres: logical replication launcher 
yuyash     54524   39226  0 11:32 pts/2    00:00:00 grep --color=auto postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 6: Connect to PostgreSQL using psql
&lt;/h2&gt;

&lt;p&gt;Before using &lt;code&gt;psql&lt;/code&gt; command, set shared library path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PG_DIR_PREFIX}/lib
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, connect to the PostgreSQL database using &lt;code&gt;psql&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;${PG_DIR_PREFIX}/bin/psql -d postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To test the connection, execute a simple query to retrieve the version number:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;postgres=# select version();
                                              version                                               
----------------------------------------------------------------------------------------------------
 PostgreSQL 18devel on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
(1 row)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 7: Disconnect from PostgreSQL
&lt;/h2&gt;

&lt;p&gt;Enter &lt;code&gt;\q&lt;/code&gt; to exit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;postgres=# \q
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 8: Stop PostgreSQL
&lt;/h2&gt;

&lt;p&gt;To stop the PostgreSQL server, execute following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;${PG_DIR_PREFIX}/bin/pg_ctl stop -D ${PG_DIR_PREFIX}/data -m smart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! In my next article, I'll explore how to debug the PostgreSQL process.&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>postgressql</category>
      <category>database</category>
    </item>
  </channel>
</rss>
