Step-by-step | PostgreSQL 12 Admin Guide for Gnu/Linux

October 14, 2020 | By the+gnu+linux+evangelist.

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.

    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(/nuser_id serial PRIMARY KEY,/nusername 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 12 Online Documentation

  12. 13. Dropping Test DB

    Finally, to Delete test Database
    Issue:

    dropdb test
  13. 14. Installing PostgreSQL Admin UI

    For PostgreSQL 12 GUI Administration Install PgAdmin 4

    PgAdmin4 on Linux Install

Contents


QuickChic Theme • Powered by WordPress