django psql setup

This gist I write, because I couldn't find step by step instructions 
how to install and start postgresql locally and not globally in the
operating system (which would require sudo).

I hope, this will help especially people new to postgresql!

####################################
# create conda environment
####################################

conda create --name myenv

# enter the environment
conda activate myenv

####################################
# install postgresql via conda
####################################

conda install -y -c conda-forge postgresql

####################################
# create a base database locally
####################################

initdb -D mylocal_db

##############################
# now start the server modus/instance of postgres
##############################

pg_ctl -D mylocal_db -l logfile start

## waiting for server to start.... done
## server started

# now the server is up


####################################
# create a non-superuser (more safety!)
####################################

createuser --encrypted --pwprompt mynonsuperuser
# asks for name and password

####################################
# using this super user, create inner database inside the base database
####################################

createdb --owner=mynonsuperuser myinner_db


####################################
# in this point, if you run some program,
# you connect you program with this inner database
# e.g. Django 
####################################

# in django (Python) e.g. you do

nano <mysite>/settings.py # or instead of nano your favorite editor!

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'myinner_db',
        'USER': 'mynonsuperuser',
        'PASSWORD': '<mynonsuperuserpassword>',
        'HOST': 'localhost',
        'PORT': '',
    }
}




# and it is available for django
# so that you can do

##############################
# do with the connected program further steps
##############################

# first install psycopg2
# because django requires this for handling postgresql
conda install -c anaconda psycopg2

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source