PostgreSQL 14 Admin Guide for GNU/Linux – Step-by-step

October 2, 2021 | By the+gnu+linux+evangelist | Filed in: Tutorial.

Getting Started

  1. 2. Making Directories

    First, Make Needed Directories

    sudo mkdir -p /home/postgres/data

    Set postgres as Owner with:

    sudo chown -R postgres:postgres /home/postgres
  2. 3. Setting up postgres Pass

    Set the postgres User Password

    sudo passwd postgres

    Give a Password to the postgres User Account.
    If Got “User is Not in Sudoers file” then see: How to Enable sudo

  3. 4. Logging in

    Login as the postgres User

    su postgres

    Change to the Home Directory:

    cd 
  4. 5. Setting up PATH

    And Setup User’s Path

    echo "export PATH=$PATH:/usr/lib/postgresql/[REL]/bin" >> ~/.bashrc
    

    Replace [REL] with your Current one in the above Command. So in this case is 14.

    Load the New PATH with:

    bash
  5. 6. Making PostgreSQL DB Cluster

    Then Setup First, PostgreSQL DB Cluster
    Simply run:

    initdb -D /home/postgres/data

    This just for testing pourposes…

  6. 7. Starting PostgreSQL Server

    Next to Start PostgreSQL Server
    Play:

    pg_ctl -D /home/postgres/data -l logfile start

    In case of Issue then Check the logfile with:

    cat logfile
  7. 8. Making PostgreSQL Test DB

    Create a PostgreSQL test Database
    Issue:

    createdb test
  8. 9. Accessing PostgreSQL Database

    Access PostgreSQL Database CLI
    First, Set the postgres Database’s Password:

    psql template1

    And then on the template1# Prompt:

    password postgres

    And Exit with:

    \q

    Then to Access test Database:

    psql test
  9. 10. Creating Table

    Then to Create a Table

    CREATE TABLE account(
    user_id serial PRIMARY KEY,
    username VARCHAR (50) UNIQUE NOT NULL 
    );
    
  10. 11. Listing Tables

    Next to List Tables
    With:

    \dt
  11. 12. Listing Databases

    Again Listing Databases
    Use:

    \l 

    ‘q’ to Quit.
    For More See PostgreSQL 14 Online Documentation

  12. 13. Dropping Test DB

    Finally, to Delete test Database
    Issue:

    dropdb test
  13. 14. Installing PostgreSQL Admin UI

    For PostgreSQL 14 GUI Administration Install PgAdmin 4

    PgAdmin4 on Linux Install

Contents


Tags: ,

QuickChic Theme • Powered by WordPress