{"id":13868,"date":"2024-05-28T20:15:55","date_gmt":"2024-05-28T17:15:55","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=13868"},"modified":"2024-05-28T20:15:56","modified_gmt":"2024-05-28T17:15:56","slug":"how-to-install-postgresql-psql-on-ubuntu-24-04-lts","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/how-to-install-postgresql-psql-on-ubuntu-24-04-lts\/","title":{"rendered":"How to Install PostgreSQL (psql) on Ubuntu 24.04 LTS"},"content":{"rendered":"\n

PostgreSQL, often referred to as Postgres, is a powerful, open-source object-relational database<\/a> system with a strong reputation for reliability, feature robustness, and performance. In this guide, we will walk you through the steps to install PostgreSQL on Ubuntu 24.04 LTS.<\/p>\n\n\n\n

Why PostgreSQL?<\/h3>\n\n\n\n

PostgreSQL<\/a> is known for its advanced features like complex queries, foreign keys, triggers, updatable views, transactional integrity, and multi-version concurrency control. It supports a wide range of data types and can be extended by users in many ways, making it an excellent choice for both small and large applications.<\/p>\n\n\n\n

Prerequisites<\/h3>\n\n\n\n

Before you start, ensure that you have:<\/p>\n\n\n\n

    \n
  1. A system running Ubuntu<\/a> 24.04 LTS.<\/li>\n\n\n\n
  2. Sudo privileges to install software and manage system configurations.<\/li>\n<\/ol>\n\n\n\n

    Step 1: Update Your System<\/h3>\n\n\n\n

    First, update your package index to make sure you have the latest information on the newest versions of packages and their dependencies:<\/p>\n\n\n\n

    $ sudo apt update\n$ sudo apt upgrade -y<\/code><\/pre>\n\n\n\n

    Step 2: Install PostgreSQL<\/h3>\n\n\n\n

    Ubuntu’s default package repository includes PostgreSQL, so you can install it easily using the apt<\/code> package manager.<\/p>\n\n\n\n

      \n
    1. Install PostgreSQL<\/strong>:<\/li>\n<\/ol>\n\n\n\n
      $ sudo apt install postgresql postgresql-contrib -y<\/code><\/pre>\n\n\n\n

      Step 3: Verify the Installation<\/h3>\n\n\n\n

      Once the installation is complete, you can verify that PostgreSQL is installed and running correctly.<\/p>\n\n\n\n

        \n
      1. Check the status of PostgreSQL<\/strong>:<\/li>\n<\/ol>\n\n\n\n
        $ sudo systemctl status postgresql<\/code><\/pre>\n\n\n\n

        You should see output indicating that PostgreSQL is active and running.<\/p>\n\n\n\n

        Step 4: Configure PostgreSQL<\/h3>\n\n\n\n

        By default, PostgreSQL is set up to use the peer authentication method for local connections, meaning it uses the operating system user accounts for authentication.<\/p>\n\n\n\n

          \n
        1. Switch to the PostgreSQL user<\/strong>:<\/li>\n<\/ol>\n\n\n\n
          $ sudo -i -u postgres<\/code><\/pre>\n\n\n\n
            \n
          1. Access the PostgreSQL prompt<\/strong>:<\/li>\n<\/ol>\n\n\n\n
            $ psql<\/code><\/pre>\n\n\n\n

            You will now be logged into the PostgreSQL shell as the postgres<\/code> user.<\/p>\n\n\n\n

            Step 5: Basic PostgreSQL Commands<\/h3>\n\n\n\n

            Here are some basic commands to get you started with PostgreSQL:<\/p>\n\n\n\n