Django 1 - Install PostgreSQL along with Django

By Sheldon L Published at 2020-01-10 Updated at 2020-01-10


References

Operation

export all_proxy="socks5://127.0.0.1"
pip install -U pip # make sure to have an up-to-date pip
pip install psycopg2
# OR if not work:
pip install psycopg2-binary

sudo touch /etc/apt/sources.list.d/pgdg.list
sudo vim /etc/apt/sources.list.d/pgdg.list
"""\
\ deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main
"""
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt install postgresql-12
sudo systemctl start postgresql
sudo systemctl {status|enable|disable} postgresql

## Users and Roles: user is system user, role is separated from system
# Create user
sudo -u postgres psql       # login to psql as default super role postgres
\password postgres          # set password as first time

\du                         # check all roles
CREATE USER <username=***n> WITH LOGIN CREATEDB PASSWORD '<password=***x>';
\du
\q

# Create roles
sudo -u postgres createuser <rolename=pgadmin> -d -P    # password=n***9
# OR
sudo -u postgres psql
\du
CREATE ROLE pgadmin WITH LOGIN CREATEDB PASSWORD '<password=***k>';
\du
\q

# Create db
sudo -u postgres createdb <dbname> -O <username=***n>
# OR
sudo -u postgres psql
CREATE DATABASE <dbname> OWNER <username>;
\l  # list all database
\q

# Drop db
sudo -u postgres dropdb <dbname> --if-exists
# OR
DROP DATABASE IF EXISTS <dbname>;

"""""" Other Usage: https://zaiste.net/postgresql_primer_for_busy_people/
Export database as CSV
Create compressed PostgreSQL database backup
Create schema-only database backup
Restore database from binary dump
Create compressed backups for all databases at once
Convert binary database dump to SQL file
Copy database quickly
Change database ownership
Table operation
Column operation
Date and time operation
JSON
PSQL
Others
""""""
cd $hub/mysites/dj_py38/dashboard/src
python -m pip install Django
python
>>> import django
>>> print(django.get_version())
django-admin startproject dashboard  # will create new dir
python manage.py runserver