Skip to content

Instantly share code, notes, and snippets.

@anilahir
Created October 12, 2020 15:30
Show Gist options
  • Select an option

  • Save anilahir/a7b3908392ff1e8ff507fd6d938cadc3 to your computer and use it in GitHub Desktop.

Select an option

Save anilahir/a7b3908392ff1e8ff507fd6d938cadc3 to your computer and use it in GitHub Desktop.

Revisions

  1. anilahir created this gist Oct 12, 2020.
    42 changes: 42 additions & 0 deletions PostgreSQL.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    Installation:
    -----------------------------------------
    ```
    sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
    wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
    sudo apt-get update
    sudo apt-get -y install postgresql
    ```

    Setup User:
    ---------------------------------------------------------
    ```
    $ sudo -u postgres psql
    CREATE DATABASE <dbname>;
    CREATE USER <username> WITH ENCRYPTED PASSWORD '<password>';
    GRANT ALL PRIVILEGES ON DATABASE <dbname> TO <username>;
    ```

    Create user:
    ------------------------------------
    ```
    sudo -u postgres createuser <username>
    ```

    Create Database
    ----------------------------------------
    ```
    sudo -u postgres createdb <dbname>
    ```

    Give password to the user:
    ----------------------------------------------
    ```
    $ sudo -u postgres psql
    psql=# ALTER USER <username> WITH ENCRYPTED PASSWORD '<password>';
    ```

    Grant privileges on database:
    ------------------------------------------------
    ```
    psql=# GRANT ALL PRIVILEGES ON DATABASE <dbname> TO <username>;
    ```