sudo apt install postgresql postgresql-contribSet ps to run on startup
sudo update-rc.d postgresql enableNext start a postgres session
sudo -u postgres psqlCREATE ROLE username WITH LOGIN PASSWORD 'password' ;ALTER ROLE username CREATEDB;CREATE DATABASE databasename;GRANT ALL PRIVILEGES ON DATABASE databasename TO username;# List all database
\list
# Connect to database
\connect databasename
# List all tables
\dtFirst install the PostgreSQL helper
pip install psycopg2-binaryNext, add the database to settings.py
'postgresql': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'bdname',
'USER': 'username',
'PASSWORD': 'pass',
'HOST': '127.0.0.1',
'PORT': '',
}Ensure migrations are up to date
python manage.py makemigrations
python manage.py migrateMigrate settings to the new database and ensure tables are clear for import.
python manage.py migrate --database=posgresql
python manage.py sqlflush --database=postgresqlExport MySQL database to json.
python manage.py dumpdata --all --natural-primary --indent=4 > dbname.jsonImport json to Postgres
python manage.py loaddata dbname.json --database=postgresqlFinally change the default database in settings.py to the PostgreSQL connection.
sudo service postgresql restartEdit conf file. You can start a session with PostgreSQL and run SHOW config_file; to see its location.
sudo nano /etc/postgresql/10/main/postgresql.confSet shared_buffers to 25% of total ram. Example: with 4gb ram:
shared_buffers = 1024MB